1
0
mirror of https://github.com/KarolS/millfork.git synced 2026-04-19 10:42:10 +00:00

Fix for i,const,downto,0 loops

This commit is contained in:
Karol Stasiak
2018-06-04 09:44:54 +02:00
parent 0c50c4562a
commit 0919a98e4b
2 changed files with 23 additions and 2 deletions
@@ -419,8 +419,8 @@ object StatementCompiler {
Nil
case (ForDirection.DownTo, Some(NumericConstant(s, ssize)), Some(NumericConstant(0, esize))) if s > 0 =>
compile(ctx, List(
Assignment(vex, f.start),
DoWhileStatement(f.body, List(decrement), FunctionCallExpression("!=", List(vex, f.end)), names)
Assignment(vex, SumExpression(List(false -> f.start, false -> LiteralExpression(1, 1)), decimal = false)),
DoWhileStatement(decrement :: f.body, Nil, FunctionCallExpression("!=", List(vex, f.end)), names)
))
@@ -54,6 +54,27 @@ class ForLoopSuite extends FunSuite with Matchers {
| }
""".stripMargin)(_.readByte(0xc000) should equal(15))
}
test("For-downto 2") {
EmuBenchmarkRun(
"""
| array output [55] @$c000
| void main () {
| byte i
| output[0] = 0
| output[5] = 0
| output[6] = 0
| for i,5,downto,0 {
| output[i] += 1
| }
| }
""".stripMargin){m =>
m.readByte(0xc000) should equal(1)
m.readByte(0xc005) should equal(1)
m.readByte(0xc006) should equal(0)
}
}
test("For-until") {
EmuBenchmarkRun(
"""