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

Commit fe915af

Browse files
committed
Use const enums everywhere.
1 parent 83fcc77 commit fe915af

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 = " ";
@@ -732,7 +732,7 @@ module J2ME {
732732
return;
733733
}
734734
if (!(getKindCheck(methodInfo.returnKind)(l, h))) {
735-
assert(false, "Expected " + Kind[methodInfo.returnKind] + " return value, got low: " + l + " high: " + h + " in " + methodInfo.implKey);
735+
assert(false, "Expected " + getKindName(methodInfo.returnKind) + " return value, got low: " + l + " high: " + h + " in " + methodInfo.implKey);
736736
}
737737
}
738738

@@ -813,7 +813,7 @@ module J2ME {
813813
if (traceStackWriter) {
814814
frame.set(thread, fp, sp, opPC); frame.trace(traceStackWriter);
815815
traceStackWriter.writeLn();
816-
traceStackWriter.greenLn(mi.implKey + ": PC: " + opPC + ", FP: " + fp + ", " + Bytecodes[op]);
816+
traceStackWriter.greenLn(mi.implKey + ": PC: " + opPC + ", FP: " + fp + ", " + Bytecode.getBytecodesName(op));
817817
}
818818
}
819819

@@ -868,7 +868,7 @@ module J2ME {
868868
} else if (tag === TAGS.CONSTANT_String) {
869869
i32[sp++] = ci.constantPool.resolve(index, tag, false);
870870
} else {
871-
release || assert(false, TAGS[tag]);
871+
release || assert(false, getTAGSName(tag));
872872
}
873873
continue;
874874
case Bytecodes.LDC2_W:
@@ -881,7 +881,7 @@ module J2ME {
881881
i32[sp ] = buffer[offset++] << 24 | buffer[offset++] << 16 | buffer[offset++] << 8 | buffer[offset++];
882882
sp += 2;
883883
} else {
884-
release || assert(false, TAGS[tag]);
884+
release || assert(false, getTAGSName(tag));
885885
}
886886
continue;
887887
case Bytecodes.ILOAD:
@@ -1612,7 +1612,7 @@ module J2ME {
16121612
}
16131613

16141614
if (U) {
1615-
traceWriter && traceWriter.writeLn("<< I Unwind: " + VMState[U]);
1615+
traceWriter && traceWriter.writeLn("<< I Unwind: " + getVMStateName(U));
16161616
release || assert(thread.unwoundNativeFrames.length, "Must have unwound frames.");
16171617
thread.nativeFrameCount--;
16181618
i32[frameTypeOffset] = FrameType.PushPendingFrames;
@@ -1643,7 +1643,7 @@ module J2ME {
16431643
case Kind.Void:
16441644
return;
16451645
default:
1646-
release || assert(false, "Invalid Kind: " + Kind[kind]);
1646+
release || assert(false, "Invalid Kind: " + getKindName(kind));
16471647
}
16481648
}
16491649

@@ -1676,7 +1676,7 @@ module J2ME {
16761676
case Kind.Void:
16771677
continue;
16781678
default:
1679-
release || assert(false, "Invalid Kind: " + Kind[kind]);
1679+
release || assert(false, "Invalid Kind: " + getKindName(kind));
16801680
}
16811681
}
16821682
}
@@ -2036,7 +2036,7 @@ module J2ME {
20362036
// this.pc = this.local[this.read16()];
20372037
// break;
20382038
default:
2039-
var opName = Bytecodes[op];
2039+
var opName = Bytecode.getBytecodesName(op);
20402040
throw new Error("Wide opcode " + opName + " [" + op + "] not supported.");
20412041
}
20422042
continue;
@@ -2129,7 +2129,7 @@ module J2ME {
21292129
if (interrupt) {
21302130
continue;
21312131
}
2132-
release || assert(isInvoke(code[opPC]), "Return must come from invoke op: " + mi.implKey + " PC: " + pc + Bytecodes[op]);
2132+
release || assert(isInvoke(code[opPC]), "Return must come from invoke op: " + mi.implKey + " PC: " + pc + Bytecode.getBytecodesName(op));
21332133
// Calculate the PC based on the size of the caller's invoke bytecode.
21342134
pc = opPC + (code[opPC] === Bytecodes.INVOKEINTERFACE ? 5 : 3);
21352135
// Push return value.
@@ -2192,8 +2192,8 @@ module J2ME {
21922192
calleeTargetMethodInfo = classInfo.iTable[calleeMethodInfo.mangledName];
21932193
break;
21942194
default:
2195-
release || traceWriter && traceWriter.writeLn("Not Implemented: " + Bytecodes[op]);
2196-
assert(false, "Not Implemented: " + Bytecodes[op]);
2195+
release || traceWriter && traceWriter.writeLn("Not Implemented: " + Bytecode.getBytecodesName(op));
2196+
assert(false, "Not Implemented: " + Bytecode.getBytecodesName(op));
21972197
}
21982198

21992199
// Call Native or Compiled Method.
@@ -2246,7 +2246,7 @@ module J2ME {
22462246
args.unshift(i32[--sp]);
22472247
break;
22482248
default:
2249-
release || assert(false, "Invalid Kind: " + Kind[kind]);
2249+
release || assert(false, "Invalid Kind: " + getKindName(kind));
22502250
}
22512251
}
22522252

@@ -2271,7 +2271,7 @@ module J2ME {
22712271
}
22722272

22732273
if (U) {
2274-
traceWriter && traceWriter.writeLn("<< I Unwind: " + VMState[U]);
2274+
traceWriter && traceWriter.writeLn("<< I Unwind: " + getVMStateName(U));
22752275
release || assert(thread.unwoundNativeFrames.length, "Must have unwound frames.");
22762276
thread.nativeFrameCount--;
22772277
i32[frameTypeOffset] = FrameType.PushPendingFrames;
@@ -2304,7 +2304,7 @@ module J2ME {
23042304
case Kind.Void:
23052305
continue;
23062306
default:
2307-
release || assert(false, "Invalid Kind: " + Kind[kind]);
2307+
release || assert(false, "Invalid Kind: " + getKindName(kind));
23082308
}
23092309
continue;
23102310
}
@@ -2351,8 +2351,8 @@ module J2ME {
23512351
release || traceWriter && traceWriter.indent();
23522352
continue;
23532353
default:
2354-
release || traceWriter && traceWriter.writeLn("Not Implemented: " + Bytecodes[op] + ", PC: " + opPC + ", CODE: " + code.length);
2355-
release || assert(false, "Not Implemented: " + Bytecodes[op]);
2354+
release || traceWriter && traceWriter.writeLn("Not Implemented: " + Bytecode.getBytecodesName(op) + ", PC: " + opPC + ", CODE: " + code.length);
2355+
release || assert(false, "Not Implemented: " + Bytecode.getBytecodesName(op));
23562356
continue;
23572357
}
23582358
} 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)