diff --git a/compiler/test/ast/TestVariousCompilerAst.kt b/compiler/test/ast/TestVariousCompilerAst.kt index aa20f15f2..9af80d3d4 100644 --- a/compiler/test/ast/TestVariousCompilerAst.kt +++ b/compiler/test/ast/TestVariousCompilerAst.kt @@ -7,10 +7,7 @@ import io.kotest.matchers.string.shouldContain import io.kotest.matchers.types.instanceOf import prog8.ast.IFunctionCall import prog8.ast.expressions.* -import prog8.ast.statements.Assignment -import prog8.ast.statements.ForLoop -import prog8.ast.statements.InlineAssembly -import prog8.ast.statements.VarDecl +import prog8.ast.statements.* import prog8.code.core.DataType import prog8.code.core.Position import prog8.code.target.C64Target @@ -457,42 +454,38 @@ main { compileText(VMTarget(), optimize=false, src, writeAssembly=false) shouldNotBe null } - test("chained comparison") { + test("no chained comparison modifying expression semantics") { val src=""" main { sub start() { - ubyte @shared x = 1 - ubyte @shared y = 2 - ubyte @shared z = 3 - x = x==y==z - y = 4" - right2.operator shouldBe "<" - (left2.left as? IdentifierReference)?.nameInSource shouldBe listOf("x") - (left2.right as? NumericLiteral)?.number shouldBe 4.0 - (right2.left as? IdentifierReference)?.nameInSource shouldBe listOf("x") - (right2.right as? NumericLiteral)?.number shouldBe 10.0 + val ifCond = (st[4] as IfElse).condition as BinaryExpression + ifCond.operator shouldBe "==" + (ifCond.right as NumericLiteral).number shouldBe 0.0 + (ifCond.left as BinaryExpression).operator shouldBe "<" + val assign1 = (st[5] as Assignment).value as BinaryExpression + val assign2 = (st[6] as Assignment).value as BinaryExpression + assign1.operator shouldBe "==" + (assign1.right as NumericLiteral).number shouldBe 0.0 + (assign1.left as BinaryExpression).operator shouldBe "<" + assign2.operator shouldBe "==" + (assign2.right as NumericLiteral).number shouldBe 0.0 + (assign2.left as BinaryExpression).operator shouldBe "<" } test("modulo is not directive") { diff --git a/examples/test.p8 b/examples/test.p8 index dfce0ad43..da34daf28 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -3,12 +3,15 @@ main { sub start() { - ubyte[10] array1 - ubyte[10] array2 - ubyte @shared xx + ubyte @shared n=20 + ubyte @shared x=10 - cx16.r0 = (cx16.r1+cx16.r2) / (cx16.r2+cx16.r1) - cx16.r1 = 4*(cx16.r1+cx16.r2) + 3*(cx16.r1+cx16.r2) - cx16.r2 = array1[xx+20]==10 or array2[xx+20]==20 or array1[xx+20]==30 or array2[xx+20]==40 + if n < x { + ; nothing here, conditional gets inverted + } else { + cx16.r0++ + } + cx16.r0L = n