pluotsorbet/jvm.js

66 строки
1.6 KiB
JavaScript
Исходник Обычный вид История

2014-07-06 12:29:36 +04:00
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set shiftwidth=4 tabstop=4 autoindent cindent expandtab: */
'use strict';
2014-07-13 01:07:11 +04:00
var LOG, CLASSES, THREADS, NATIVE;
2014-07-06 12:29:36 +04:00
var JVM = function() {
if (this instanceof JVM) {
LOG = new Logger();
CLASSES = new Classes();
THREADS = new Threads();
2014-07-10 09:23:17 +04:00
NATIVE = new Native();
2014-07-12 20:48:05 +04:00
2014-07-06 12:29:36 +04:00
THREADS.add(new Thread("main"));
2014-07-12 20:48:05 +04:00
2014-07-06 12:29:36 +04:00
this.entryPoint = {
className: null,
methodName: "main"
};
} else {
return new JVM();
}
}
JVM.prototype.setEntryPointClassName = function(className) {
this.entryPoint.className = className;
}
JVM.prototype.setEntryPointMethodName = function(methodName) {
this.entryPoint.methodName = methodName;
}
JVM.prototype.setLogLevel = function(level) {
LOG.setLogLevel(level);
}
JVM.prototype.addPath = function(path, data) {
return CLASSES.addPath(path, data);
}
JVM.prototype.loadClassFile = function(fileName) {
return CLASSES.loadClassFile(fileName);
}
JVM.prototype.loadJSFile = function(fileName) {
return CLASSES.loadJSFile(fileName);
}
JVM.prototype.loadJarFile = function(fileName) {
return CLASSES.loadJarFile(fileName);
}
2014-07-13 10:05:35 +04:00
JVM.prototype.start = function() {
2014-07-06 12:29:36 +04:00
var self = this;
2014-07-09 11:12:58 +04:00
2014-07-06 12:29:36 +04:00
var entryPoint = CLASSES.getEntryPoint(this.entryPoint.className, this.entryPoint.methodName);
if (!entryPoint) {
throw new Error("Entry point method is not found.");
}
2014-07-09 11:12:58 +04:00
2014-07-13 10:05:35 +04:00
var toplevel = new Frame();
toplevel.stack.push(null); // args
2014-07-13 11:00:11 +04:00
toplevel.invoke(entryPoint);
2014-07-13 01:07:11 +04:00
}