Interactive development mode restored and more Intrp code
This commit is contained in:
parent
b4d67b71a0
commit
a2fbf6d230
12
src/class.js
12
src/class.js
@ -223,7 +223,13 @@ ClassDefinition.prototype.initializeClass = function(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.calculateEffectiveMembers();
|
this.calculateEffectiveMembers();
|
||||||
var that = this
|
for (var i=0; i<this.fields_count; i++){
|
||||||
|
var f = this.fields[i];
|
||||||
|
if(f.access_flags & ACC_STATIC){
|
||||||
|
this[this.this_class.name_ref.str + " " + f.name_ref.str] = (f.primitive)?0:null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// call <cinit>
|
// call <cinit>
|
||||||
this.inited = true;
|
this.inited = true;
|
||||||
}
|
}
|
||||||
@ -263,7 +269,9 @@ ClassDefinition.prototype.makeInstance = function(){
|
|||||||
if (!this.inited) { this.initializeClass(); }
|
if (!this.inited) { this.initializeClass(); }
|
||||||
var newInstance = {};
|
var newInstance = {};
|
||||||
for(var k in this.effectiveFields){
|
for(var k in this.effectiveFields){
|
||||||
newInstance[k] = (this.effectiveFields[k].primitive)?0:null;
|
if (!(this.effectiveFields[k].access_flags & ACC_STATIC)){
|
||||||
|
newInstance[k] = (this.effectiveFields[k].primitive)?0:null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
newInstance["class"] = this;
|
newInstance["class"] = this;
|
||||||
return newInstance;
|
return newInstance;
|
||||||
|
@ -12,14 +12,25 @@
|
|||||||
|
|
||||||
#define CLASS_MAGIC 0xCAFEBABE
|
#define CLASS_MAGIC 0xCAFEBABE
|
||||||
|
|
||||||
#define ACC_PUBLIC 0x0001 // Declared public; may be accessed from outside its package.
|
#define ACC_PUBLIC 0x0001
|
||||||
#define ACC_PRIVATE 0x0002 // Declared private; usable only within the defining class.
|
// Declared public; may be accessed from outside its package.
|
||||||
#define ACC_PROTECTED 0x0004 // Declared protected; may be accessed within subclasses.
|
#define ACC_PRIVATE 0x0002
|
||||||
#define ACC_STATIC 0x0008 // Declared static.
|
// Declared private; usable only within the defining class.
|
||||||
#define ACC_FINAL 0x0010 // Declared final; no subclasses allowed.
|
#define ACC_PROTECTED 0x0004
|
||||||
#define ACC_SUPER 0x0020 // Treat superclass methods specially when invoked by the invokespecial instruction.
|
// Declared protected; may be accessed within subclasses.
|
||||||
#define ACC_VOLATILE 0x0040 // Declared volatile; cannot be cached.
|
#define ACC_STATIC 0x0008
|
||||||
#define ACC_NATIVE 0x0100 // Declared native; implemented in a language other than Java.
|
// Declared static.
|
||||||
#define ACC_INTERFACE 0x0200 // Is an interface, not a class.
|
#define ACC_FINAL 0x0010
|
||||||
#define ACC_ABSTRACT 0x0400 // Declared abstract; may not be instantiated.
|
// Declared final; no subclasses allowed.
|
||||||
#define ACC_TRANSIENT 0x0080 // Declared transient; not written or read by a persistent object manager.
|
#define ACC_SUPER 0x0020
|
||||||
|
// Treat superclass methods specially when invoked by the invokespecial instruction.
|
||||||
|
#define ACC_VOLATILE 0x0040
|
||||||
|
// Declared volatile; cannot be cached.
|
||||||
|
#define ACC_NATIVE 0x0100
|
||||||
|
// Declared native; implemented in a language other than Java.
|
||||||
|
#define ACC_INTERFACE 0x0200
|
||||||
|
// Is an interface, not a class.
|
||||||
|
#define ACC_ABSTRACT 0x0400
|
||||||
|
// Declared abstract; may not be instantiated.
|
||||||
|
#define ACC_TRANSIENT 0x0080
|
||||||
|
// Declared transient; not written or read by a persistent object manager.
|
||||||
|
251
src/intrp.def
251
src/intrp.def
@ -173,12 +173,10 @@ ENDDEF
|
|||||||
DEFOP(DALOAD)
|
DEFOP(DALOAD)
|
||||||
var index = OPPOP();
|
var index = OPPOP();
|
||||||
var arrayref = OPPOP();
|
var arrayref = OPPOP();
|
||||||
if (arrayref == NULL){
|
|
||||||
JVM_THROWS_NEW(java.lang.NullPointerException);
|
CHECK_NULL(arrayref);
|
||||||
}
|
CHECK_ARRAY_INDEX(index,arrayref);
|
||||||
if (index >= arrayref.length){
|
|
||||||
JVM_THROWS_NEW(java.lang.ArrayIndexOutOfBoundsException);
|
|
||||||
}
|
|
||||||
OPPUSHD(arrayref.value[index]);
|
OPPUSHD(arrayref.value[index]);
|
||||||
ENDDEF
|
ENDDEF
|
||||||
|
|
||||||
@ -186,12 +184,10 @@ DEFOP(DASTORE)
|
|||||||
var value = OPPOPD();
|
var value = OPPOPD();
|
||||||
var index = OPPOP();
|
var index = OPPOP();
|
||||||
var arrayref = OPPOP();
|
var arrayref = OPPOP();
|
||||||
if (arrayref == NULL){
|
|
||||||
JVM_THROWS_NEW(java.lang.NullPointerException);
|
CHECK_NULL(arrayref);
|
||||||
}
|
CHECK_ARRAY_INDEX(index,arrayref);
|
||||||
if (index >= arrayref.length){
|
|
||||||
JVM_THROWS_NEW(java.lang.ArrayIndexOutOfBoundsException);
|
|
||||||
}
|
|
||||||
arrayref.value[index] = value;
|
arrayref.value[index] = value;
|
||||||
ENDDEF
|
ENDDEF
|
||||||
|
|
||||||
@ -380,12 +376,10 @@ ENDDEF
|
|||||||
DEFOP(FALOAD)
|
DEFOP(FALOAD)
|
||||||
var index = OPPOP();
|
var index = OPPOP();
|
||||||
var arrayref = OPPOP();
|
var arrayref = OPPOP();
|
||||||
if (arrayref == NULL){
|
|
||||||
JVM_THROWS_NEW(java.lang.NullPointerException);
|
CHECK_NULL(arrayref);
|
||||||
}
|
CHECK_ARRAY_INDEX(index,arrayref);
|
||||||
if (index >= arrayref.length){
|
|
||||||
JVM_THROWS_NEW(java.lang.ArrayIndexOutOfBoundsException);
|
|
||||||
}
|
|
||||||
OPPUSHD(arrayref.value[index]);
|
OPPUSHD(arrayref.value[index]);
|
||||||
ENDDEF
|
ENDDEF
|
||||||
|
|
||||||
@ -393,12 +387,10 @@ DEFOP(FASTORE)
|
|||||||
var value = OPPOPD();
|
var value = OPPOPD();
|
||||||
var index = OPPOP();
|
var index = OPPOP();
|
||||||
var arrayref = OPPOP();
|
var arrayref = OPPOP();
|
||||||
if (arrayref == NULL){
|
|
||||||
JVM_THROWS_NEW(java.lang.NullPointerException);
|
CHECK_NULL(arrayref);
|
||||||
}
|
CHECK_ARRAY_INDEX(index,arrayref);
|
||||||
if (index >= arrayref.length){
|
|
||||||
JVM_THROWS_NEW(java.lang.ArrayIndexOutOfBoundsException);
|
|
||||||
}
|
|
||||||
arrayref.value[index] = value;
|
arrayref.value[index] = value;
|
||||||
ENDDEF
|
ENDDEF
|
||||||
|
|
||||||
@ -530,5 +522,216 @@ DEFOP(GETFIELD)
|
|||||||
ENDDEF
|
ENDDEF
|
||||||
|
|
||||||
DEFOP(GETSTATIC)
|
DEFOP(GETSTATIC)
|
||||||
|
var indexbyte1 = READ_NEXT();
|
||||||
|
var indexbyte2 = READ_NEXT();
|
||||||
|
|
||||||
|
CHECK_NULL(objectref)
|
||||||
|
var field = this_method_cass.constantPool[(indexbyte1 << 8) | indexbyte2];
|
||||||
|
var aClass = field.class_ref.name_ref.str;
|
||||||
|
|
||||||
|
//check if static
|
||||||
|
OPPUSH(jvm.classForName(aClass)[canonicalName(field.class_ref.name_ref.str) + " " + field.name_and_type_ref.name_ref.str]);
|
||||||
ENDDEF
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(GOTO)
|
||||||
|
var branchbyte1 = READ_NEXT();
|
||||||
|
var branchbyte2 = READ_NEXT();
|
||||||
|
|
||||||
|
var branchoffset = (branchbyte1 << 8) | branchbyte2;
|
||||||
|
PC = PC + branchoffset;
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(GOTO_W)
|
||||||
|
var branchbyte1 = READ_NEXT();
|
||||||
|
var branchbyte2 = READ_NEXT();
|
||||||
|
var branchbyte3 = READ_NEXT();
|
||||||
|
var branchbyte4 = READ_NEXT();
|
||||||
|
|
||||||
|
var branchoffset = (branchbyte1 << 24) | (branchbyte2 << 16) | (branchbyte3 << 8) | branchbyte4;
|
||||||
|
PC = PC + branchoffset;
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(I2B)
|
||||||
|
var value = OPPOP();
|
||||||
|
|
||||||
|
if (IS_OVERFLOW(value,BYTE_MAX_VALUE) || IS_UNDERFLOW(result,BYTE_MIN_VALUE)){
|
||||||
|
OPPUSH(BYTE_OVERFLOW(value));
|
||||||
|
}else{
|
||||||
|
OPPUSH(value);
|
||||||
|
}
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(I2C)
|
||||||
|
var value = OPPOP()
|
||||||
|
|
||||||
|
if (IS_OVERFLOW(value,CHAR_MAX_VALUE) || IS_UNDERFLOW(result,CHAR_MIN_VALUE)){
|
||||||
|
OPPUSH(CHAR_OVERFLOW(value));
|
||||||
|
}else{
|
||||||
|
OPPUSH(value);
|
||||||
|
}
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(I2D)
|
||||||
|
OPPUSH(null);
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(I2F)
|
||||||
|
OPPUSH(null);
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(I2L)
|
||||||
|
//NOP because it is the same size.
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(IADD)
|
||||||
|
var value1 = OPPOP();
|
||||||
|
var value2 = OPPOP();
|
||||||
|
var result = value1 + value2;
|
||||||
|
if (IS_OVERFLOW(result,INT_MAX_VALUE) || IS_UNDERFLOW(result,INT_MIN_VALUE)){
|
||||||
|
OPPUSH(INT_OVERFLOW(result));
|
||||||
|
}else{
|
||||||
|
OPPUSH(result);
|
||||||
|
}
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(IALOAD)
|
||||||
|
var index = OPPOP();
|
||||||
|
var arrayref = OPPOP();
|
||||||
|
|
||||||
|
CHECK_NULL(arrayref);
|
||||||
|
CHECK_ARRAY_INDEX(index,arrayref);
|
||||||
|
|
||||||
|
OPPUSH(arrayref.value[index]);
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(IAND)
|
||||||
|
var value1 = OPPOP()
|
||||||
|
var value2 = OPPOP()
|
||||||
|
var result = value1 & value2
|
||||||
|
OPPUSH(result);
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(IASTORE)
|
||||||
|
var index = OPPOP();
|
||||||
|
var arrayref = OPPOP();
|
||||||
|
var value = OPPOP();
|
||||||
|
|
||||||
|
CHECK_NULL(arrayref);
|
||||||
|
CHECK_ARRAY_INDEX(index,arrayref);
|
||||||
|
|
||||||
|
arrayref.value[index] = value;
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFALIAS(ICONST_M1)
|
||||||
|
DEFALIAS(ICONST_0)
|
||||||
|
DEFALIAS(ICONST_1)
|
||||||
|
DEFALIAS(ICONST_2)
|
||||||
|
DEFALIAS(ICONST_3)
|
||||||
|
DEFALIAS(ICONST_4)
|
||||||
|
DEFALIAS(ICONST_5)
|
||||||
|
DEFNOP()
|
||||||
|
OPPUSH(OPCODE - ICONST_0)
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(IDIV)
|
||||||
|
var value1 = OPPOP();
|
||||||
|
var value2 = OPPOP();
|
||||||
|
if(value2 == 0){
|
||||||
|
JVM_THROWS_NEW(java.lang.ArithmeticException);
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = Math.round(value1 / value2);
|
||||||
|
if (IS_OVERFLOW(result,INT_MAX_VALUE) || IS_UNDERFLOW(result,INT_MIN_VALUE)){
|
||||||
|
OPPUSH(INT_OVERFLOW(result));
|
||||||
|
}else{
|
||||||
|
OPPUSH(result);
|
||||||
|
}
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(IF_ACMPEQ)
|
||||||
|
var branchbyte1 = READ_NEXT();
|
||||||
|
var branchbyte2 = READ_NEXT();
|
||||||
|
var value1 = OPPOP();
|
||||||
|
var value2 = OPPOP();
|
||||||
|
if (value1 == value2){
|
||||||
|
var branchoffset = (branchbyte1 << 8) | branchbyte2;
|
||||||
|
PC = PC + branchoffset;
|
||||||
|
}
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(IF_ACMPNE)
|
||||||
|
var branchbyte1 = READ_NEXT();
|
||||||
|
var branchbyte2 = READ_NEXT();
|
||||||
|
var value1 = OPPOP();
|
||||||
|
var value2 = OPPOP();
|
||||||
|
if (value1 != value2){
|
||||||
|
var branchoffset = (branchbyte1 << 8) | branchbyte2;
|
||||||
|
PC = PC + branchoffset;
|
||||||
|
}
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(IF_ICMPEQ)
|
||||||
|
var branchbyte1 = READ_NEXT();
|
||||||
|
var branchbyte2 = READ_NEXT();
|
||||||
|
var value1 = OPPOP();
|
||||||
|
var value2 = OPPOP();
|
||||||
|
if (value1 == value2){
|
||||||
|
var branchoffset = (branchbyte1 << 8) | branchbyte2;
|
||||||
|
PC = PC + branchoffset;
|
||||||
|
}
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(IF_ICMPNE)
|
||||||
|
var branchbyte1 = READ_NEXT();
|
||||||
|
var branchbyte2 = READ_NEXT();
|
||||||
|
var value1 = OPPOP();
|
||||||
|
var value2 = OPPOP();
|
||||||
|
if (value1 != value2){
|
||||||
|
var branchoffset = (branchbyte1 << 8) | branchbyte2;
|
||||||
|
PC = PC + branchoffset;
|
||||||
|
}
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(IF_ICMPLT)
|
||||||
|
var branchbyte1 = READ_NEXT();
|
||||||
|
var branchbyte2 = READ_NEXT();
|
||||||
|
var value1 = OPPOP();
|
||||||
|
var value2 = OPPOP();
|
||||||
|
if (value1 < value2){
|
||||||
|
var branchoffset = (branchbyte1 << 8) | branchbyte2;
|
||||||
|
PC = PC + branchoffset;
|
||||||
|
}
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(IF_ICMPLE)
|
||||||
|
var branchbyte1 = READ_NEXT();
|
||||||
|
var branchbyte2 = READ_NEXT();
|
||||||
|
var value1 = OPPOP();
|
||||||
|
var value2 = OPPOP();
|
||||||
|
if (value1 <= value2){
|
||||||
|
var branchoffset = (branchbyte1 << 8) | branchbyte2;
|
||||||
|
PC = PC + branchoffset;
|
||||||
|
}
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(IF_ICMPGT)
|
||||||
|
var branchbyte1 = READ_NEXT();
|
||||||
|
var branchbyte2 = READ_NEXT();
|
||||||
|
var value1 = OPPOP();
|
||||||
|
var value2 = OPPOP();
|
||||||
|
if (value1 < value2){
|
||||||
|
var branchoffset = (branchbyte1 << 8) | branchbyte2;
|
||||||
|
PC = PC + branchoffset;
|
||||||
|
}
|
||||||
|
ENDDEF
|
||||||
|
|
||||||
|
DEFOP(IF_ICMPLE)
|
||||||
|
var branchbyte1 = READ_NEXT();
|
||||||
|
var branchbyte2 = READ_NEXT();
|
||||||
|
var value1 = OPPOP();
|
||||||
|
var value2 = OPPOP();
|
||||||
|
if (value1 <= value2){
|
||||||
|
var branchoffset = (branchbyte1 << 8) | branchbyte2;
|
||||||
|
PC = PC + branchoffset;
|
||||||
|
}
|
||||||
|
ENDDEF
|
@ -25,9 +25,9 @@ class index:
|
|||||||
if filename.endswith("favicon.ico"):
|
if filename.endswith("favicon.ico"):
|
||||||
web.webapi.notfound()
|
web.webapi.notfound()
|
||||||
return ""
|
return ""
|
||||||
if filename.endswith(".js"):
|
if filename == "jvm.js":
|
||||||
web.header('Content-Type', 'text/javascript')
|
web.header('Content-Type', 'text/javascript')
|
||||||
return commands.getstatusoutput("/usr/bin/cpp -P -DDEBUG -DDEBUG_INTRP -undef -Wundef -std=c99 -nostdinc -Wtrigraphs -fdollars-in-identifiers ../src/" + filename)[1]
|
return commands.getstatusoutput("cat ../src/*.js | cpp -DDEBUG -DDEBUG_INTRP -I../src/ -P -undef -CC -Wundef -std=c99 -nostdinc -Wtrigraphs -fdollars-in-identifiers")[1]
|
||||||
if "testRuntime" in filename:
|
if "testRuntime" in filename:
|
||||||
alphex = filename[filename.rfind("/") + 1:];
|
alphex = filename[filename.rfind("/") + 1:];
|
||||||
return file("../runtime/" + alphex.replace(".","/") + ".class");
|
return file("../runtime/" + alphex.replace(".","/") + ".class");
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>JS JVM</title>
|
<title>JS JVM</title>
|
||||||
<script src="preload.js" type="text/javascript"></script>
|
|
||||||
<script>
|
<script>
|
||||||
write = function(msg){
|
write = function(msg){
|
||||||
var l = document.getElementById("log");
|
var l = document.getElementById("log");
|
||||||
l.innerHTML = l.innerHTML + msg + "\n";
|
l.innerHTML = l.innerHTML + msg + "\n";
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script src="main.js" type="text/javascript"></script>
|
<script src="jvm.js" type="text/javascript"></script>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
<style>
|
<style>
|
||||||
body{
|
body{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user