From 796d07a7f8df0011d5a1c2f514e35b0ae57dca9c Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 13 Mar 2020 01:26:53 +0100 Subject: [PATCH] fix crash in asm code generated for bitshift operation with memory address operand --- .../prog8/compiler/target/c64/codegen/AssignmentAsmGen.kt | 4 ++-- .../compiler/target/c64/codegen/BuiltinFunctionsAsmGen.kt | 8 ++++---- docs/source/todo.rst | 3 ++- examples/arithmetic/bitshift.p8 | 2 +- examples/test.p8 | 8 +++++++- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/compiler/src/prog8/compiler/target/c64/codegen/AssignmentAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/AssignmentAsmGen.kt index e0400f11d..b81d58d8e 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/AssignmentAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/AssignmentAsmGen.kt @@ -313,7 +313,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen sta (+) +1 sty (+) +2 lda $sourceName -+ sta ${65535.toHex()} ; modified ++ sta ${'$'}ffff ; modified """) } } @@ -469,7 +469,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen sta (+) +1 lda $ESTACK_HI_HEX,x sta (+) +2 -+ sty ${65535.toHex()} ; modified ++ sty ${'$'}ffff ; modified """) } } diff --git a/compiler/src/prog8/compiler/target/c64/codegen/BuiltinFunctionsAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/BuiltinFunctionsAsmGen.kt index c376c9595..c648de2c6 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/BuiltinFunctionsAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/BuiltinFunctionsAsmGen.kt @@ -149,7 +149,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val sta (+) + 1 lda $ESTACK_HI_HEX,x sta (+) + 2 -+ asl 0 ; modified ++ asl ${'$'}ffff ; modified """) } } @@ -205,7 +205,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val sta (+) + 1 lda $ESTACK_HI_HEX,x sta (+) + 2 -+ lsr 0 ; modified ++ lsr ${'$'}ffff ; modified """) } } @@ -286,7 +286,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val sta (+) + 1 lda $ESTACK_HI_HEX,x sta (+) + 2 -+ rol 0 ; modified ++ rol ${'$'}ffff ; modified """) } } @@ -397,7 +397,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val sta (+) + 1 lda $ESTACK_HI_HEX,x sta (+) + 2 -+ ror 0 ; modified ++ ror ${'$'}ffff ; modified """) } } is RegisterExpr -> { diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 98a3462fa..dcb9c98f0 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -4,7 +4,8 @@ TODO - option to load library files from a directory instead of the embedded ones - exit('message', returncode) function to immediately exit the program with this message (restores stack) -- vector inc/dec/add/sub/lsl/asl/mul/div...? +- vector inc/dec/add/sub/mul/div...? + arrayvar++ / arrayvar-- / arrayvar += 2 / arrayvar -= 2 / arrayvar *= 3 / arrayvar /= 3 Memory Block Operations integrated in language? diff --git a/examples/arithmetic/bitshift.p8 b/examples/arithmetic/bitshift.p8 index a253a5328..7ea78ed49 100644 --- a/examples/arithmetic/bitshift.p8 +++ b/examples/arithmetic/bitshift.p8 @@ -74,7 +74,7 @@ main { ror2(@(9999)) rol2(@(9999)) - lsl(@(9999+A)) ; TODO optimizer generates invalid code here -> crash + lsl(@(9999+A)) lsr(@(9999+A)) ror(@(9999+A)) rol(@(9999+A)) diff --git a/examples/test.p8 b/examples/test.p8 index 5d9b9ecbd..c681fe433 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -5,7 +5,13 @@ main { sub start() { - byte[] barr = [22,-33,-44,55,66] + lsr(@(9999+A)) + ror(@(9999+A)) + rol(@(9999+A)) + ror2(@(9999+A)) + rol2(@(9999+A)) + + c64scr.print_ub(X) } }