Fixed Enums

This commit is contained in:
NeeEoo
2024-04-24 03:57:07 +02:00
parent 006b0e1f32
commit b13d449b78
2 changed files with 22 additions and 7 deletions
+8 -7
View File
@@ -594,12 +594,13 @@ class Interp {
UnsafeReflect.setField(enumThingy, c, en.createByName(c));
} catch(e) {
try {
UnsafeReflect.setField(enumThingy, c, UnsafeReflect.field(en, c));
UnsafeReflect.setField(enumThingy, c, Reflect.makeVarArgs((args:Array<Dynamic>) -> en.createByName(c, args)));
} catch(ex) {
throw e;
}
}
}
//var enumThingy = en;
variables.set(toSetName, enumThingy);
} else {
variables.set(toSetName, cl);
@@ -624,7 +625,7 @@ class Interp {
locals.set(n, {r: (e == null) ? null : expr(e), depth: depth});
if (depth == 0) {
if(isStatic == true) {
if(!staticVariables.exists(n)) {
if(!staticVariables.exists(n)) { // dont overwrite existing static variables
staticVariables.set(n, locals[n].r);
}
return null;
@@ -674,8 +675,8 @@ class Interp {
}
case ECall(e, params):
var args = new Array();
for (p in params)
args.push(expr(p));
for(i in 0...params.length)
args.push(expr(params[i]));
switch (Tools.expr(e)) {
case EField(e, f, s):
@@ -857,7 +858,7 @@ class Interp {
// a.push(expr(e));
//}
//return a;
return [for (e in arr) expr(e)];
return [for (j in 0...arr.length) expr(arr[j])];
}
case EArray(e, index):
var arr:Dynamic = expr(e);
@@ -869,8 +870,8 @@ class Interp {
}
case ENew(cl, params):
var a = new Array();
for (e in params)
a.push(expr(e));
for (i in 0...params.length)
a.push(expr(params[i]));
return cnew(cl, a);
case EThrow(e):
throw expr(e);
+14
View File
@@ -44,6 +44,13 @@ class FinalCase extends TestCase {
');
Util.parse('sprite.setPosition(codesList.x + (sprite.ID % 2 == 1 ? 240 : 67),codesList.y + (15 * sprite.ID) + (sprite.ID%2 == 1 ? 35 : 54));');
headerCode = "import tests.FinalCase.TestEnum;";
assertEq("TestEnum.A", TestEnum.A);
assertEq("TestEnum.B", TestEnum.B);
assertEq("TestEnum.C(1, 2)", TestEnum.C(1, 2));
assertEq("TestEnum.D(1, 2, 3)", TestEnum.D(1, 2, 3));
}
function assertDisplay(script:String, expected:Dynamic) {
@@ -55,4 +62,11 @@ class FinalCase extends TestCase {
override function teardown() {
super.teardown();
}
}
enum TestEnum {
A;
B;
C(a:Int, b:Int);
D(a:Int, b:Int, c:Int);
}