mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-26 20:33:02 +00:00
For-to loop fixes
This commit is contained in:
parent
c8c6ec83fc
commit
4e80236a65
@ -44,6 +44,8 @@ where `11111` is a sequential number and `xx` is the type:
|
||||
|
||||
* `th` – beginning of the "then" block in an `if` statement
|
||||
|
||||
* `to` – end of a `for-to` loop
|
||||
|
||||
* `wh` – beginning of a `while` statement
|
||||
|
||||
|
||||
|
@ -1745,12 +1745,24 @@ object MfCompiler {
|
||||
FunctionCallExpression("<", List(vex, f.end)),
|
||||
f.body :+ increment),
|
||||
))
|
||||
// case (ForDirection.To | ForDirection.ParallelTo, _, Some(NumericConstant(n, _))) if n > 0 && n < 255 =>
|
||||
// compile(ctx, List(
|
||||
// Assignment(vex, f.start),
|
||||
// WhileStatement(
|
||||
// FunctionCallExpression("<=", List(vex, f.end)),
|
||||
// f.body :+ increment),
|
||||
// ))
|
||||
case (ForDirection.To | ForDirection.ParallelTo, _, _) =>
|
||||
val label = nextLabel("to")
|
||||
compile(ctx, List(
|
||||
Assignment(vex, f.start),
|
||||
WhileStatement(
|
||||
FunctionCallExpression("<=", List(vex, f.end)),
|
||||
f.body :+ increment),
|
||||
VariableExpression("true"),
|
||||
f.body :+ IfStatement(
|
||||
FunctionCallExpression("==", List(vex, f.end)),
|
||||
List(AssemblyStatement(JMP, AddrMode.Absolute, VariableExpression(label), elidable = true)),
|
||||
List(increment))),
|
||||
AssemblyStatement(LABEL, AddrMode.DoesNotExist, VariableExpression(label), elidable=true)
|
||||
))
|
||||
case (ForDirection.DownTo, _, _) =>
|
||||
compile(ctx, List(
|
||||
|
@ -1,6 +1,6 @@
|
||||
package millfork.test
|
||||
|
||||
import millfork.test.emu.EmuBenchmarkRun
|
||||
import millfork.test.emu.{EmuBenchmarkRun, EmuUnoptimizedRun}
|
||||
import org.scalatest.{FunSuite, Matchers}
|
||||
|
||||
/**
|
||||
@ -21,6 +21,26 @@ class ForLoopSuite extends FunSuite with Matchers {
|
||||
| }
|
||||
""".stripMargin)(_.readByte(0xc000) should equal(15))
|
||||
}
|
||||
|
||||
test("For-to 2") {
|
||||
EmuBenchmarkRun(
|
||||
"""
|
||||
| word output @$c000
|
||||
| byte five
|
||||
| void main () {
|
||||
| init()
|
||||
| byte i
|
||||
| output = 0
|
||||
| for i,0,to,five {
|
||||
| output += i
|
||||
| }
|
||||
| }
|
||||
| void init() {
|
||||
| five = 5
|
||||
| }
|
||||
""".stripMargin)(_.readByte(0xc000) should equal(15))
|
||||
}
|
||||
|
||||
test("For-downto") {
|
||||
EmuBenchmarkRun(
|
||||
"""
|
||||
@ -73,4 +93,41 @@ class ForLoopSuite extends FunSuite with Matchers {
|
||||
| }
|
||||
""".stripMargin)(_.readByte(0xc000) should equal(15))
|
||||
}
|
||||
|
||||
test("Various loops") {
|
||||
EmuUnoptimizedRun(
|
||||
"""
|
||||
| void init() {
|
||||
| zero = 0
|
||||
| ff = $ff
|
||||
| }
|
||||
| byte zero
|
||||
| byte ff
|
||||
| byte flag @$c000
|
||||
| void main () {
|
||||
| init()
|
||||
| byte i
|
||||
| flag = 0
|
||||
| for i, zero, until, ff { }
|
||||
| flag = 1
|
||||
| for i, zero, to, ff { }
|
||||
| flag = 2
|
||||
| for i, ff, downto, zero { }
|
||||
| flag = 3
|
||||
| for i, zero, paralleluntil, ff { }
|
||||
| flag = 4
|
||||
| for i, zero, parallelto, ff { }
|
||||
| flag = 5
|
||||
| for i, ff, until, zero { _panic() }
|
||||
| flag = 6
|
||||
| for i, ff, paralleluntil, zero { _panic() }
|
||||
| flag = 7
|
||||
| for i, ff, paralleluntil, zero { _panic() }
|
||||
| flag = 8
|
||||
| for i, zero, until, ff { }
|
||||
| flag = 9
|
||||
| }
|
||||
| void _panic(){while(true){}}
|
||||
""".stripMargin)
|
||||
}
|
||||
}
|
||||
|
@ -222,6 +222,7 @@ class EmuRun(cpu: millfork.Cpu.Value, nodeOptimizations: List[NodeOptimization],
|
||||
}
|
||||
}
|
||||
}
|
||||
ErrorReporting.trace(f"[$$c000] = ${memoryBank.readByte(0xc000)}%02X")
|
||||
countCmos should be < TooManyCycles
|
||||
println(countNmos + " NMOS cycles")
|
||||
println(countCmos + " CMOS cycles")
|
||||
|
Loading…
x
Reference in New Issue
Block a user