mirror of
https://github.com/irmen/prog8.git
synced 2024-10-25 00:24:16 +00:00
fixed several bugs in the repeat assembly for loop sizes like 0 and 256
This commit is contained in:
parent
10145b946b
commit
bee6c65293
@ -8,7 +8,7 @@
|
|||||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" />
|
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||||
<orderEntry type="module" module-name="parser" />
|
<orderEntry type="module" module-name="parser" />
|
||||||
|
@ -938,7 +938,6 @@ internal class AsmGen(private val program: Program,
|
|||||||
when {
|
when {
|
||||||
iterations == 0 -> {}
|
iterations == 0 -> {}
|
||||||
iterations <= 256 -> {
|
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}")
|
out(" lda #${iterations and 255}")
|
||||||
repeatByteCountInA(iterations, repeatLabel, endLabel, stmt.body)
|
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) {
|
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!
|
// note: A/Y must have been loaded with the number of iterations already!
|
||||||
val counterVar = makeLabel("repeatcounter")
|
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("""
|
out("""
|
||||||
bne +
|
sta $counterVar
|
||||||
cpy #0
|
|
||||||
bne +
|
|
||||||
beq $endLabel
|
|
||||||
+ sta $counterVar
|
|
||||||
sty $counterVar+1
|
sty $counterVar+1
|
||||||
$repeatLabel lda $counterVar
|
$repeatLabel lda $counterVar
|
||||||
bne +
|
bne +
|
||||||
@ -1018,11 +1014,13 @@ $counterVar .word 0""")
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun repeatByteCountInA(constIterations: Int?, repeatLabel: String, endLabel: String, body: AnonymousScope) {
|
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!
|
// note: A must have been loaded with the number of iterations already!
|
||||||
val counterVar = makeLabel("repeatcounter")
|
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("""
|
out("""
|
||||||
beq $endLabel
|
|
||||||
sta $counterVar
|
sta $counterVar
|
||||||
$repeatLabel""")
|
$repeatLabel""")
|
||||||
translate(body)
|
translate(body)
|
||||||
|
@ -7,81 +7,6 @@
|
|||||||
main {
|
main {
|
||||||
|
|
||||||
sub start() {
|
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() {
|
asmsub testX() {
|
||||||
|
Loading…
Reference in New Issue
Block a user