diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt index 0867188f0..7f022ea82 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt @@ -191,12 +191,13 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, asmgen.out(" ldx P8ZP_SCRATCH_B1") } SourceStorageKind.EXPRESSION -> { - asmgen.out(" sta P8ZP_SCRATCH_B1") - if(value.expression is PtTypeCast) - inplacemodificationByteVariableWithValue("P8ZP_SCRATCH_B1", DataType.UBYTE, operator, value.expression) - else - inplacemodificationByteVariableWithValue("P8ZP_SCRATCH_B1", DataType.UBYTE, operator, value.expression!!) - asmgen.out(" ldx P8ZP_SCRATCH_B1") + TODO("safe evaluation of sub-expression at ${value.expression!!.position} - in the meantime, split up the expression in multiple statements") +// asmgen.out(" sta P8ZP_SCRATCH_B1") +// if(value.expression is PtTypeCast) +// inplacemodificationByteVariableWithValue("P8ZP_SCRATCH_B1", DataType.UBYTE, operator, value.expression) +// else +// inplacemodificationByteVariableWithValue("P8ZP_SCRATCH_B1", DataType.UBYTE, operator, value.expression!!) +// asmgen.out(" ldx P8ZP_SCRATCH_B1") } } asmgen.restoreRegisterStack(CpuRegister.Y, false) @@ -325,13 +326,14 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, } SourceStorageKind.EXPRESSION -> { - asmgen.out(" sta P8ZP_SCRATCH_B1") - if(value.expression is PtTypeCast) - inplacemodificationByteVariableWithValue("P8ZP_SCRATCH_B1", target.datatype, operator, value.expression) - else - inplacemodificationByteVariableWithValue("P8ZP_SCRATCH_B1", target.datatype, operator, value.expression!!) - asmgen.restoreRegisterStack(CpuRegister.Y, false) - asmgen.out(" lda P8ZP_SCRATCH_B1") + TODO("safe evaluation of sub-expression at ${value.expression!!.position} - in the meantime, split up the expression in multiple statements") +// asmgen.out(" sta P8ZP_SCRATCH_B1") +// if(value.expression is PtTypeCast) +// inplacemodificationByteVariableWithValue("P8ZP_SCRATCH_B1", target.datatype, operator, value.expression) +// else +// inplacemodificationByteVariableWithValue("P8ZP_SCRATCH_B1", target.datatype, operator, value.expression!!) +// asmgen.restoreRegisterStack(CpuRegister.Y, false) +// asmgen.out(" lda P8ZP_SCRATCH_B1") } } asmgen.out(" sta ${target.array.variable.name},y") @@ -399,12 +401,13 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, } SourceStorageKind.EXPRESSION -> { - asmgen.out(" sta P8ZP_SCRATCH_W1 | stx P8ZP_SCRATCH_W1+1") - if(value.expression is PtTypeCast) - inplacemodificationWordWithValue("P8ZP_SCRATCH_W1", target.datatype, operator, value.expression, block) - else - inplacemodificationWordWithValue("P8ZP_SCRATCH_W1", target.datatype, operator, value.expression!!, block) - asmgen.out(" lda P8ZP_SCRATCH_W1 | ldx P8ZP_SCRATCH_W1+1") + TODO("safe evaluation of sub-expression at ${value.expression!!.position} - in the meantime, split up the expression in multiple statements") +// asmgen.out(" sta P8ZP_SCRATCH_W1 | stx P8ZP_SCRATCH_W1+1") +// if(value.expression is PtTypeCast) +// inplacemodificationWordWithValue("P8ZP_SCRATCH_W1", target.datatype, operator, value.expression, block) +// else +// inplacemodificationWordWithValue("P8ZP_SCRATCH_W1", target.datatype, operator, value.expression!!, block) +// asmgen.out(" lda P8ZP_SCRATCH_W1 | ldx P8ZP_SCRATCH_W1+1") } } asmgen.restoreRegisterStack(CpuRegister.Y, true) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index e743852a8..a43446838 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,6 +1,9 @@ TODO ==== +fix "safe evaluation of sub-expression" (byte and word, in AugmentableAssignmentAsmGen). + + maze: if cell & UP!=0 and @(celladdr(cx,cy-1)) & (WALKED|BACKTRACKED) ==0 ^^ adding this !=0 caused a weird beq + / lda #1 / + to appear in front of the shortcircuit beq... diff --git a/examples/test.p8 b/examples/test.p8 index 91c34c530..0ff71bd27 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,10 +1,49 @@ %import textio -%import floats +%import test_stack %zeropage basicsafe %option no_sysinit main { + uword[3] a + uword[3] b + ubyte @shared j + uword @shared aa = 1 + sub start() { + test_stack.test() + j = 1 + a[j] = 1 + b[j] = 0 + b[j] += 5 * aa + b[j] += 5 * aa + b[j] += 5 * aa + b[j] += 5 * aa + txt.print_uw(b[j]) ; 20 + txt.nl() + b[j] += 5 * a[1] + b[j] += 5 * a[1] + b[j] += 5 * a[1] + b[j] += 5 * a[1] + txt.print_uw(b[j]) ; 40 + txt.nl() + b[j] += 5 * a[j] + b[j] += 5 * a[j] + b[j] += 5 * a[j] + b[j] += 5 * a[j] + txt.print_uw(b[j]) ; 60 + txt.nl() + test_stack.test() + } +} + + +;%import textio +;%import floats +;%zeropage basicsafe +;%option no_sysinit +; +;main { +; sub start() { ; uword @shared addr = 2000 ; @(2000) = 199 @@ -35,24 +74,24 @@ main { ; txt.nl() ; - ubyte @shared xx - ubyte[3] ubarr - uword[3] @split uwarr - byte[3] sbarr - bool[3] barr - float[3] flarr - bool @shared bb - uword ptr = &ubarr - - ptr[1]++ - ptr[1]++ - ptr[1]-- - txt.print_ub(ubarr[1]) - txt.nl() - ptr[1]+=4 - ptr[1]-=3 - txt.print_ub(ubarr[1]) - txt.nl() +; ubyte @shared xx +; ubyte[3] ubarr +; uword[3] @split uwarr +; byte[3] sbarr +; bool[3] barr +; float[3] flarr +; bool @shared bb +; uword ptr = &ubarr +; +; ptr[1]++ +; ptr[1]++ +; ptr[1]-- +; txt.print_ub(ubarr[1]) +; txt.nl() +; ptr[1]+=4 +; ptr[1]-=3 +; txt.print_ub(ubarr[1]) +; txt.nl() ; sbarr[1] = sbarr[1] == 0 ; sbarr[1] = sbarr[1] != 0 @@ -107,5 +146,5 @@ main { ; bb = bb or barr[1] ; bb = bb xor barr[1] ; bb = not bb - } -} +; } +;}