Skip to content

Commit 32c8a42

Browse files
authored
Replace Type.enumIndex with manual index.
Changing Expr can easily break `hscript.Bytes`, so it's better to assign index manually.
1 parent 5214b07 commit 32c8a42

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

hscript/Bytes.hx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Bytes {
122122
doEncodeInt(e.line);
123123
var e = e.e;
124124
#end
125-
bout.addByte(Type.enumIndex(e));
125+
bout.addByte(exprIndex(e));
126126
switch( e ) {
127127
case EConst(c):
128128
doEncodeConst(c);
@@ -238,6 +238,42 @@ class Bytes {
238238
}
239239
}
240240

241+
function exprIndex(e:Expr):Int {
242+
#if hscriptPos
243+
var e = e.e;
244+
#end
245+
return switch (e) {
246+
case EConst(_): 0;
247+
case EIdent(_): 1;
248+
case EVar(_): 2;
249+
case EParent(_): 3;
250+
case EBlock(_): 4;
251+
case EField(_): 5;
252+
case EBinop(_): 6;
253+
case EUnop(_): 7;
254+
case ECall(_): 8;
255+
case EIf(_): 9;
256+
case EWhile(_): 10;
257+
case EFor(_): 11;
258+
case EBreak: 12;
259+
case EContinue: 13;
260+
case EFunction(_): 14;
261+
case EReturn(_): 15;
262+
case EArray(_): 16;
263+
case EArrayDecl(_): 17;
264+
case ENew(_): 18;
265+
case EThrow(_): 19;
266+
case ETry(_): 20;
267+
case EObject(_): 21;
268+
case ETernary(_): 22;
269+
case ESwitch(_): 23;
270+
case EDoWhile(_): 24;
271+
case EMeta(_): 25;
272+
case ECheckType(_): 26;
273+
case EForGen(_): 27;
274+
}
275+
}
276+
241277
function doDecode() : Expr {
242278
#if hscriptPos
243279
if (bin.get(pin) == 255) {

0 commit comments

Comments
 (0)