fix crash in asmgen for boolean comparison with false, when not using optimizations

This commit is contained in:
Irmen de Jong 2025-03-01 23:57:55 +01:00
parent 5255f1c052
commit 125b66c929
3 changed files with 24 additions and 19 deletions

View File

@ -1845,8 +1845,7 @@ internal class AssignmentAsmGen(
"==" -> {
val dt = expr.left.type
when {
dt.isBool -> TODO("compare bool to 0 ${expr.position}")
dt.isByte -> {
dt.isBool || dt.isByte -> {
assignExpressionToRegister(expr.left, RegisterOrPair.A, dt.isSigned)
asmgen.out("""
cmp #0
@ -1881,8 +1880,7 @@ internal class AssignmentAsmGen(
"!=" -> {
val dt = expr.left.type
when {
dt.isBool -> TODO("compare bool to 0 ${expr.position}")
dt.isByte -> {
dt.isBool || dt.isByte -> {
assignExpressionToRegister(expr.left, RegisterOrPair.A, dt.isSigned)
asmgen.out(" beq + | lda #1")
asmgen.out("+")

View File

@ -1159,4 +1159,20 @@ main {
compileText(VMTarget(), true, src, writeAssembly = true) shouldNotBe null
compileText(C64Target(), true, src, writeAssembly = true) shouldNotBe null
}
test("boolean comparisons without optimization can be assembled") {
val src="""
main {
sub start() {
bool @shared pre_start, xxx
if (pre_start != false and xxx) {
return
} else if (pre_start != false and xxx) {
return
}
}
}"""
compileText(C64Target(), false, src, writeAssembly = true) shouldNotBe null
}
})

View File

@ -4,21 +4,12 @@
main {
sub start() {
str name1 = "n1"
str name2 = ""
bool @shared pre_start, xxx
uword buf1 = memory("a", 2000, 0)
uword buf2 = memory("", 2000, 0)
uword buf3 = memory(name1, 2000, 0)
uword buf4 = memory(name2, 2000, 0)
txt.print_uwhex(buf1, true)
txt.spc()
txt.print_uwhex(buf2, true)
txt.spc()
txt.print_uwhex(buf3, true)
txt.spc()
txt.print_uwhex(buf4, true)
txt.spc()
if (pre_start != false and xxx) {
return
} else if (pre_start != false and xxx) {
return
}
}
}