mirror of
https://github.com/irmen/prog8.git
synced 2024-10-25 00:24:16 +00:00
optimizer: don't replace for loop with repeat loop (the loop variable might be used elsewhere!)
This commit is contained in:
parent
e705a8bd89
commit
07c606bfc9
@ -176,16 +176,6 @@ class StatementOptimizer(private val program: Program,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val iterationCount = forLoop.constIterationCount(program)
|
|
||||||
if(iterationCount!=null) {
|
|
||||||
val loopName = forLoop.loopVar.nameInSource
|
|
||||||
if(!forLoop.iterable.referencesIdentifier(loopName) && !forLoop.body.referencesIdentifier(loopName)) {
|
|
||||||
errors.warn("for loop can be replaced with repeat loop", forLoop.position)
|
|
||||||
val repeat = RepeatLoop(NumericLiteral.optimalNumeric(iterationCount, forLoop.position), forLoop.body, forLoop.position)
|
|
||||||
return listOf(IAstModification.ReplaceNode(forLoop, repeat, parent))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return noModifications
|
return noModifications
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ main {
|
|||||||
var result = compileText(target, true, src, writeAssembly = true)!!
|
var result = compileText(target, true, src, writeAssembly = true)!!
|
||||||
var virtfile = result.compilationOptions.outputDir.resolve(result.compilerAst.name + ".p8ir")
|
var virtfile = result.compilationOptions.outputDir.resolve(result.compilerAst.name + ".p8ir")
|
||||||
VmRunner().runAndTestProgram(virtfile.readText()) { vm ->
|
VmRunner().runAndTestProgram(virtfile.readText()) { vm ->
|
||||||
vm.stepCount shouldBe 36
|
vm.stepCount shouldBe 48
|
||||||
}
|
}
|
||||||
|
|
||||||
result = compileText(target, false, src, writeAssembly = true)!!
|
result = compileText(target, false, src, writeAssembly = true)!!
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
|
- check for name clash: variable vs block name
|
||||||
|
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user