corrections to most of closure bugs
This commit is contained in:
parent
d0d347dc84
commit
e22a3feaed
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
|||||||
*~
|
*~
|
||||||
*#
|
*#
|
||||||
*.py[co]
|
*.py[co]
|
||||||
|
build
|
||||||
|
15
makefile
15
makefile
@ -1,14 +1,23 @@
|
|||||||
|
|
||||||
|
SRCS=$(wildcard src/*.js)
|
||||||
|
|
||||||
|
OBJS=$(SRCS:.js=.jspp)
|
||||||
|
|
||||||
all: ids
|
all: ids
|
||||||
|
|
||||||
ids:
|
ids:
|
||||||
cd webserver && python app.py
|
cd webserver && python app.py
|
||||||
|
|
||||||
preprocess:
|
%.jspp: %.js
|
||||||
|
cpp -P -undef -CC -Wundef -std=c99 -nostdinc -Wtrigraphs -fdollars-in-identifiers $< `echo $@ | sed s/src/build/`
|
||||||
|
|
||||||
|
builddir:
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
/usr/bin/cpp -P -undef -CC -Wundef -std=c99 -nostdinc -Wtrigraphs -fdollars-in-identifiers src/main.js build/pp_jvm.js
|
|
||||||
|
preprocess: builddir $(OBJS)
|
||||||
|
|
||||||
compile: preprocess
|
compile: preprocess
|
||||||
java -jar lib/compiler.jar --warning_level VERBOSE --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 `find build/ -name *.jspp -exec echo --js {} \;` --js_output_file build/jvm.js
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -dR build
|
rm -dR build
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
* Author: Artur Ventura
|
* Author: Artur Ventura
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "constantPool.jsh"
|
||||||
|
|
||||||
/** @constructor */
|
/** @constructor */
|
||||||
var ExceptionTableEntry = function(dStream, constantPool){
|
var ExceptionTableEntry = function(dStream, constantPool){
|
||||||
@ -191,4 +193,4 @@ var Attribute = function(dStream, constantPool){
|
|||||||
result.attribute_length = dStream.getU4();
|
result.attribute_length = dStream.getU4();
|
||||||
result.read(dStream, constantPool);
|
result.read(dStream, constantPool);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
15
src/class.js
15
src/class.js
@ -9,19 +9,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define CLASS_MAGIC 0xCAFEBABE
|
#include "constantPool.jsh"
|
||||||
|
#include "class.jsh"
|
||||||
#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.
|
|
||||||
#define ACC_STATIC 0x0008 // Declared static.
|
|
||||||
#define ACC_FINAL 0x0010 // Declared final; no subclasses allowed.
|
|
||||||
#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.
|
|
||||||
|
|
||||||
function slurpFile (filename, fa) {
|
function slurpFile (filename, fa) {
|
||||||
var xmlHttpRequest, response, result ;
|
var xmlHttpRequest, response, result ;
|
||||||
|
25
src/class.jsh
Normal file
25
src/class.jsh
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* -*- Mode: Javascript -*-
|
||||||
|
* -*- coding: UTF-8 -*-
|
||||||
|
* Copyright (C) 2011 by Artur Ventura
|
||||||
|
*
|
||||||
|
* File: class.jsh
|
||||||
|
*
|
||||||
|
* Author: Artur Ventura
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#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.
|
||||||
|
#define ACC_STATIC 0x0008 // Declared static.
|
||||||
|
#define ACC_FINAL 0x0010 // Declared final; no subclasses allowed.
|
||||||
|
#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.
|
@ -9,20 +9,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define CONSTANT_Utf8 1
|
#include "constantPool.jsh"
|
||||||
//what is CONSTANT_????? 2
|
|
||||||
#define CONSTANT_Integer 3
|
|
||||||
#define CONSTANT_Float 4
|
|
||||||
#define CONSTANT_Long 5
|
|
||||||
#define CONSTANT_Double 6
|
|
||||||
#define CONSTANT_Class 7
|
|
||||||
#define CONSTANT_String 8
|
|
||||||
#define CONSTANT_Fieldref 9
|
|
||||||
#define CONSTANT_Methodref 10
|
|
||||||
#define CONSTANT_InterfaceMethodref 11
|
|
||||||
#define CONSTANT_NameAndType 12
|
|
||||||
|
|
||||||
// constant pool members
|
|
||||||
|
|
||||||
/** @constructor */
|
/** @constructor */
|
||||||
var constUtf8 = function(){
|
var constUtf8 = function(){
|
||||||
|
22
src/constantPool.jsh
Normal file
22
src/constantPool.jsh
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/* -*- Mode: Javascript -*-
|
||||||
|
* -*- coding: UTF-8 -*-
|
||||||
|
* Copyright (C) 2011 by Artur Ventura
|
||||||
|
*
|
||||||
|
* File: constantPool.jsh
|
||||||
|
*
|
||||||
|
* Author: Artur Ventura
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define CONSTANT_Utf8 1
|
||||||
|
//what is CONSTANT_????? 2
|
||||||
|
#define CONSTANT_Integer 3
|
||||||
|
#define CONSTANT_Float 4
|
||||||
|
#define CONSTANT_Long 5
|
||||||
|
#define CONSTANT_Double 6
|
||||||
|
#define CONSTANT_Class 7
|
||||||
|
#define CONSTANT_String 8
|
||||||
|
#define CONSTANT_Fieldref 9
|
||||||
|
#define CONSTANT_Methodref 10
|
||||||
|
#define CONSTANT_InterfaceMethodref 11
|
||||||
|
#define CONSTANT_NameAndType 12
|
41
src/cpu.js
41
src/cpu.js
@ -9,40 +9,11 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "opcodes.js"
|
#include "constantPool.jsh"
|
||||||
#import "types.js"
|
#include "opcodes.jsh"
|
||||||
#define JVM_THROWS_NEW(exception) throw "VER: throws new exception"
|
#include "types.jsh"
|
||||||
#ifdef DEBUG_INTRP
|
#include "cpu.jsh"
|
||||||
#define LOG_INTRP(x) LOG(x)
|
|
||||||
#define DEFALIAS(opx) case opx: if(temp!=null) { temp = pc + ": opx" }
|
|
||||||
|
|
||||||
#else
|
|
||||||
#define LOG_INTRP(x)
|
|
||||||
#define DEFALIAS(opx) case opx:
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define PANIC(msg) throw new JVMPanic(msg)
|
|
||||||
|
|
||||||
#define DEFOP(opx) case opx: LOG_INTRP(pc + ": opx");
|
|
||||||
#define DEFNOP() LOG_INTRP(temp)
|
|
||||||
#define ENDDEF break;
|
|
||||||
|
|
||||||
#define OPPOP() operand_stack.pop()
|
|
||||||
#define OPPUSH(v) operand_stack.push(v)
|
|
||||||
|
|
||||||
#define OPPOPD() operand_stack.pop() && operand_stack.pop()
|
|
||||||
#define OPPUSHD(v) operand_stack.push(v) && operand_stack.push(null)
|
|
||||||
|
|
||||||
#define OPSTACK(v) operand_stack[v]
|
|
||||||
#define OPSTACK_LENGTH() operand_stack.length
|
|
||||||
|
|
||||||
#define LOCAL_VAR(v) local_variables[v]
|
|
||||||
#define OPCODE opcode
|
|
||||||
#define PC pc
|
|
||||||
#define STACK_MOVE(y,x) OPSTACK(OPSTACK_LENGTH()-y) = OPSTACK(OPSTACK_LENGTH()-x)
|
|
||||||
#define READ_NEXT() code[++pc]
|
|
||||||
|
|
||||||
#define canonicalName(ref) ref.str.replace(/\//g,".")
|
|
||||||
/** @constructor */
|
/** @constructor */
|
||||||
var JVM = function(params,args){
|
var JVM = function(params,args){
|
||||||
this.nativeMappingTable = {}
|
this.nativeMappingTable = {}
|
||||||
@ -128,6 +99,6 @@ function interpret(frame){
|
|||||||
var temp = null;
|
var temp = null;
|
||||||
#endif
|
#endif
|
||||||
switch(OPCODE){
|
switch(OPCODE){
|
||||||
#include "intrp.js"
|
#include "intrp.def"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
56
src/cpu.jsh
Normal file
56
src/cpu.jsh
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/* -*- Mode: Javascript -*-
|
||||||
|
* -*- coding: UTF-8 -*-
|
||||||
|
* Copyright (C) 2011 by Artur Ventura
|
||||||
|
*
|
||||||
|
* File: cpu.jsh
|
||||||
|
*
|
||||||
|
* Author: Artur Ventura
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _CPU_JSH_
|
||||||
|
#define _CPU_JSH_
|
||||||
|
|
||||||
|
#include "log.jsh"
|
||||||
|
|
||||||
|
#define JVM_THROWS_NEW(exception) throw "VER: throws new exception"
|
||||||
|
#ifdef DEBUG_INTRP
|
||||||
|
#define LOG_INTRP(x) LOG(x)
|
||||||
|
#define DEFALIAS(opx) case opx: if(temp!=null) { temp = pc + ": opx" }
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define LOG_INTRP(x)
|
||||||
|
#define DEFALIAS(opx) case opx:
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define PANIC(msg) throw new JVMPanic(msg)
|
||||||
|
|
||||||
|
#define DEFOP(opx) case opx: LOG_INTRP(pc + ": opx");
|
||||||
|
#define DEFNOP() LOG_INTRP(temp)
|
||||||
|
#define ENDDEF break;
|
||||||
|
|
||||||
|
#define OPPOP() operand_stack.pop()
|
||||||
|
#define OPPUSH(v) operand_stack.push(v)
|
||||||
|
|
||||||
|
#define OPPOPD() operand_stack.pop() && operand_stack.pop()
|
||||||
|
#define OPPUSHD(v) operand_stack.push(v) && operand_stack.push(null)
|
||||||
|
|
||||||
|
#define OPSTACK(v) operand_stack[v]
|
||||||
|
#define OPSTACK_LENGTH() operand_stack.length
|
||||||
|
|
||||||
|
#define LOCAL_VAR(v) local_variables[v]
|
||||||
|
#define OPCODE opcode
|
||||||
|
#define PC pc
|
||||||
|
#define STACK_MOVE(y,x) OPSTACK(OPSTACK_LENGTH()-y) = OPSTACK(OPSTACK_LENGTH()-x)
|
||||||
|
#define READ_NEXT() code[++pc]
|
||||||
|
|
||||||
|
#define CHECK_NULL(ref) if (ref == NULL){ JVM_THROWS_NEW(java.lang.NullPointerException); }
|
||||||
|
#define CHECK_ARRAY_INDEX(ind,ref) if (ind >= 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_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));}
|
||||||
|
|
||||||
|
function canonicalName(ref) {return ref.str.replace(/\//g,".");}
|
||||||
|
|
||||||
|
#endif //_CPU_JSH_
|
@ -9,6 +9,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "constantPool.jsh"
|
||||||
|
|
||||||
/** @constructor */
|
/** @constructor */
|
||||||
var FieldInfo = function(dStream,constantPool){
|
var FieldInfo = function(dStream,constantPool){
|
||||||
this.access_flags = dStream.getU2();
|
this.access_flags = dStream.getU2();
|
||||||
@ -33,4 +35,4 @@ var MethodInfo = function(dStream, constantPool){
|
|||||||
for (var i=0; i<this.attributes_count; i++){
|
for (var i=0; i<this.attributes_count; i++){
|
||||||
this.attributes[i] = Attribute(dStream,constantPool);
|
this.attributes[i] = Attribute(dStream,constantPool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "opcodes.js"
|
|
||||||
#define CHECK_NULL(ref) if (ref == NULL){ JVM_THROWS_NEW(java.lang.NullPointerException); }
|
|
||||||
#define CHECK_ARRAY_INDEX(ind,ref) if (ind >= 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_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)
|
DEFOP(AALOAD)
|
||||||
/*
|
/*
|
||||||
* ..., array ref, index -> ..., ref value
|
* ..., array ref, index -> ..., ref value
|
18
src/log.jsh
Normal file
18
src/log.jsh
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/* -*- Mode: Javascript -*-
|
||||||
|
* -*- coding: UTF-8 -*-
|
||||||
|
* Copyright (C) 2011 by Artur Ventura
|
||||||
|
*
|
||||||
|
* File: log.jsh
|
||||||
|
*
|
||||||
|
* Author: Artur Ventura
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DEBUG
|
||||||
|
#define LOG(msg)
|
||||||
|
#else
|
||||||
|
#define LOG(msg) write(msg);\
|
||||||
|
if (console){\
|
||||||
|
console.log(msg);\
|
||||||
|
}
|
||||||
|
#endif
|
20
src/main.js
20
src/main.js
@ -9,26 +9,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DEBUG
|
|
||||||
#define LOG(msg)
|
|
||||||
#else
|
|
||||||
#define LOG(msg) write(msg);\
|
|
||||||
if (console){\
|
|
||||||
console.log(msg);\
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "linearDataStream.js"
|
|
||||||
#include "constantPool.js"
|
|
||||||
#include "attributes.js"
|
|
||||||
#include "infos.js"
|
|
||||||
#include "class.js"
|
|
||||||
#include "cpu.js"
|
|
||||||
#include "types.js"
|
|
||||||
|
|
||||||
|
|
||||||
var test_jvm;
|
var test_jvm;
|
||||||
function main (args){
|
function main (args){
|
||||||
test_jvm = new JVM({},["foo"])
|
test_jvm = new JVM({},["foo"])
|
||||||
test_jvm.run();
|
test_jvm.run();
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,10 @@
|
|||||||
* Author: Artur Ventura
|
* Author: Artur Ventura
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _TYPES_JSH_
|
||||||
|
#define _TYPES_JSH_
|
||||||
|
|
||||||
// Local Variables Types
|
// Local Variables Types
|
||||||
#define LOC_VAR_boolean 0x001;
|
#define LOC_VAR_boolean 0x001;
|
||||||
#define LOC_VAR_byte 0x002;
|
#define LOC_VAR_byte 0x002;
|
||||||
@ -86,5 +89,5 @@
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
#endif //_TYPES_JSH_
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user