2014-11-26 12:21:11 +03:00
|
|
|
|
|
|
|
module J2ME {
|
|
|
|
export var CLASSES = new ClassRegistry();
|
|
|
|
declare var util;
|
|
|
|
|
|
|
|
import Isolate = com.sun.cldc.isolate.Isolate;
|
|
|
|
export class JVM {
|
|
|
|
constructor() {
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
|
|
|
|
startIsolate0(className: string, args: string []) {
|
|
|
|
var runtime = new Runtime(this);
|
|
|
|
var ctx = new Context(runtime);
|
2014-12-18 01:04:13 +03:00
|
|
|
ctx.setAsCurrentContext();
|
2014-11-26 12:21:11 +03:00
|
|
|
|
|
|
|
var isolateClassInfo = CLASSES.getClass("com/sun/cldc/isolate/Isolate");
|
|
|
|
var isolate: Isolate = <Isolate>newObject(isolateClassInfo.klass);
|
|
|
|
|
|
|
|
isolate.id = util.id();
|
|
|
|
|
2014-11-27 05:35:12 +03:00
|
|
|
var array = newStringArray(args.length);
|
2014-11-26 12:21:11 +03:00
|
|
|
for (var n = 0; n < args.length; ++n)
|
2014-12-17 07:46:05 +03:00
|
|
|
array[n] = args[n] ? J2ME.newString(args[n]) : null;
|
2014-11-26 12:21:11 +03:00
|
|
|
|
2014-12-17 23:30:14 +03:00
|
|
|
ctx.executeNewFrameSet([
|
|
|
|
new Frame(CLASSES.getMethod(isolateClassInfo, "I.<init>.(Ljava/lang/String;[Ljava/lang/String;)V"),
|
|
|
|
[ isolate, J2ME.newString(className.replace(/\./g, "/")), array ], 0)
|
|
|
|
]);
|
2014-11-26 12:21:11 +03:00
|
|
|
|
2014-12-17 23:30:14 +03:00
|
|
|
ctx.start(new Frame(CLASSES.getMethod(isolateClassInfo, "I.start.()V"), [ isolate ], 0));
|
2014-11-26 12:21:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
startIsolate(isolate: Isolate) {
|
2014-12-09 00:45:30 +03:00
|
|
|
var mainClass = util.fromJavaString(isolate.klass.classInfo.getField("I._mainClass.Ljava/lang/String;").get(isolate)).replace(/\./g, "/");
|
|
|
|
var mainArgs = isolate.klass.classInfo.getField("I._mainArgs.[Ljava/lang/String;").get(isolate);
|
2014-11-26 12:21:11 +03:00
|
|
|
var runtime = new J2ME.Runtime(this);
|
|
|
|
var ctx = new Context(runtime);
|
|
|
|
|
|
|
|
isolate.runtime = runtime;
|
|
|
|
runtime.isolate = isolate;
|
|
|
|
|
|
|
|
runtime.updateStatus(RuntimeStatus.Started);
|
|
|
|
|
|
|
|
var classInfo = CLASSES.getClass(mainClass);
|
|
|
|
if (!classInfo)
|
|
|
|
throw new Error("Could not find or load main class " + mainClass);
|
|
|
|
|
|
|
|
var entryPoint = CLASSES.getEntryPoint(classInfo);
|
|
|
|
if (!entryPoint)
|
|
|
|
throw new Error("Could not find main method in class " + mainClass);
|
|
|
|
|
|
|
|
ctx.thread = runtime.mainThread = util.newObject(CLASSES.java_lang_Thread);
|
|
|
|
ctx.thread.pid = util.id();
|
|
|
|
ctx.thread.alive = true;
|
|
|
|
|
2014-12-12 03:04:44 +03:00
|
|
|
var oldCtx = $.ctx;
|
2014-12-18 01:04:13 +03:00
|
|
|
ctx.setAsCurrentContext();
|
2014-12-17 23:30:14 +03:00
|
|
|
ctx.executeNewFrameSet([new Frame(CLASSES.getMethod(CLASSES.java_lang_Thread, "I.<init>.(Ljava/lang/String;)V"),
|
|
|
|
[ runtime.mainThread, J2ME.newString("main") ], 0)])
|
2014-12-18 01:04:13 +03:00
|
|
|
oldCtx.setAsCurrentContext();
|
2014-11-26 12:21:11 +03:00
|
|
|
|
2014-11-27 05:35:12 +03:00
|
|
|
var args = J2ME.newStringArray(mainArgs.length);
|
2014-12-09 03:04:42 +03:00
|
|
|
for (var n = 0; n < mainArgs.length; ++n) {
|
|
|
|
args[n] = mainArgs[n];
|
|
|
|
}
|
2014-11-26 12:21:11 +03:00
|
|
|
|
2014-12-17 23:30:14 +03:00
|
|
|
ctx.start(new Frame(entryPoint, [ args ], 0));
|
2014-11-26 12:21:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.defineProperty(jsGlobal, "CLASSES", {
|
|
|
|
get: function () {
|
|
|
|
return J2ME.CLASSES;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-14 03:47:42 +03:00
|
|
|
var JVM = J2ME.JVM;
|