From 3ea052a707f900a9e49300b86ac5b0077a4cf58e Mon Sep 17 00:00:00 2001 From: Artur Ventura Date: Sun, 17 Jul 2011 18:42:58 +0100 Subject: [PATCH] can make instances, without --- class.js | 59 ++++++++++++++++++++++++++++++++++++++-- cpu.js | 11 ++++---- infos.js | 10 ++++--- intrp.js | 4 +-- main.js | 2 +- types.js | 83 ++++++++++++++++++++++++++++++++++++++++++++------------ 6 files changed, 137 insertions(+), 32 deletions(-) diff --git a/class.js b/class.js index c350a23..ae08193 100644 --- a/class.js +++ b/class.js @@ -9,6 +9,8 @@ * */ +#define CLASS_MAGIC 0xCAFEBABE + #define ACC_PUBLIC 0x0001 // Declared public; may be accessed from outside its package. #define ACC_PRIVATE 0x0002 // Declared private; usable only within the defining class. #define ACC_PROTECTED 0x0004 // Declared protected; may be accessed within subclasses. @@ -62,7 +64,7 @@ var ClassDefinition = function(jvm) { // bad bad code! This shouldn't be done this way! ClassDefinition.prototype.makeForArray = function(arrayDef){ - this.magic = 0xCAFEBABE; + this.magic = CLASS_MAGIC; this.minorVersion = 0; this.majorVersion = 50; this.constantPool = []; @@ -110,7 +112,7 @@ ClassDefinition.prototype.makeForArray = function(arrayDef){ ClassDefinition.prototype.loadFromFile = function (file){ var dataStream = new DataStream(slurpFile(file)[1]); this.magic = dataStream.getU4(); - if (this.magic != 0xCAFEBABE){ + if (this.magic != CLASS_MAGIC){ throw "Invalid Class Magic (" + this.magic + ")" ; } this.minorVersion = dataStream.getU2(); @@ -208,7 +210,7 @@ ClassDefinition.prototype.isClassOrSuperClass = function(C){ if (this.jvm.java_lang_object == this){ return false; }else{ - this.jvm.classForName(this.super_class.name_ref).isClassOrSuperClass(C); + this.super_class_ref.isClassOrSuperClass(C); } } } @@ -226,6 +228,57 @@ ClassDefinition.prototype.isInterfaceOrSuperInterface = function(I){ } } +ClassDefinition.prototype.initializeClass = function(){ + if (this.super_class && !this.super_class_ref.inited){ + this.super_class_ref.initializeClass(); + } + this.calculateEffectiveMembers(); + + // call + this.inited = true; +} + +ClassDefinition.prototype.calculateEffectiveMembers = function(){ + if (!this.effectiveMethods){ + var superEffective = (this.super_class)? this.super_class_ref.calculateEffectiveMembers() : [{},{}]; + + // fields + this.effectiveFields = {} + for(var k in superEffective[0]){ + this.effectiveFields[k] = superEffective[0][k]; + } + + for(var i=0; i mark) +#define IS_UNDERFLOW(value,mark) (value < mark) + +#define ADD(value1,value2) (value1)+(value2) +#define AND(value1,value2) (value1)&(value2) +#define DIV(value1,value2) (value1)/(value2) +#define MUL(value1,value2) (value1)*(value2) +#define NEG(value1) -(value1) +#define OR(value1,value2) (value1)|(value2) +#define REM(value1,value2) (value1)%(value2) +#define SHL(value1,value2) (value1)<<(0x001f&(value2)) +#define SHR(value1,value2) (value1)>>(0x001f&(value2)) +#define SUB(value1,value2) ((value1)-(value2)) +#define USHR(value1,value2) ((value1)>0?(value1)>>s:((value1)>>s) + (2<<~s)) +#define XOR(value1,value2) ((value1)^(value2)) function getRefClass(ref){ if (ref.type == REF_TYPE_array){ @@ -38,5 +87,5 @@ function getRefClass(ref){ } } -var NULL = makeLocalVar(LOC_VAR_reference); +