Fixed bug

This commit is contained in:
NeeEoo
2024-04-24 00:49:36 +02:00
parent 0ca6eab16e
commit 006b0e1f32
3 changed files with 39 additions and 5 deletions
+26 -5
View File
@@ -280,21 +280,22 @@ class Optimizer {
}
}
// Possible bugs here
if(isNumber(e1) && !isConstant(e2)) {
var c1 = getNumber(e1);
if(c1 == 0 && op == "+")
if(compareNumber(c1, 0) && op == "+")
return mk(Tools.expr(e2), s);
//if(c1 == 0 && op == "*")
//if(compareNumber(c1, 0) && op == "*")
// return mk(convertConstant(0), s);
}
if(!isConstant(e1) && isNumber(e2)) {
var c2 = getNumber(e2);
if(op == "+" && c2 == 0)
if(op == "+" && compareNumber(c2, 0))
return mk(Tools.expr(e1), s);
if(op == "/" && c2 == 1)
if(op == "/" && compareNumber(c2, 1))
return mk(Tools.expr(e1), s);
//if(op == "*" && c2 == 0)
//if(op == "*" && compareNumber(c2, 0))
// return mk(convertConstant(0), s);
}
@@ -321,6 +322,26 @@ class Optimizer {
return s;
}
static function compareNumber(a:Dynamic, b:Dynamic):Bool {
return switch(Type.typeof(a)) {
case TInt:
var a:Int = cast a;
switch(Type.typeof(b)) {
case TInt: a == cast(b, Int);
case TFloat: a == cast(b, Float);
default: false;
}
case TFloat:
var a:Float = cast a;
switch(Type.typeof(b)) {
case TInt: a == cast(b, Int);
case TFloat: a == cast(b, Float);
default: false;
}
default: false;
}
}
static function hasDecl(e:Expr):Bool {
return switch(Tools.expr(e)) {
case EVar(_): true;// has a declaration
+6
View File
@@ -38,6 +38,12 @@ class FinalCase extends TestCase {
Util.parse("openCodesList(false, codesOpened ? false : true, previousOpen != open ? true : false);");
Util.parse("openCodesList(false, 'HELLO' ? false : false, 'WORLD' ? true : true);");
Util.parse('FlxTween.tween(newSprite, {"scale.x": 1, "scale.y": 1, alpha: 1, angle: 0}, 0.3, {ease: FlxEase.qaudInOut});');
Util.parse('
bloomShader.dim = dim = .8 + (.3 * FlxMath.fastSin(__totalTime));
bloomShader.size = size = 18 + (8 * FlxMath.fastSin(__totalTime));
');
Util.parse('sprite.setPosition(codesList.x + (sprite.ID % 2 == 1 ? 240 : 67),codesList.y + (15 * sprite.ID) + (sprite.ID%2 == 1 ? 35 : 54));');
}
function assertDisplay(script:String, expected:Dynamic) {
+7
View File
@@ -149,6 +149,13 @@ class MiscCase extends TestCase {
assertEq("[55,66,77][1]",66);
assertEq("{
var a = 1;
function b() { return a; }
a = 2;
b();
}", 2);
}
override function teardown() {