fix compiler crash related to word types in certain comparison expressions

This commit is contained in:
Irmen de Jong 2022-07-06 00:49:57 +02:00
parent 298b25cf7d
commit 65daf29acd
3 changed files with 24 additions and 8 deletions

View File

@ -467,7 +467,7 @@ internal class AssignmentAsmGen(private val program: Program,
private fun attemptAssignToByteCompareZero(expr: BinaryExpression, assign: AsmAssignment): Boolean {
when (expr.operator) {
"==" -> {
when(val dt = assign.source.datatype) {
when(val dt = expr.left.inferType(program).getOrElse { throw AssemblyError("invalid dt") }) {
in ByteDatatypes -> {
assignExpressionToRegister(expr.left, RegisterOrPair.A, dt==DataType.BYTE)
asmgen.out("""
@ -504,7 +504,7 @@ internal class AssignmentAsmGen(private val program: Program,
}
}
"!=" -> {
when(val dt = assign.source.datatype) {
when(val dt = expr.left.inferType(program).getOrElse { throw AssemblyError("invalid dt") }) {
in ByteDatatypes -> {
assignExpressionToRegister(expr.left, RegisterOrPair.A, dt==DataType.BYTE)
asmgen.out(" beq + | lda #1")

View File

@ -16,6 +16,27 @@ import prog8tests.helpers.compileText
class TestTypecasts: FunSpec({
test("correct evaluation of words in boolean expressions") {
val text="""
main {
sub start() {
uword camg
ubyte @shared interlaced
interlaced = (camg & ${'$'}0004) != 0
interlaced++
interlaced = (${'$'}0004 & camg) != 0
interlaced++
uword @shared ww
ww = (camg & ${'$'}0004)
ww++
ww = (${'$'}0004 & camg)
}
}"""
val result = compileText(C64Target(), false, text, writeAssembly = false)!!
val stmts = result.program.entrypoint.statements
stmts.size shouldBe 11
}
test("word to byte casts") {
val text="""
%import textio
@ -33,7 +54,6 @@ class TestTypecasts: FunSpec({
val result = compileText(C64Target(), false, text, writeAssembly = false)!!
val stmts = result.program.entrypoint.statements
stmts.size shouldBe 3
}
test("add missing & to function arguments") {

View File

@ -3,11 +3,7 @@ TODO
For next release
^^^^^^^^^^^^^^^^
- fix imageviewer compilation crash
- petaxian is larger again after introduction of BOOL type (against main branch). WHY??? FIX.
caused by replacing cast-to-bool by !=0 expression perhaps rather than optimized asm for boolean() func?
boolcheck.p8 illustrates problem: stack eval
...
Need help with