From 55dbd095edecfacb96c11cc36acc404bb009d544 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 2 Dec 2024 00:32:28 +0100 Subject: [PATCH] fix IR codegen missing a CMPI after if not condition fix IR codegen for containmentcheck --- .../prog8/codegen/intermediate/ExpressionGen.kt | 3 +-- .../src/prog8/codegen/intermediate/IRCodeGen.kt | 3 ++- compiler/res/prog8lib/c128/syslib.p8 | 1 + docs/source/todo.rst | 8 +++++++- examples/test.p8 | 15 ++++++--------- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/codeGenIntermediate/src/prog8/codegen/intermediate/ExpressionGen.kt b/codeGenIntermediate/src/prog8/codegen/intermediate/ExpressionGen.kt index 11c4a84ae..a6d9ff4c1 100644 --- a/codeGenIntermediate/src/prog8/codegen/intermediate/ExpressionGen.kt +++ b/codeGenIntermediate/src/prog8/codegen/intermediate/ExpressionGen.kt @@ -229,8 +229,7 @@ internal class ExpressionGen(private val codeGen: IRCodeGen) { } addInstr(result, IRInstruction(Opcode.LOAD, IRDataType.BYTE, elementTr.resultReg, immediate = 1), gottemLabel) result += IRCodeChunk(endLabel, null) - return ExpressionCodeResult(result, IRDataType.BYTE, -1, -1) - + return ExpressionCodeResult(result, IRDataType.BYTE, elementTr.resultReg, -1) } DataType.FLOAT -> throw AssemblyError("containmentchecks for floats should always be done on an array variable with subroutine") else -> throw AssemblyError("weird dt $elementDt") diff --git a/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt b/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt index 9c196e85a..b3868fc1f 100644 --- a/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt +++ b/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt @@ -1556,6 +1556,7 @@ class IRCodeGen( } when(val cond=ifElse.condition) { + // TODO investigate; maybe do all conditions require a CMPI at the end? Some here still have false, but do they work correctly in all cases? is PtBool -> { // normally this will be optimized away, but not with -noopt translateSimple(cond, Opcode.BSTEQ, false) @@ -1572,7 +1573,7 @@ class IRCodeGen( } is PtPrefix -> { require(cond.operator=="not") - translateSimple(cond.value, Opcode.BSTNE, false) + translateSimple(cond.value, Opcode.BSTNE, true) } is PtBinaryExpression -> { translateBinExpr(cond) diff --git a/compiler/res/prog8lib/c128/syslib.p8 b/compiler/res/prog8lib/c128/syslib.p8 index a3deae4bc..fcc7f32df 100644 --- a/compiler/res/prog8lib/c128/syslib.p8 +++ b/compiler/res/prog8lib/c128/syslib.p8 @@ -320,6 +320,7 @@ c128 { ; TODO c128 a bunch of kernal routines are missing here that are specific to the c128 extsub $FF6E = JSRFAR() +extsub $FF68 = SETBNK(ubyte databank @A, ubyte filenamebank @X) ; ---- C128 specific system utility routines: ---- diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 0793d9ea1..2dc1cc035 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,7 +1,11 @@ TODO ==== -make a compiler switch to disable footgun warnings +Fix diskio (cx16, possibly other cbm targets too?) when opening write file , read file stops working + +make a compiler switch to disable footgun warnings -ignorefootguns + +update zsmkit to newest version that includes the on_deck routines ... @@ -9,6 +13,7 @@ make a compiler switch to disable footgun warnings Future Things and Ideas ^^^^^^^^^^^^^^^^^^^^^^^ +- a syntax to access specific bits in a variable, to avoid manually shifts&ands, something like variable[4:8] ? (or something else this may be too similar to regular array indexing) - something to reduce the need to use fully qualified names all the time. 'with' ? Or 'using '? - on the C64: make the floating point routines @banked so that basic can be permanently banked out even if you use floats? But this will crash when the call is done from program code at $a000+ - Libraries: improve ability to create library files in prog8; for instance there's still stuff injected into the start of the start() routine AND there is separate setup logic going on before calling it. @@ -45,6 +50,7 @@ Future Things and Ideas IR/VM ----- +- ExpressionCodeResult: get rid of the separation between single result register and multiple result registers? - constants are not retained in the IR file, they should. (need to be able to make asm labels from them eventually) - implement missing operators in AssignmentGen (array shifts etc) - support %align on code chunks diff --git a/examples/test.p8 b/examples/test.p8 index f0a93d55e..f3a1d371e 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -4,14 +4,11 @@ main { sub start() { - txt.print_ubhex($123456>>16, true) - txt.spc() - txt.print_ubhex(msw($123456), true) - txt.nl() - - txt.print_uwhex($123456 & $ffff, true) - txt.spc() - txt.print_uwhex(lsw($123456), true) - txt.nl() + ubyte @shared index + bool @shared success = index==0 or index==255 + if success + txt.print("yo") + if index==0 or index==255 + txt.print("yo") } }