identified wrong expr eval code - still need solution. Crash for now.

This commit is contained in:
Irmen de Jong
2024-01-30 23:00:40 +01:00
parent 9aea2b22c4
commit 48ef856c0b
3 changed files with 85 additions and 40 deletions

View File

@@ -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)

View File

@@ -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...

View File

@@ -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
}
}
; }
;}