From fa4c83df6bb0148148061781a06ee61569b471c4 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 18 Nov 2021 23:55:20 +0100 Subject: [PATCH] added 3 tests for discovered problems --- compiler/test/TestOptimization.kt | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/compiler/test/TestOptimization.kt b/compiler/test/TestOptimization.kt index d0d7ffcde..6b04c52ae 100644 --- a/compiler/test/TestOptimization.kt +++ b/compiler/test/TestOptimization.kt @@ -368,4 +368,65 @@ class TestOptimization: FunSpec({ (z3plus.value as BinaryExpression).operator shouldBe "-" (z3plus.value as BinaryExpression).right shouldBe NumericLiteralValue(DataType.UBYTE, 5.0, Position.DUMMY) } + + test("force_output option should work with optimizing memwrite assignment") { + val src=""" + main { + %option force_output + + sub start() { + uword aa + ubyte zz + @(aa) = zz + 32 + } + } + """ + + // TODO fix this problem! + + val result = compileText(C64Target, optimize=true, src, writeAssembly=false).assertSuccess() + printAst(result.program) + val stmts = result.program.entrypoint.statements + stmts.size shouldBe 5 + } + + test("don't optimize memory writes away") { + val src=""" + main { + sub start() { + uword aa + ubyte zz + @(aa) = zz + 32 ; do not optimize this away! + } + } + """ + + // TODO fix this problem! + + val result = compileText(C64Target, optimize=true, src, writeAssembly=false).assertSuccess() + printAst(result.program) + val stmts = result.program.entrypoint.statements + stmts.size shouldBe 5 + } + + test("correctly process constant prefix numbers") { + val src=""" + main { + sub start() { + byte z1 = 1 + byte z2 = +1 + byte z3 = ~1 + byte z4 = not 1 + byte z5 = - 1 + } + } + """ + + // TODO fix this problem! + + val result = compileText(C64Target, optimize=true, src, writeAssembly=false).assertSuccess() + printAst(result.program) + val stmts = result.program.entrypoint.statements + stmts.size shouldBe 2 + } })