String concatenation, field lookup, preventing undef into stack
This commit is contained in:
parent
6e79e69f59
commit
3f11e0c2f0
13
src/class.js
13
src/class.js
@ -131,13 +131,13 @@ ClassDefinition.prototype.loadFromFile = function (file){
|
|||||||
this.fields = []
|
this.fields = []
|
||||||
for(var i=0; i<this.fields_count; i++){
|
for(var i=0; i<this.fields_count; i++){
|
||||||
|
|
||||||
this.fields[i] = new FieldInfo(dataStream,this.constantPool);
|
this.fields[i] = new FieldInfo(dataStream,this.constantPool,this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.methods_count = dataStream.getU2();
|
this.methods_count = dataStream.getU2();
|
||||||
this.methods=[];
|
this.methods=[];
|
||||||
for(var i=0; i<this.methods_count; i++){
|
for(var i=0; i<this.methods_count; i++){
|
||||||
this.methods[i] = new MethodInfo(dataStream, this.constantPool);
|
this.methods[i] = new MethodInfo(dataStream, this.constantPool,this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.attributes_count = dataStream.getU2();
|
this.attributes_count = dataStream.getU2();
|
||||||
@ -284,6 +284,15 @@ ClassDefinition.prototype.makeInstance = function(){
|
|||||||
return newInstance;
|
return newInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClassDefinition.prototype.resolveField = function(name){
|
||||||
|
for(var k in this.effectiveFields){
|
||||||
|
var field = this.effectiveFields[k];
|
||||||
|
if (field.name_ref.str === name && !(field.access_flags & ACC_PRIVATE)){
|
||||||
|
return field.dec_class.this_class.name_ref.str + " " +field.name_ref.str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function LoadClassFile (x,jvm){
|
function LoadClassFile (x,jvm){
|
||||||
var def = new ClassDefinition(jvm);
|
var def = new ClassDefinition(jvm);
|
||||||
if (x.charAt(0) != "[" ){
|
if (x.charAt(0) != "[" ){
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#define JVM_THROWS_NEW(exception) throw "VER: throws new exception"
|
#define JVM_THROWS_NEW(exception) throw "VER: throws new exception"
|
||||||
#ifdef DEBUG_INTRP
|
#ifdef DEBUG_INTRP
|
||||||
#define LOG_INTRP(x) LOG(x)
|
#define LOG_INTRP(x) write(x)
|
||||||
#define DEFALIAS(opx) case opx: if(!temp) { temp = pc + ": opx op:[" + operand_stack + "] lvar:[" + local_variables + "]"; }
|
#define DEFALIAS(opx) case opx: if(!temp) { temp = pc + ": opx op:[" + operand_stack + "] lvar:[" + local_variables + "]"; }
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -40,8 +40,12 @@
|
|||||||
#define ENDDEF break;
|
#define ENDDEF break;
|
||||||
|
|
||||||
#define OPPOP() operand_stack.pop()
|
#define OPPOP() operand_stack.pop()
|
||||||
#define OPPUSH(v) operand_stack.push(v)
|
|
||||||
|
|
||||||
|
#ifdef DEBUG_INTRP
|
||||||
|
#define OPPUSH(v) var $unused = v; if (typeof $unused === "undefined") {PANIC("pushing undefined to stack")}; operand_stack.push($unused)
|
||||||
|
#else
|
||||||
|
#define OPPUSH(v) operand_stack.push(v)
|
||||||
|
#endif
|
||||||
#define OPPOPD() (operand_stack.pop() || operand_stack.pop())
|
#define OPPOPD() (operand_stack.pop() || operand_stack.pop())
|
||||||
#define OPPUSHD(v) (operand_stack.push(v) && operand_stack.push(null))
|
#define OPPUSHD(v) (operand_stack.push(v) && operand_stack.push(null))
|
||||||
|
|
||||||
|
@ -56,8 +56,9 @@ function parseArgs(descriptor){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @constructor */
|
/** @constructor */
|
||||||
var FieldInfo = function(dStream,constantPool){
|
var FieldInfo = function(dStream,constantPool,cl){
|
||||||
this.access_flags = dStream.getU2();
|
this.access_flags = dStream.getU2();
|
||||||
|
this.dec_class = cl;
|
||||||
this.name_ref = ConstantPoolRef(dStream.getU2(), constantPool, CONSTANT_Utf8);
|
this.name_ref = ConstantPoolRef(dStream.getU2(), constantPool, CONSTANT_Utf8);
|
||||||
this.descriptor_ref = ConstantPoolRef(dStream.getU2(), constantPool, CONSTANT_Utf8);
|
this.descriptor_ref = ConstantPoolRef(dStream.getU2(), constantPool, CONSTANT_Utf8);
|
||||||
var type = this.descriptor_ref.str.charAt(0);
|
var type = this.descriptor_ref.str.charAt(0);
|
||||||
@ -70,8 +71,9 @@ var FieldInfo = function(dStream,constantPool){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @constructor */
|
/** @constructor */
|
||||||
var MethodInfo = function(dStream, constantPool){
|
var MethodInfo = function(dStream, constantPool,cl){
|
||||||
this.access_flags = dStream.getU2();
|
this.access_flags = dStream.getU2();
|
||||||
|
this.dec_class = cl;
|
||||||
this.name_ref = ConstantPoolRef(dStream.getU2(), constantPool, CONSTANT_Utf8);
|
this.name_ref = ConstantPoolRef(dStream.getU2(), constantPool, CONSTANT_Utf8);
|
||||||
this.descriptor_ref = ConstantPoolRef(dStream.getU2(), constantPool, CONSTANT_Utf8);
|
this.descriptor_ref = ConstantPoolRef(dStream.getU2(), constantPool, CONSTANT_Utf8);
|
||||||
this.descriptor = parseArgs(this.descriptor_ref.str);
|
this.descriptor = parseArgs(this.descriptor_ref.str);
|
||||||
|
@ -520,9 +520,12 @@ DEFOP(GETFIELD)
|
|||||||
|
|
||||||
CHECK_NULL(objectref)
|
CHECK_NULL(objectref)
|
||||||
var field = xl.constantPool.get((indexbyte1 << 8) | indexbyte2);
|
var field = xl.constantPool.get((indexbyte1 << 8) | indexbyte2);
|
||||||
//check if static
|
var fieldSig = field.class_ref.name_ref.str + " " + field.name_and_type_ref.name_ref.str ;
|
||||||
OPPUSH(objectref[field.class_ref.name_ref.str + " " + field.name_and_type_ref.name_ref.str]);
|
if (!(fieldSig in objectref)){
|
||||||
LOG(field.class_ref.name_ref.str + " " + field.name_and_type_ref.name_ref.str);
|
fieldSig = xl.resolveField(field.name_and_type_ref.name_ref.str);
|
||||||
|
}
|
||||||
|
OPPUSH(objectref[fieldSig]);
|
||||||
|
LOG(fieldSig);
|
||||||
ENDDEF
|
ENDDEF
|
||||||
|
|
||||||
DEFOP(GETSTATIC)
|
DEFOP(GETSTATIC)
|
||||||
@ -937,9 +940,7 @@ DEFOP(INVOKESTATIC)
|
|||||||
LOG("Calling " + xl.className+ " " + method.name_ref.str + method.descriptor_ref.str)
|
LOG("Calling " + xl.className+ " " + method.name_ref.str + method.descriptor_ref.str)
|
||||||
LOG("!! NATIVE !!")
|
LOG("!! NATIVE !!")
|
||||||
if (methodId in xl.jvm.internalJNITable[canonicalName(cl.this_class.name_ref)]){
|
if (methodId in xl.jvm.internalJNITable[canonicalName(cl.this_class.name_ref)]){
|
||||||
|
|
||||||
result = xl.jvm.internalJNITable[canonicalName(cl.this_class.name_ref)][methodId].apply(cl,args);
|
result = xl.jvm.internalJNITable[canonicalName(cl.this_class.name_ref)][methodId].apply(cl,args);
|
||||||
LOG("Returing from " + xl.className+ " " + method.name_ref.str + method.descriptor_ref.str)
|
|
||||||
}else if (methodId in xl.jvm.JNITable[canonicalName(cl.this_class.name_ref)][methodId]){
|
}else if (methodId in xl.jvm.JNITable[canonicalName(cl.this_class.name_ref)][methodId]){
|
||||||
result = xl.jvm.JNITable[canonicalName(cl.this_class.name_ref)][methodId].apply(cl,args)
|
result = xl.jvm.JNITable[canonicalName(cl.this_class.name_ref)][methodId].apply(cl,args)
|
||||||
}else{
|
}else{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user