Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasgal committed Jul 10, 2014
1 parent 7972db1 commit 44e5a5a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 44 deletions.
39 changes: 19 additions & 20 deletions classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ Classes.prototype.getEntryPoint = function(className, methodName) {
if (ACCESS_FLAGS.isPublic(ca.getAccessFlags())) {
var methods = ca.getMethods();
var cp = ca.getConstantPool();
for(var i=0; i<methods.length; i++) {
if
(
ACCESS_FLAGS.isPublic(methods[i].access_flags) &&
ACCESS_FLAGS.isStatic(methods[i].access_flags) &&
cp[methods[i].name_index].bytes === methodName
)
{ return new Frame(ca, methods[i]); }
for (var i=0; i<methods.length; i++) {
if (ACCESS_FLAGS.isPublic(methods[i].access_flags) &&
ACCESS_FLAGS.isStatic(methods[i].access_flags) &&
!ACCESS_FLAGS.isNative(methods[i].access_flags) &&
cp[methods[i].name_index].bytes === methodName) {
return new Frame(ca, methods[i]);
}
}
}
}
Expand Down Expand Up @@ -120,18 +119,18 @@ Classes.prototype.setStaticField = function(className, fieldName, value) {
Classes.prototype.getMethod = function(className, methodName, signature, staticFlag) {
// Only force initialization when accessing a static method.
var ca = this.getClass(className, staticFlag);
if (ca instanceof ClassArea) {
var methods = ca.getMethods();
var cp = ca.getConstantPool();
for(var i=0; i<methods.length; i++) {
if (ACCESS_FLAGS.isStatic(methods[i].access_flags) === !!staticFlag)
if (cp[methods[i].name_index].bytes === methodName)
if (signature.toString() === cp[methods[i].signature_index].bytes)
return new Frame(ca, methods[i]);
}
} else {
if (methodName in ca) {
return ca[methodName];
var methods = ca.getMethods();
var cp = ca.getConstantPool();
for (var i=0; i<methods.length; i++) {
if (ACCESS_FLAGS.isStatic(methods[i].access_flags) === !!staticFlag) {
if (cp[methods[i].name_index].bytes === methodName) {
if (signature.toString() === cp[methods[i].signature_index].bytes) {
if (ACCESS_FLAGS.isNative(methods[i].access_flags)) {
return NATIVE.getMethod(className, methodName, signature.toString());
}
return new Frame(ca, methods[i], className, methodName, signature);
}
}
}
}
return null;
Expand Down
42 changes: 20 additions & 22 deletions frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var Frame = function(classArea, method) {
break;
}
}

} else {
return new Frame(classArea, method);
}
Expand Down Expand Up @@ -1443,15 +1442,31 @@ Frame.prototype.putstatic = function(done) {
return done();
}

Frame.prototype._invoke = function(method, signature, args, done) {
if (method instanceof Frame) {
method.setPid(this._pid);
method.run(args, function(res) {
if (signature.OUT.length != 0) {
this._stack.push(res);
}
return done();
});
} else {
var res = method.apply(null, args);
if (signature.OUT.length != 0) {
this._stack.push(res);
}
return done();
}
}

Frame.prototype.invokestatic = function(done) {
var self = this;

var idx = this._read16();

var className = this._cp[this._cp[this._cp[idx].class_index].name_index].bytes;
var methodName = this._cp[this._cp[this._cp[idx].name_and_type_index].name_index].bytes;
var signature = Signature.parse(this._cp[this._cp[this._cp[idx].name_and_type_index].signature_index].bytes);

var args = [];
for (var i=0; i<signature.IN.length; i++) {
if (!signature.IN[i].isArray && ["long", "double"].indexOf(signature.IN[i].type) !== -1) {
Expand All @@ -1462,23 +1477,7 @@ Frame.prototype.invokestatic = function(done) {
}
}

var method = CLASSES.getStaticMethod(className, methodName, signature);

if (method instanceof Frame) {
method.setPid(self._pid);
method.run(args, function(res) {
if (signature.OUT.length != 0) {
self._stack.push(res);
}
return done();
});
} else {
var res = method.apply(null, args);
if (signature.OUT.length != 0) {
self._stack.push(res);
}
return done();
}
this._invoke(CLASSES.getStaticMethod(className, methodName, signature), signature, args, done);
}


Expand Down Expand Up @@ -1698,7 +1697,6 @@ Frame.prototype.checkcast = function(done) {
return done();
}


Frame.prototype.athrow = function(done) {
this._throw(this._stack.pop());
return done();
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<script type="text/javascript" src="signature.js"></script>
<script type="text/javascript" src="opcodes.js"></script>
<script type="text/javascript" src="classes.js"></script>
<script type="text/javascript" src="native.js"></script>
<script type="text/javascript" src="frame.js"></script>
<script type="text/javascript" src="scheduler.js"></script>
<script type="text/javascript" src="thread.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion java/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ CLDC1_1_1_SRC=$(shell find cldc1.1.1 -name *.java) $(shell find vm -name *.java)
cldc1_1_1.jar: $(CLDC1_1_1_SRC)
rm -rf build
mkdir build
javac -d ./build $^
javac -source 1.3 -d ./build $^
cd build && jar cvf ../cldc1.1.1.jar *
rm -rf build
3 changes: 2 additions & 1 deletion jvm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

'use strict';

var LOG, CLASSES, THREADS, SCHEDULER;
var LOG, CLASSES, THREADS, SCHEDULER, NATIVE;

var JVM = function() {
if (this instanceof JVM) {
LOG = new Logger();
CLASSES = new Classes();
THREADS = new Threads();
SCHEDULER = new Scheduler();
NATIVE = new Native();

THREADS.add(new Thread("main"));

Expand Down

0 comments on commit 44e5a5a

Please sign in to comment.