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:
@@ -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(
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user