mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-07 16:29:59 +00:00
Fix for...downto loops
This commit is contained in:
parent
6b43f73f57
commit
df71435c78
@ -229,6 +229,8 @@ abstract class AbstractStatementCompiler[T <: AbstractCode] {
|
||||
names)
|
||||
))
|
||||
case (ForDirection.DownTo, _, _) =>
|
||||
// TODO: smarter countdown if end is not a constant
|
||||
val endMinusOne = SumExpression(List(true -> f.end, false -> LiteralExpression(1, 1)), decimal = false).pos(p)
|
||||
compile(ctx, List(
|
||||
Assignment(vex, f.start).pos(p),
|
||||
IfStatement(
|
||||
@ -236,7 +238,7 @@ abstract class AbstractStatementCompiler[T <: AbstractCode] {
|
||||
List(DoWhileStatement(
|
||||
f.body,
|
||||
List(decrement),
|
||||
FunctionCallExpression("!=", List(vex, f.end)).pos(p),
|
||||
FunctionCallExpression("!=", List(vex, endMinusOne)).pos(p),
|
||||
names
|
||||
).pos(p)),
|
||||
Nil)
|
||||
|
@ -77,6 +77,30 @@ class ForLoopSuite extends FunSuite with Matchers {
|
||||
}
|
||||
}
|
||||
|
||||
test("For-downto 3") {
|
||||
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)(
|
||||
"""
|
||||
| array output [55] @$c000
|
||||
| void main () {
|
||||
| byte i
|
||||
| output[0] = 0
|
||||
| output[1] = 0
|
||||
| output[5] = 0
|
||||
| output[6] = 0
|
||||
| for i,5,downto,1 {
|
||||
| stuff()
|
||||
| output[i] += 1
|
||||
| }
|
||||
| }
|
||||
| noinline void stuff() {}
|
||||
""".stripMargin){m =>
|
||||
m.readByte(0xc000) should equal(0)
|
||||
m.readByte(0xc001) should equal(1)
|
||||
m.readByte(0xc005) should equal(1)
|
||||
m.readByte(0xc006) should equal(0)
|
||||
}
|
||||
}
|
||||
|
||||
test("For-until") {
|
||||
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)(
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user