empty for loops are removed

This commit is contained in:
Irmen de Jong 2020-07-25 22:54:50 +02:00
parent c38508c262
commit af8279a9b9
6 changed files with 6 additions and 69 deletions

View File

@ -110,9 +110,6 @@ internal class AstChecker(private val program: Program,
}
override fun visit(forLoop: ForLoop) {
if(forLoop.body.containsNoCodeNorVars())
errors.warn("for loop body is empty", forLoop.position)
val iterableDt = forLoop.iterable.inferType(program).typeOrElse(DataType.BYTE)
if(iterableDt !in IterableDatatypes && forLoop.iterable !is RangeExpr) {
errors.err("can only loop over an iterable type", forLoop.position)

View File

@ -195,7 +195,7 @@ internal class StatementOptimizer(private val program: Program,
override fun after(forLoop: ForLoop, parent: Node): Iterable<IAstModification> {
if(forLoop.body.containsNoCodeNorVars()) {
// remove empty for loop
errors.warn("removing empty for loop", forLoop.position)
return listOf(IAstModification.Remove(forLoop, parent))
} else if(forLoop.body.statements.size==1) {
val loopvar = forLoop.body.statements[0] as? VarDecl

View File

@ -37,10 +37,8 @@ sub start() {
}
sub delay() {
ubyte d
for d in 0 to 12 {
while c64.RASTER!=0 {
; tempo delay synced to screen refresh
repeat 32 {
while c64.RASTER {
}
}
}

View File

@ -7,8 +7,7 @@ main {
sub start() {
c64scr.print("fibonacci sequence\n")
ubyte i
for i in 0 to 20 {
repeat 21 {
c64scr.print_uw(fib_next())
c64.CHROUT('\n')
}

View File

@ -7,64 +7,7 @@
main {
; TODO check removal of empty loops
sub start() {
ubyte i
for i in 1 to 20 {
c64.CHROUT('*')
}
c64.CHROUT('\n')
i=0
do {
c64.CHROUT('*')
i++
} until i==20
c64.CHROUT('\n')
repeat {
break
continue
c64.CHROUT('*')
}
c64.CHROUT('\n')
repeat 0 {
c64.CHROUT('@')
break
continue
}
c64.CHROUT('\n')
repeat 1 {
c64.CHROUT('1')
continue
break
}
c64.CHROUT('\n')
repeat 255 {
c64.CHROUT('@')
}
c64.CHROUT('\n')
repeat 256 {
c64.CHROUT('!')
}
c64.CHROUT('\n')
uword teller
repeat 4000 {
teller++
}
c64scr.print_uw(teller)
c64.CHROUT('\n')
repeat {
}
}
}

View File

@ -11,12 +11,12 @@ main {
graphics.enable_bitmap_mode()
turtle.init()
ubyte i
for i in 0 to 255 {
repeat 100 {
while c64.RASTER {
}
}
ubyte i
for i in 0 to 100 {
turtle.fd(i+20)
turtle.rt(94)