зеркало из https://github.com/mozilla/pluotsorbet.git
Add object arrays.
This commit is contained in:
Родитель
b34379cc7e
Коммит
ec70b204a3
|
@ -304,28 +304,18 @@ module J2ME.C4.Backend {
|
|||
|
||||
IR.JVMCheckCast.prototype.compile = function (cx: Context): AST.Node {
|
||||
var object = compileValue(this.object, cx);
|
||||
var runtimeFunction;
|
||||
if (this.classInfo.isArrayClass) {
|
||||
runtimeFunction = "$CCA";
|
||||
} else {
|
||||
runtimeFunction = "$CCK";
|
||||
if (this.classInfo.isInterface) {
|
||||
runtimeFunction = "$CCI";
|
||||
}
|
||||
var runtimeFunction = "$CCK";
|
||||
if (this.classInfo.isInterface) {
|
||||
runtimeFunction = "$CCI";
|
||||
}
|
||||
return new AST.CallExpression(new AST.Identifier(runtimeFunction), [object, id(mangleClass(this.classInfo))]);
|
||||
};
|
||||
|
||||
IR.JVMInstanceOf.prototype.compile = function (cx: Context): AST.Node {
|
||||
var object = compileValue(this.object, cx);
|
||||
var runtimeFunction;
|
||||
if (this.classInfo.isArrayClass) {
|
||||
runtimeFunction = "$IOA";
|
||||
} else {
|
||||
runtimeFunction = "$IOK";
|
||||
if (this.classInfo.isInterface) {
|
||||
runtimeFunction = "$IOI";
|
||||
}
|
||||
var runtimeFunction = "$IOK";
|
||||
if (this.classInfo.isInterface) {
|
||||
runtimeFunction = "$IOI";
|
||||
}
|
||||
return new AST.CallExpression(new AST.Identifier(runtimeFunction), [object, id(mangleClass(this.classInfo))]);
|
||||
};
|
||||
|
@ -365,7 +355,7 @@ module J2ME.C4.Backend {
|
|||
};
|
||||
|
||||
IR.JVMNewObjectArray.prototype.compile = function (cx: Context): AST.Node {
|
||||
return new AST.NewExpression(new AST.Identifier("Array"), [compileValue(this.length, cx)]);
|
||||
return call(id("$NA"), [id(this.classInfo.mangledName), compileValue(this.length, cx)]);
|
||||
};
|
||||
|
||||
IR.JVMStoreIndexed.prototype.compile = function (cx: Context): AST.Node {
|
||||
|
@ -652,7 +642,7 @@ module J2ME.C4.Backend {
|
|||
|
||||
export function mangleClass(classInfo: ClassInfo) {
|
||||
if (classInfo.isArrayClass) {
|
||||
return "arrayOf(" + mangleClass(classInfo.elementClass) + ")";
|
||||
return "$AK(" + mangleClass(classInfo.elementClass) + ")";
|
||||
} else {
|
||||
if (friendlyMangledNames) {
|
||||
return mangleString(classInfo.className);
|
||||
|
|
4
jvm.js
4
jvm.js
|
@ -35,7 +35,7 @@ JVM.prototype.startIsolate0 = function(className, args) {
|
|||
var isolate = util.newObject(com_sun_cldc_isolate_Isolate);
|
||||
isolate.id = util.id();
|
||||
|
||||
var array = util.newArray("[Ljava/lang/String;", args.length);
|
||||
var array = J2ME.newArray(J2ME.Klasses.java.lang.String, args.length);
|
||||
for (var n = 0; n < args.length; ++n)
|
||||
array[n] = args[n] ? util.newString(args[n]) : null;
|
||||
|
||||
|
@ -79,7 +79,7 @@ JVM.prototype.startIsolate = function(isolate) {
|
|||
[ runtime.mainThread, util.newString("main") ], 0));
|
||||
ctx.execute();
|
||||
|
||||
var args = util.newArray("[Ljava/lang/String;", mainArgs.length);
|
||||
var args = J2ME.newArray(J2ME.Klasses.java.lang.String, mainArgs.length);
|
||||
for (var n = 0; n < mainArgs.length; ++n)
|
||||
args[n] = mainArgs[n] ? util.newString(mainArgs[n]) : null;
|
||||
|
||||
|
|
58
runtime.ts
58
runtime.ts
|
@ -4,6 +4,17 @@ var runtimeTemplate = {};
|
|||
|
||||
module J2ME {
|
||||
|
||||
export var Klasses = {
|
||||
java: {
|
||||
lang: {
|
||||
Object: null,
|
||||
Class: null,
|
||||
String: null,
|
||||
Thread: null
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export var consoleWriter = new IndentingWriter();
|
||||
|
||||
export enum ExecutionPhase {
|
||||
|
@ -139,6 +150,11 @@ module J2ME {
|
|||
export interface Klass extends Function {
|
||||
new (): java.lang.Object;
|
||||
|
||||
/**
|
||||
* Array klass of this klass constructed via \arrayKlass\.
|
||||
*/
|
||||
arrayKlass: ArrayKlass;
|
||||
|
||||
superKlass: Klass;
|
||||
|
||||
/**
|
||||
|
@ -175,6 +191,7 @@ module J2ME {
|
|||
|
||||
export interface ArrayKlass extends Klass {
|
||||
elementKlass: Klass;
|
||||
|
||||
}
|
||||
|
||||
export module java.lang {
|
||||
|
@ -284,9 +301,15 @@ module J2ME {
|
|||
release || assert(!classInfo.klass);
|
||||
classInfo.klass = klass;
|
||||
} else {
|
||||
classInfo.klass = createKlass(classInfo);
|
||||
classInfo.klass = klass = createKlass(classInfo);
|
||||
}
|
||||
classInfo.klass.classInfo = classInfo;
|
||||
switch (classInfo.className) {
|
||||
case "java/lang/Object": Klasses.java.lang.Object = klass; break;
|
||||
case "java/lang/Class": Klasses.java.lang.Class = klass; break;
|
||||
case "java/lang/String": Klasses.java.lang.String = klass; break;
|
||||
case "java/lang/Thread": Klasses.java.lang.Thread = klass; break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -329,10 +352,6 @@ module J2ME {
|
|||
return object.klass.display[klass.depth] === klass;
|
||||
}
|
||||
|
||||
export function instanceOfArray(object: java.lang.Object, klass: Klass): boolean {
|
||||
return object.klass.display[klass.depth] === klass;
|
||||
}
|
||||
|
||||
export function checkCast(object: java.lang.Object, klass: Klass) {
|
||||
return false; // TODO: Generic
|
||||
}
|
||||
|
@ -347,14 +366,30 @@ module J2ME {
|
|||
|
||||
}
|
||||
|
||||
export function checkCastArray(object: java.lang.Object, klass: Klass) {
|
||||
|
||||
}
|
||||
|
||||
export function newObject(klass: Klass): java.lang.Object {
|
||||
return new klass();
|
||||
}
|
||||
|
||||
export function newArray(klass: Klass, size: number) {
|
||||
var constructor: any = arrayKlass(klass);
|
||||
return new constructor(size);
|
||||
}
|
||||
|
||||
export function arrayKlass(klass: Klass): Klass {
|
||||
if (klass.arrayKlass) {
|
||||
return klass.arrayKlass;
|
||||
}
|
||||
var arrayKlass = klass.arrayKlass = <ArrayKlass><any>function (size: number) {
|
||||
var array: any = new Array(size);
|
||||
array.klass = arrayKlass;
|
||||
return array;
|
||||
};
|
||||
arrayKlass.elementKlass = klass;
|
||||
arrayKlass.superKlass = Klasses.java.lang.Object;
|
||||
initializeKlassTables(arrayKlass);
|
||||
return arrayKlass;
|
||||
}
|
||||
|
||||
export function toDebugString(object: java.lang.Object): string {
|
||||
if (!object) {
|
||||
return "null";
|
||||
|
@ -374,8 +409,9 @@ var $RK = J2ME.registerKlass;
|
|||
|
||||
var $IOK = J2ME.instanceOfKlass;
|
||||
var $IOI = J2ME.instanceOfInterface;
|
||||
var $IOA = J2ME.instanceOfArray;
|
||||
|
||||
var $CCK = J2ME.checkCastKlass;
|
||||
var $CCI = J2ME.checkCastInterface;
|
||||
var $CCA = J2ME.checkCastArray;
|
||||
|
||||
var $AK = J2ME.arrayKlass;
|
||||
var $NA = J2ME.newArray;
|
6
util.js
6
util.js
|
@ -116,8 +116,10 @@ var util = (function () {
|
|||
return new constructor(size);
|
||||
}
|
||||
|
||||
function newArray(typeName, size) {
|
||||
return new (CLASSES.getClass(typeName).constructor)(size);
|
||||
|
||||
// Remove
|
||||
function newArray(classInfo, size) {
|
||||
return J2ME.newArray(classInfo.klass, size);
|
||||
}
|
||||
|
||||
function newMultiArray(typeName, lengths) {
|
||||
|
|
2
vm.js
2
vm.js
|
@ -837,7 +837,7 @@ VM.execute = function(ctx) {
|
|||
if (className[0] !== "[")
|
||||
className = "L" + className + ";";
|
||||
className = "[" + className;
|
||||
stack.push(util.newArray(className, size));
|
||||
stack.push(util.newArray(classInfo, size));
|
||||
break;
|
||||
case 0xc5: // multianewarray
|
||||
var idx = frame.read16();
|
||||
|
|
Загрузка…
Ссылка в новой задаче