From d0d347dc848504e22ee304660ba728b00c833ab0 Mon Sep 17 00:00:00 2001 From: Artur Ventura Date: Tue, 19 Jul 2011 15:17:34 +0100 Subject: [PATCH] advancing closure compilation process --- makefile | 4 ++-- src/attributes.js | 27 ++++++++++++++++----------- src/class.js | 8 ++++---- src/constantPool.js | 17 ++++++++++++++--- src/cpu.js | 20 ++++++++++++-------- src/infos.js | 2 ++ src/intrp.js | 6 +++--- src/linearDatastream.js | 8 -------- src/main.js | 5 +---- src/types.js | 11 ++++------- webserver/app.py | 2 +- 11 files changed, 59 insertions(+), 51 deletions(-) diff --git a/makefile b/makefile index fb973ed..97ce022 100644 --- a/makefile +++ b/makefile @@ -5,10 +5,10 @@ ids: preprocess: mkdir -p build - /usr/bin/cpp -P -undef -Wundef -std=c99 -nostdinc -Wtrigraphs -fdollars-in-identifiers src/main.js build/pp_jvm.js + /usr/bin/cpp -P -undef -CC -Wundef -std=c99 -nostdinc -Wtrigraphs -fdollars-in-identifiers src/main.js build/pp_jvm.js compile: preprocess - java -jar lib/compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --js build/pp_jvm.js --js_output_file build/jvm.js + java -jar lib/compiler.jar --warning_level VERBOSE --compilation_level ADVANCED_OPTIMIZATIONS --js build/pp_jvm.js --js_output_file build/jvm.js clean: rm -dR build diff --git a/src/attributes.js b/src/attributes.js index 194c327..32eb3e5 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -9,6 +9,7 @@ * */ +/** @constructor */ var ExceptionTableEntry = function(dStream, constantPool){ this.start_pc = dStream.getU2(); this.end_pc = dStream.getU2(); @@ -21,6 +22,7 @@ var ExceptionTableEntry = function(dStream, constantPool){ } } +/** @constructor */ var InnerClass = function(dStream, constantPool){ this.inner_class_info = ConstantPoolRef(dStream.getU2(), constantPool,CONSTANT_Class); var outerClassIndex = dStream.getU2(); @@ -33,11 +35,13 @@ var InnerClass = function(dStream, constantPool){ this.inner_class_access_flags = dStream.getU2(); } +/** @constructor */ var LineNumberTableEntry = function(dStream){ this.start_pt = dStream.getU2(); this.line_number = dStream.getU2(); } +/** @constructor */ var LocalVariableTableEntry = function(dStream, constantPool){ this.start_pc = dStream.getU2(); this.length =dStream.getU2(); @@ -47,6 +51,7 @@ var LocalVariableTableEntry = function(dStream, constantPool){ } var Attributes_table = { + /** @constructor */ ConstantValue: function(){ this.read = function(dStream, constantPool){ this.constantvalue = ConstantPoolRef(dStream.getU2(), constantPool); @@ -63,7 +68,7 @@ var Attributes_table = { } } }, - + /** @constructor */ Code: function(){ this.read = function(dStream, constantPool){ this.max_stack = dStream.getU2(); @@ -100,7 +105,7 @@ var Attributes_table = { } } }, - + /** @constructor */ Exceptions: function(){ this.read = function(dStream, constantPool){ this.number_of_exceptions = dStream.getU2(); @@ -110,7 +115,7 @@ var Attributes_table = { } } }, - + /** @constructor */ InnerClasses: function(){ this.read = function(dStream, constantPool){ this.number_of_classes = dStream.getU2(); @@ -120,7 +125,7 @@ var Attributes_table = { } } }, - + /** @constructor */ Synthetic: function(){ this.read = function(dStream,constantPool){ if (this.attribute_length != 0){ @@ -128,13 +133,13 @@ var Attributes_table = { } } }, - + /** @constructor */ SourceFile: function(){ this.read = function(dStream,constantPool){ this.soucefile = ConstantPoolRef(dStream.getU2(), constantPool,CONSTANT_Utf8); } }, - + /** @constructor */ LineNumberTable: function(){ this.read = function(dStream,constantPool){ this.line_number_table_length = dStream.getU2(); @@ -144,17 +149,17 @@ var Attributes_table = { } } }, - + /** @constructor */ LocalVariableTable: function(){ this.read=function(dStream,constantPool){ this.local_variable_table_length = dStream.getU2(); this.local_variable_table = []; - for(var i=0; i= ref.length){ JVM_THROWS_NEW(java.lang.ArrayIndexOutOfBoundsException); } #define TO_INT(value) if (isNaN(value)){ OPPUSH(0); }else if(IS_OVERFLOW(value,INT_MAX_VALUE)){ OPPUSH(INT_MAX_VALUE); }else if(IS_UNDERFLOW(value,INT_MIN_VALUE)){ OPPUSH(INT_MIN_VALUE); }else{ OPPUSH(Math.round(value)); } -#define TO_FLOAT(value) if (isNaN(value)){ OPPUSHD(NaN); }else if(IS_OVERFLOW(value,FLOAT_MAX_VALUE)){ OPPUSHD(POSITIVE_INF); }else if (IS_UNDEFLOW(value,FLOAT_MIN_VALUE)){ OPPUSHD(NEGATIVE_INF); }else{ OPPUSHD(value);} +#define TO_FLOAT(value) if (isNaN(value)){ OPPUSHD(NaN); }else if(IS_OVERFLOW(value,FLOAT_MAX_VALUE)){ OPPUSHD(POSITIVE_INF); }else if (IS_UNDERFLOW(value,FLOAT_MIN_VALUE)){ OPPUSHD(NEGATIVE_INF); }else{ OPPUSHD(value);} #define TO_LONG(value) if (isNaN(value)){ OPPUSH(0); }else if(IS_OVERFLOW(value,LONG_MAX_VALUE)){ OPPUSH(LONG_MAX_VALUE); }else if(IS_UNDERFLOW(value,LONG_MIN_VALUE)){ OPPUSH(LONG_MIN_VALUE); }else{ OPPUSH(Math.round(value));} DEFOP(AALOAD) @@ -70,7 +70,7 @@ DEFOP(ANEWARRAY) JVM_THROWS_NEW(java.lang.NegativeArraySizeException); } var clRef = frame.classRef.constantPool.get((indexbyte1 << 8) | indexbyte2); - var instance = {length:count, value:[], 'class':this.jvm.classForName(clRef)}; + var instance = {length:count, value:[], 'class':xl.jvm.classForName(clRef)}; OPPUSH(instance); ENDDEF @@ -532,7 +532,7 @@ DEFOP(GETFIELD) var objectref = OPPOP(); CHECK_NULL(objectref) - field = objectref["class"].constantPool[(indexbyte1 << 8) | indexbyte2]; + var field = objectref["class"].constantPool[(indexbyte1 << 8) | indexbyte2]; //check if static OPPUSH(objectref[canonicalName(field.class_ref.name_ref.str) + " " + field.name_and_type_ref.name_ref.str]); ENDDEF diff --git a/src/linearDatastream.js b/src/linearDatastream.js index 67c9f96..2c39347 100644 --- a/src/linearDatastream.js +++ b/src/linearDatastream.js @@ -45,10 +45,6 @@ function DataStream(data){ result = new DataView(data,this.i,4).getUint32(0); this.i += 4; break; - case 8: - result = new DataView(data,this.i,8).getUint64(0); - this.i += 8; - break; default: throw "Weird size " + size; } @@ -70,10 +66,6 @@ function DataStream(data){ result = new DataView(data,this.i,4).getInt32(0); this.i += 4; break; - case 8: - result = new DataView(data,this.i,8).getInt64(0); - this.i += 8; - break; default: throw "Weird size " + size; } diff --git a/src/main.js b/src/main.js index b827f76..3dc755a 100644 --- a/src/main.js +++ b/src/main.js @@ -9,11 +9,8 @@ * */ -#define DEBUG -#define DEBUG_INTRP - #ifndef DEBUG -#define log(msg) +#define LOG(msg) #else #define LOG(msg) write(msg);\ if (console){\ diff --git a/src/types.js b/src/types.js index ff5abab..827039f 100644 --- a/src/types.js +++ b/src/types.js @@ -8,9 +8,6 @@ * Author: Artur Ventura * */ - -#ifndef _TYPES_JS_ -#define _TYPES_JS_ // Local Variables Types #define LOC_VAR_boolean 0x001; @@ -81,13 +78,13 @@ #define USHR(value1,value2) ((value1)>0?(value1)>>s:((value1)>>s) + (2<<~s)) #define XOR(value1,value2) ((value1)^(value2)) -function getRefClass(ref){ +/*function getRefClass(ref){ if (ref.type == REF_TYPE_array){ - return getArrayClass(); + return getArrayClass(ref); }else{ return ref.classRef; } -} -#endif //_TYPES_JS_ +}*/ + diff --git a/webserver/app.py b/webserver/app.py index ca15781..01377e2 100644 --- a/webserver/app.py +++ b/webserver/app.py @@ -27,7 +27,7 @@ class index: return "" if filename.endswith(".js"): web.header('Content-Type', 'text/javascript') - return commands.getstatusoutput("/usr/bin/cpp -P -undef -Wundef -std=c99 -nostdinc -Wtrigraphs -fdollars-in-identifiers ../src/" + filename)[1] + return commands.getstatusoutput("/usr/bin/cpp -P -DDEBUG -DDEBUG_INTRP -undef -Wundef -std=c99 -nostdinc -Wtrigraphs -fdollars-in-identifiers ../src/" + filename)[1] if "testRuntime" in filename: alphex = filename[filename.rfind("/") + 1:]; return file("../runtime/" + alphex.replace(".","/") + ".class");