Skip to content
This repository was archived by the owner on Aug 20, 2018. It is now read-only.

Commit f089da3

Browse files
committed
Merge pull request #1842 from brendandahl/intex-const
Use const enums everywhere.
2 parents cfffa95 + fe915af commit f089da3

File tree

13 files changed

+91
-67
lines changed

13 files changed

+91
-67
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ PREPROCESS_SRCS = \
194194
$(NULL)
195195
PREPROCESS_DESTS = $(PREPROCESS_SRCS:.in=)
196196

197-
all: config-build java jasmin tests j2me shumway aot bench/benchmark.jar bld/main-all.js
197+
all: config-build java jasmin tests j2me shumway bench/benchmark.jar bld/main-all.js
198198

199199
$(shell mkdir -p build_tools)
200200

@@ -358,19 +358,19 @@ vm/native/Boehm.js/.libs/$(BOEHM_LIB):
358358

359359
bld/j2me.js: Makefile $(BASIC_SRCS) $(JIT_SRCS) bld/native.js build_tools/closure.jar .checksum
360360
@echo "Building J2ME"
361-
tsc --sourcemap --target ES5 references.ts -d --out bld/j2me.js
361+
tsc --preserveConstEnums --sourcemap --target ES5 references.ts -d --out bld/j2me.js
362362
ifeq ($(RELEASE),1)
363363
java -jar build_tools/closure.jar --formatting PRETTY_PRINT --warning_level $(CLOSURE_WARNING_LEVEL) --language_in ECMASCRIPT5 -O $(J2ME_JS_OPTIMIZATION_LEVEL) bld/j2me.js > bld/j2me.cc.js \
364364
&& mv bld/j2me.cc.js bld/j2me.js
365365
endif
366366

367367
bld/j2me-jsc.js: $(BASIC_SRCS) $(JIT_SRCS)
368368
@echo "Building J2ME AOT Compiler"
369-
tsc --sourcemap --target ES5 references-jsc.ts -d --out bld/j2me-jsc.js
369+
tsc --preserveConstEnums --sourcemap --target ES5 references-jsc.ts -d --out bld/j2me-jsc.js
370370

371371
bld/jsc.js: jsc.ts bld/j2me-jsc.js
372372
@echo "Building J2ME JSC CLI"
373-
tsc --sourcemap --target ES5 jsc.ts --out bld/jsc.js
373+
tsc --preserveConstEnums --sourcemap --target ES5 jsc.ts --out bld/jsc.js
374374

375375
# Some scripts use ES6 features, so we have to specify ES6 as the in-language
376376
# in order for Closure to compile them, even though for now we're optimizing

bytecodes.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module J2ME.Bytecode {
7272
}
7373
}
7474

75-
export enum Condition {
75+
export const enum Condition {
7676
/**
7777
* Equal.
7878
*/
@@ -147,7 +147,7 @@ module J2ME.Bytecode {
147147
* bytecodes share a common first byte and carry additional instruction-specific
148148
* information in the second and third bytes.
149149
*/
150-
export enum Bytecodes {
150+
export const enum Bytecodes {
151151
NOP = 0, // 0x00
152152
ACONST_NULL = 1, // 0x01
153153
ICONST_M1 = 2, // 0x02
@@ -371,6 +371,10 @@ module J2ME.Bytecode {
371371
LAST_JVM_OPCODE = Bytecodes.JSR_W
372372
}
373373

374+
export function getBytecodesName(bytecode: Bytecodes): string {
375+
return (<any>Bytecode).Bytecodes[bytecode];
376+
}
377+
374378
const enum Flags {
375379
/**
376380
* Denotes an instruction that ends a basic block and does not let control flow fall through to its lexical successor.

int.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ module J2ME {
192192
i32[this.fp + FrameLayout.CallerSaveSize + i] = v;
193193
break;
194194
default:
195-
release || assert(false, "Cannot set stack slot of kind: " + Kind[kind]);
195+
release || assert(false, "Cannot set stack slot of kind: " + getKindName(kind));
196196
}
197197
}
198198

@@ -261,7 +261,7 @@ module J2ME {
261261
op = this.methodInfo.codeAttribute.code[this.pc];
262262
}
263263
var type = i32[this.fp + FrameLayout.FrameTypeOffset];
264-
writer.writeLn("Frame: " + FrameType[type] + " " + (this.methodInfo ? this.methodInfo.implKey : "null") + ", FP: " + this.fp + "(" + (this.fp - (this.thread.tp >> 2)) + "), SP: " + this.sp + ", PC: " + this.pc + (op >= 0 ? ", OP: " + Bytecodes[op] : ""));
264+
writer.writeLn("Frame: " + FrameType[type] + " " + (this.methodInfo ? this.methodInfo.implKey : "null") + ", FP: " + this.fp + "(" + (this.fp - (this.thread.tp >> 2)) + "), SP: " + this.sp + ", PC: " + this.pc + (op >= 0 ? ", OP: " + Bytecode.getBytecodesName(op) : ""));
265265
if (details) {
266266
for (var i = Math.max(0, this.fp + this.parameterOffset); i < this.sp; i++) {
267267
var prefix = " ";
@@ -726,7 +726,7 @@ module J2ME {
726726
return;
727727
}
728728
if (!(getKindCheck(methodInfo.returnKind)(l, h))) {
729-
assert(false, "Expected " + Kind[methodInfo.returnKind] + " return value, got low: " + l + " high: " + h + " in " + methodInfo.implKey);
729+
assert(false, "Expected " + getKindName(methodInfo.returnKind) + " return value, got low: " + l + " high: " + h + " in " + methodInfo.implKey);
730730
}
731731
}
732732

@@ -807,7 +807,7 @@ module J2ME {
807807
if (traceStackWriter) {
808808
frame.set(thread, fp, sp, opPC); frame.trace(traceStackWriter);
809809
traceStackWriter.writeLn();
810-
traceStackWriter.greenLn(mi.implKey + ": PC: " + opPC + ", FP: " + fp + ", " + Bytecodes[op]);
810+
traceStackWriter.greenLn(mi.implKey + ": PC: " + opPC + ", FP: " + fp + ", " + Bytecode.getBytecodesName(op));
811811
}
812812
}
813813

@@ -862,7 +862,7 @@ module J2ME {
862862
} else if (tag === TAGS.CONSTANT_String) {
863863
i32[sp++] = cp.resolve(index, tag, false);
864864
} else {
865-
release || assert(false, TAGS[tag]);
865+
release || assert(false, getTAGSName(tag));
866866
}
867867
continue;
868868
case Bytecodes.LDC2_W:
@@ -875,7 +875,7 @@ module J2ME {
875875
i32[sp ] = buffer[offset++] << 24 | buffer[offset++] << 16 | buffer[offset++] << 8 | buffer[offset++];
876876
sp += 2;
877877
} else {
878-
release || assert(false, TAGS[tag]);
878+
release || assert(false, getTAGSName(tag));
879879
}
880880
continue;
881881
case Bytecodes.ILOAD:
@@ -1606,7 +1606,7 @@ module J2ME {
16061606
}
16071607

16081608
if (U) {
1609-
traceWriter && traceWriter.writeLn("<< I Unwind: " + VMState[U]);
1609+
traceWriter && traceWriter.writeLn("<< I Unwind: " + getVMStateName(U));
16101610
release || assert(thread.unwoundNativeFrames.length, "Must have unwound frames.");
16111611
thread.nativeFrameCount--;
16121612
i32[frameTypeOffset] = FrameType.PushPendingFrames;
@@ -1637,7 +1637,7 @@ module J2ME {
16371637
case Kind.Void:
16381638
return;
16391639
default:
1640-
release || assert(false, "Invalid Kind: " + Kind[kind]);
1640+
release || assert(false, "Invalid Kind: " + getKindName(kind));
16411641
}
16421642
}
16431643

@@ -1670,7 +1670,7 @@ module J2ME {
16701670
case Kind.Void:
16711671
continue;
16721672
default:
1673-
release || assert(false, "Invalid Kind: " + Kind[kind]);
1673+
release || assert(false, "Invalid Kind: " + getKindName(kind));
16741674
}
16751675
}
16761676
}
@@ -2030,7 +2030,7 @@ module J2ME {
20302030
// this.pc = this.local[this.read16()];
20312031
// break;
20322032
default:
2033-
var opName = Bytecodes[op];
2033+
var opName = Bytecode.getBytecodesName(op);
20342034
throw new Error("Wide opcode " + opName + " [" + op + "] not supported.");
20352035
}
20362036
continue;
@@ -2123,7 +2123,7 @@ module J2ME {
21232123
if (interrupt) {
21242124
continue;
21252125
}
2126-
release || assert(isInvoke(code[opPC]), "Return must come from invoke op: " + mi.implKey + " PC: " + pc + Bytecodes[op]);
2126+
release || assert(isInvoke(code[opPC]), "Return must come from invoke op: " + mi.implKey + " PC: " + pc + Bytecode.getBytecodesName(op));
21272127
// Calculate the PC based on the size of the caller's invoke bytecode.
21282128
pc = opPC + (code[opPC] === Bytecodes.INVOKEINTERFACE ? 5 : 3);
21292129
// Push return value.
@@ -2186,8 +2186,8 @@ module J2ME {
21862186
calleeTargetMethodInfo = classInfo.iTable[calleeMethodInfo.mangledName];
21872187
break;
21882188
default:
2189-
release || traceWriter && traceWriter.writeLn("Not Implemented: " + Bytecodes[op]);
2190-
assert(false, "Not Implemented: " + Bytecodes[op]);
2189+
release || traceWriter && traceWriter.writeLn("Not Implemented: " + Bytecode.getBytecodesName(op));
2190+
assert(false, "Not Implemented: " + Bytecode.getBytecodesName(op));
21912191
}
21922192

21932193
// Call Native or Compiled Method.
@@ -2240,7 +2240,7 @@ module J2ME {
22402240
args.unshift(i32[--sp]);
22412241
break;
22422242
default:
2243-
release || assert(false, "Invalid Kind: " + Kind[kind]);
2243+
release || assert(false, "Invalid Kind: " + getKindName(kind));
22442244
}
22452245
}
22462246

@@ -2265,7 +2265,7 @@ module J2ME {
22652265
}
22662266

22672267
if (U) {
2268-
traceWriter && traceWriter.writeLn("<< I Unwind: " + VMState[U]);
2268+
traceWriter && traceWriter.writeLn("<< I Unwind: " + getVMStateName(U));
22692269
release || assert(thread.unwoundNativeFrames.length, "Must have unwound frames.");
22702270
thread.nativeFrameCount--;
22712271
i32[frameTypeOffset] = FrameType.PushPendingFrames;
@@ -2298,7 +2298,7 @@ module J2ME {
22982298
case Kind.Void:
22992299
continue;
23002300
default:
2301-
release || assert(false, "Invalid Kind: " + Kind[kind]);
2301+
release || assert(false, "Invalid Kind: " + getKindName(kind));
23022302
}
23032303
continue;
23042304
}
@@ -2345,8 +2345,8 @@ module J2ME {
23452345
release || traceWriter && traceWriter.indent();
23462346
continue;
23472347
default:
2348-
release || traceWriter && traceWriter.writeLn("Not Implemented: " + Bytecodes[op] + ", PC: " + opPC + ", CODE: " + code.length);
2349-
release || assert(false, "Not Implemented: " + Bytecodes[op]);
2348+
release || traceWriter && traceWriter.writeLn("Not Implemented: " + Bytecode.getBytecodesName(op) + ", PC: " + opPC + ", CODE: " + code.length);
2349+
release || assert(false, "Not Implemented: " + Bytecode.getBytecodesName(op));
23502350
continue;
23512351
}
23522352
} catch (e) {

jit/analyze.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module J2ME {
99

1010
export var yieldGraph = null; // Object.create(null);
1111

12-
export enum YieldReason {
12+
export const enum YieldReason {
1313
None = 0,
1414
Root = 1,
1515
Synchronized = 2,
@@ -20,6 +20,10 @@ module J2ME {
2020
Likely = 7
2121
}
2222

23+
export function getYieldReasonName(yieldReason: YieldReason): string {
24+
return (<any>J2ME).YieldReason[yieldReason];
25+
}
26+
2327
/**
2428
* Root set of methods that can yield. Keep this up to date or else the compiler will not generate yield code
2529
* at the right spots.
@@ -234,16 +238,16 @@ module J2ME {
234238
}
235239
yieldWriter && yieldWriter.enter("> " + methodInfo.implKey);
236240
if (yieldMap[methodInfo.implKey] !== undefined) {
237-
yieldWriter && yieldWriter.leave("< " + methodInfo.implKey + " " + YieldReason[yieldMap[methodInfo.implKey]] + " cached.");
241+
yieldWriter && yieldWriter.leave("< " + methodInfo.implKey + " " + getYieldReasonName(yieldMap[methodInfo.implKey]) + " cached.");
238242
return yieldMap[methodInfo.implKey];
239243
}
240244
if (methodInfo.isSynchronized) {
241245
yieldCounter && yieldCounter.count("Method: " + methodInfo.implKey + " yields because it is synchronized.");
242-
yieldWriter && yieldWriter.leave("< " + methodInfo.implKey + " " + YieldReason[YieldReason.Synchronized]);
246+
yieldWriter && yieldWriter.leave("< " + methodInfo.implKey + " " + getYieldReasonName(YieldReason.Synchronized));
243247
return yieldMap[methodInfo.implKey] = YieldReason.Synchronized;
244248
}
245249
if (checkingForCanYield[methodInfo.implKey]) {
246-
yieldWriter && yieldWriter.leave("< " + methodInfo.implKey + " " + YieldReason[YieldReason.Cycle]);
250+
yieldWriter && yieldWriter.leave("< " + methodInfo.implKey + " " + getYieldReasonName(YieldReason.Cycle));
247251
return YieldReason.Cycle;
248252
}
249253
if (!methodInfo.codeAttribute) {
@@ -344,7 +348,7 @@ module J2ME {
344348
// stderrWriter.writeLns(e.stack);
345349
}
346350
checkingForCanYield[methodInfo.implKey] = false;
347-
yieldWriter && yieldWriter.leave("< " + methodInfo.implKey + " " + YieldReason[result]);
351+
yieldWriter && yieldWriter.leave("< " + methodInfo.implKey + " " + getYieldReasonName(result));
348352
return yieldMap[methodInfo.implKey] = result;
349353
}
350354
}

0 commit comments

Comments
 (0)