diff --git a/compiler/src/prog8/compiler/BeforeAsmGenerationAstChanger.kt b/compiler/src/prog8/compiler/BeforeAsmGenerationAstChanger.kt index 1f33e5fea..7007462a9 100644 --- a/compiler/src/prog8/compiler/BeforeAsmGenerationAstChanger.kt +++ b/compiler/src/prog8/compiler/BeforeAsmGenerationAstChanger.kt @@ -249,8 +249,8 @@ internal class BeforeAsmGenerationAstChanger(val program: Program, private val o var rightAssignment: Assignment? = null var rightOperandReplacement: Expression? = null - val separateLeftExpr = !expr.left.isSimple && expr.left !is IFunctionCall - val separateRightExpr = !expr.right.isSimple && expr.right !is IFunctionCall + val separateLeftExpr = !expr.left.isSimple && expr.left !is IFunctionCall && expr.left !is ContainmentCheck + val separateRightExpr = !expr.right.isSimple && expr.right !is IFunctionCall && expr.right !is ContainmentCheck val leftDt = expr.left.inferType(program) val rightDt = expr.right.inferType(program) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 8ffbca86a..a735c6c0d 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -18,6 +18,7 @@ Future - fix the asm-labels problem (github issue #62) - make (an option) to let 64tass produce a listing file as well as output. - simplifyConditionalExpression() should not split expression if it still results in stack-based evaluation +- simplifyConditionalExpression() sometimes introduces needless assignment to r9 tempvar - get rid of all TODO's in the code - improve testability further, add more tests - use more of Result<> and Either<> to handle errors/ nulls better @@ -39,7 +40,8 @@ Future More code optimization ideas ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- automatically convert if statements that test for multiple values (if X==1 or X==2..) to if X in [1,2,..] statements +- automatically convert if statements that test for multiple values (if X==1 or X==2..) to if X in [1,2,..] statements, instead of just a warning +- - byte typed expressions should be evaluated in the accumulator where possible, without (temp)var for instance value = otherbyte >> 1 --> lda otherbite ; lsr a; sta value - rewrite expression tree evaluation such that it doesn't use an eval stack but flatten the tree into linear code that uses a fixed number of predetermined value 'variables' diff --git a/examples/test.p8 b/examples/test.p8 index e77c46cce..13f789996 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,127 +1,8 @@ %import textio %zeropage basicsafe - main { sub start() { - ubyte @shared xx - str name = "irmen" - ubyte[] values = [1,2,3,4,5] - - if 1 in values { - txt.print("1 ok\n") - } else { - txt.print("1 err\n") - } - if 5 in values { - txt.print("7 ok\n") - } else { - txt.print("7 err\n") - } - if not(8 in values) { - txt.print("8 ok\n") - } else { - txt.print("8 err\n") - } - - xx = 1 - if xx in values { - txt.print("xx1 ok\n") - } else { - txt.print("xx1 err\n") - } - if xx in [1,3,5] { - txt.print("xx1b ok\n") - } else { - txt.print("xx1b err\n") - } - xx=5 - if xx in values { - txt.print("xx7 ok\n") - } else { - txt.print("xx7 err\n") - } - if xx in [1,3,5] { - txt.print("xx7b ok\n") - } else { - txt.print("xx7b err\n") - } - xx=8 - if not(xx in values) { - txt.print("xx8 ok\n") - } else { - txt.print("xx8 err\n") - } - if not(xx in [1,3,5]) { - txt.print("xx8b ok\n") - } else { - txt.print("xx8b err\n") - } - - if xx==9 or xx==10 or xx==11 or xx==12 or xx==13 { - txt.print("9 10 11\n") - } - - txt.print("\nthe end\n") + txt.nl() } - - sub foobar() { - txt.print("foobar\n") - } - } -; -; -;main { -; ubyte @shared foo=99 -; sub thing(uword rr) { -; ubyte @shared xx = rr[1] ; should still work as var initializer that will be rewritten -; ubyte @shared yy -; yy = rr[2] -; uword @shared other -; ubyte @shared zz = other[3] -; } -; sub start() { -; -; txt.print("should print: 10 40 80 20\n") -; -; ubyte @shared xx -; -; if xx >0 -; goto $c000 -; else -; xx++ -;labeltje: -; -; repeat { -; xx++ -; if xx==10 -; break -; } -; txt.print_ub(xx) -; txt.nl() -; -; while xx<50 { -; xx++ -; if xx==40 -; break -; } -; txt.print_ub(xx) -; txt.nl() -; -; do { -; xx++ -; if xx==80 -; break -; } until xx>100 -; txt.print_ub(xx) -; txt.nl() -; -; for xx in 0 to 25 { -; if xx==20 -; break -; } -; txt.print_ub(xx) -; txt.nl() -; } -;}