diff --git a/compiler/compiler.iml b/compiler/compiler.iml index bf8bf45c1..e395947e5 100644 --- a/compiler/compiler.iml +++ b/compiler/compiler.iml @@ -8,7 +8,7 @@ - + diff --git a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt index 0dc5a18c9..eb59eba48 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt @@ -938,7 +938,6 @@ internal class AsmGen(private val program: Program, when { iterations == 0 -> {} iterations <= 256 -> { - // TODO faulty loop code when 256 because of the beq that's also generated (should be ok if that is removed?) out(" lda #${iterations and 255}") repeatByteCountInA(iterations, repeatLabel, endLabel, stmt.body) } @@ -984,15 +983,12 @@ internal class AsmGen(private val program: Program, } private fun repeatWordCountInAY(constIterations: Int?, repeatLabel: String, endLabel: String, body: AnonymousScope) { + if(constIterations==0) + return // note: A/Y must have been loaded with the number of iterations already! val counterVar = makeLabel("repeatcounter") - // TODO the 0.w check at the start is invalid(wrong register check order), and must not be done at all if the loop count is numeric literal >0 out(""" - bne + - cpy #0 - bne + - beq $endLabel -+ sta $counterVar + sta $counterVar sty $counterVar+1 $repeatLabel lda $counterVar bne + @@ -1018,11 +1014,13 @@ $counterVar .word 0""") } private fun repeatByteCountInA(constIterations: Int?, repeatLabel: String, endLabel: String, body: AnonymousScope) { + if(constIterations==0) + return // note: A must have been loaded with the number of iterations already! val counterVar = makeLabel("repeatcounter") - // TODO the beq endlabel check can be omitted if the number of iterations is a numeric literal >0 + if(constIterations==null) + out(" beq $endLabel") out(""" - beq $endLabel sta $counterVar $repeatLabel""") translate(body) diff --git a/examples/test.p8 b/examples/test.p8 index b26920b88..6d125576c 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -7,81 +7,6 @@ main { sub start() { - ubyte xx = 0 - repeat 254 { - txt.chrout('1') - xx++ - } - txt.print_ub(xx) - txt.chrout('\n') - - xx=0 - - repeat 255 { - txt.chrout('2') - xx++ - } - txt.print_ub(xx) - txt.chrout('\n') - - xx=0 - repeat 256 { ; TODO generates faulty code, loop is never executed at all - txt.chrout('3') - xx++ - } - txt.print_ub(xx) - txt.chrout('\n') - - xx=0 - repeat 257 { ; TODO generates invalid 0-check code at start - txt.chrout('4') - xx++ - } - txt.print_ub(xx) - txt.chrout('\n') - - ubyte bb - - repeat bb { - xx++ - } - - uword ww - - repeat ww { - xx++ - } - } - - sub rec2() { - rec3() - } - - sub rec3() { - rec4() - } - - sub rec4() { - rec2() - } - - sub derp() { - repeat { - derp() - } - if true { - derp() - } else { - derp() - } - - do { - derp() - } until true - - while true { - derp() - } } asmsub testX() {