зеркало из https://github.com/mozilla/pluotsorbet.git
make interpreter fully preemptive
This commit is contained in:
Родитель
c761251cbc
Коммит
a903846238
17
context.js
17
context.js
|
@ -150,7 +150,7 @@ Context.prototype.newString = function(s) {
|
|||
return obj;
|
||||
}
|
||||
|
||||
Context.prototype.run = function(stopFrame) {
|
||||
Context.prototype.execute = function(stopFrame) {
|
||||
while (this.current() !== stopFrame) {
|
||||
try {
|
||||
VM.execute(this);
|
||||
|
@ -160,3 +160,18 @@ Context.prototype.run = function(stopFrame) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context.prototype.start = function(stopFrame) {
|
||||
if (this.current() === stopFrame)
|
||||
return;
|
||||
var ctx = this;
|
||||
window.setZeroTimeout(function() {
|
||||
try {
|
||||
VM.execute(ctx);
|
||||
} catch (e) {
|
||||
if (e !== VM.Yield)
|
||||
throw e;
|
||||
}
|
||||
ctx.start(stopFrame);
|
||||
});
|
||||
}
|
||||
|
|
6
jvm.js
6
jvm.js
|
@ -42,15 +42,15 @@ JVM.prototype.run = function(className) {
|
|||
|
||||
["java/lang/Object", "java/lang/String", "java/lang/Class", "java/lang/Thread"].forEach(function(className) {
|
||||
ctx.pushClassInitFrame(CLASSES[className.replace("/", "_", "g")] = CLASSES.loadClass(className));
|
||||
ctx.run(caller);
|
||||
ctx.execute(caller);
|
||||
});
|
||||
|
||||
ctx.thread = CLASSES.mainThread = CLASSES.newObject(CLASSES.java_lang_Thread);
|
||||
caller.stack.push(CLASSES.mainThread);
|
||||
caller.stack.push(ctx.newString("main"));
|
||||
ctx.pushFrame(CLASSES.getMethod(CLASSES.java_lang_Thread, "<init>", "(Ljava/lang/String;)V"), 2);
|
||||
ctx.run(caller);
|
||||
ctx.execute(caller);
|
||||
caller.stack.push(CLASSES.newArray("[Ljava/lang/String;", 0));
|
||||
ctx.pushFrame(entryPoint, 1);
|
||||
ctx.run(caller);
|
||||
ctx.start(caller);
|
||||
}
|
||||
|
|
|
@ -231,7 +231,7 @@ Native["java/lang/Thread.start0.()V"] = function(ctx, stack) {
|
|||
caller.stack.push(thread);
|
||||
ctx.frames.push(caller);
|
||||
ctx.pushFrame(run, 1);
|
||||
ctx.run(caller);
|
||||
ctx.start(caller);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче