From c50ecf6055cba3fa88d6fef50c1261e8502d1473 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 29 Aug 2020 02:05:24 +0200 Subject: [PATCH] fix for loop asm creation with word loopvar --- compiler/res/prog8lib/cx16lib.p8 | 2 -- compiler/res/prog8lib/cx16textio.p8 | 1 - .../src/prog8/ast/expressions/AstExpressions.kt | 9 ++++++++- .../target/c64/codegen/ForLoopsAsmGen.kt | 16 ++++++++-------- examples/test.p8 | 9 +++++++-- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/compiler/res/prog8lib/cx16lib.p8 b/compiler/res/prog8lib/cx16lib.p8 index a5c8eccae..7b84e685d 100644 --- a/compiler/res/prog8lib/cx16lib.p8 +++ b/compiler/res/prog8lib/cx16lib.p8 @@ -80,8 +80,6 @@ cx16 { &uword r15 = $20 -; TODO subroutine args + soubroutine returnvalues + clobber registers - ; supported C128 additions romsub $ff4a = close_all() romsub $ff59 = lkupla() diff --git a/compiler/res/prog8lib/cx16textio.p8 b/compiler/res/prog8lib/cx16textio.p8 index a8966debc..b2628275c 100644 --- a/compiler/res/prog8lib/cx16textio.p8 +++ b/compiler/res/prog8lib/cx16textio.p8 @@ -13,7 +13,6 @@ txt { asmsub clear_screen (ubyte char @ A, ubyte color @ Y) clobbers(A) { ; ---- clear the character screen with the given fill character and character color. - ; (assumes screen and color matrix are at their default addresses) %asm {{ brk ; TODO diff --git a/compiler/src/prog8/ast/expressions/AstExpressions.kt b/compiler/src/prog8/ast/expressions/AstExpressions.kt index 4803b9321..eff001438 100644 --- a/compiler/src/prog8/ast/expressions/AstExpressions.kt +++ b/compiler/src/prog8/ast/expressions/AstExpressions.kt @@ -642,7 +642,14 @@ class RangeExpr(var from: Expression, fromDt istype DataType.STR && toDt istype DataType.STR -> InferredTypes.knownFor(DataType.STR) fromDt istype DataType.WORD || toDt istype DataType.WORD -> InferredTypes.knownFor(DataType.ARRAY_W) fromDt istype DataType.BYTE || toDt istype DataType.BYTE -> InferredTypes.knownFor(DataType.ARRAY_B) - else -> InferredTypes.knownFor(DataType.ARRAY_UB) + else -> { + val fdt = fromDt.typeOrElse(DataType.STRUCT) + val tdt = toDt.typeOrElse(DataType.STRUCT) + if(fdt largerThan tdt) + InferredTypes.knownFor(ElementArrayTypes.getValue(fdt)) + else + InferredTypes.knownFor(ElementArrayTypes.getValue(tdt)) + } } } override fun toString(): String { diff --git a/compiler/src/prog8/compiler/target/c64/codegen/ForLoopsAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/ForLoopsAsmGen.kt index 8edcc5586..817b3eda9 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/ForLoopsAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/ForLoopsAsmGen.kt @@ -46,7 +46,7 @@ internal class ForLoopsAsmGen(private val program: Program, private val asmgen: DataType.ARRAY_B, DataType.ARRAY_UB -> { if (stepsize==1 || stepsize==-1) { - // bytes, step 1 or -1 + // bytes array, step 1 or -1 val incdec = if(stepsize==1) "inc" else "dec" // loop over byte range via loopvar @@ -258,13 +258,6 @@ $endLabel inx""") asmgen.loopEndLabels.pop() } - private fun assignLoopvar(stmt: ForLoop, range: RangeExpr) { - val target = AsmAssignTarget(TargetStorageKind.VARIABLE, program, asmgen, stmt.loopVarDt(program).typeOrElse(DataType.STRUCT), variable=stmt.loopVar) - val src = AsmAssignSource.fromAstSource(range.from, program).adjustDataTypeToTarget(target) - val assign = AsmAssignment(src, target, false, range.position) - asmgen.translateNormalAssignment(assign) - } - private fun translateForOverIterableVar(stmt: ForLoop, iterableDt: DataType, ident: IdentifierReference) { val loopLabel = asmgen.makeLabel("for_loop") val endLabel = asmgen.makeLabel("for_end") @@ -615,4 +608,11 @@ $loopLabel""") $endLabel""") asmgen.loopEndLabels.pop() } + + private fun assignLoopvar(stmt: ForLoop, range: RangeExpr) { + val target = AsmAssignTarget(TargetStorageKind.VARIABLE, program, asmgen, stmt.loopVarDt(program).typeOrElse(DataType.STRUCT), variable=stmt.loopVar) + val src = AsmAssignSource.fromAstSource(range.from, program).adjustDataTypeToTarget(target) + val assign = AsmAssignment(src, target, false, range.position) + asmgen.translateNormalAssignment(assign) + } } diff --git a/examples/test.p8 b/examples/test.p8 index ff4f38e85..eba707ad2 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -4,10 +4,15 @@ main { sub start() { - ubyte xx + uword xx ubyte yy + for xx in 319 downto 0 { + ; TODO also fix that the asm is invalid for word iterator variable. + } + + for yy in 199 downto 0 { - for xx in 255 downto 0 { + for xx in 319 downto 0 { ; TODO also fix that the asm is invalid for word iterator variable. } }