mirror of
https://github.com/irmen/prog8.git
synced 2025-04-16 15:39:43 +00:00
fix crash in asmgen for boolean comparison with false, when not using optimizations
This commit is contained in:
parent
5255f1c052
commit
125b66c929
@ -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("+")
|
||||
|
@ -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
|
||||
}
|
||||
})
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user