1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-06-12 06:29:34 +00:00

Implicit ranges in for loops are dumb, remove

This commit is contained in:
Karol Stasiak 2018-12-22 01:30:54 +01:00
parent 84c3406dc7
commit acaaa5bdfe
4 changed files with 5 additions and 74 deletions

View File

@ -14,7 +14,7 @@
* Added preprocessor.
* Added `for` loops over arrays, enum types and in-place lists
* Added `for` loops over enum types and in-place lists
* Added `align` keyword for choosing data and code alignment.

View File

@ -257,7 +257,7 @@ Syntax:
```
for <variable> , <start> , <direction> , <end> {
}
for <variable> : <array,enum type or expression> {
for <variable> : <enum type> {
}
for <variable> : [ <comma separated expressions> ] {
}
@ -282,12 +282,8 @@ for <variable> : [ <comma separated expressions> ] {
There is no `paralleldownto`, because it would do the same as `parallelto`.
* `<array>` traverse indices of an array, from 0 to length1
* `<enum type>` traverse enum constants of given type, in arbitrary order
* `<expression>` traverse from 0 to `expression` 1
* `<comma separated expressions>` traverse every value in the list
### `break` and `continue` statements

View File

@ -315,17 +315,6 @@ abstract class AbstractStatementCompiler[T <: AbstractCode] {
case Left(expr) =>
expr match {
case VariableExpression(id) =>
ctx.env.maybeGet[Thing](id + ".array") match {
case Some(arr:MfArray) =>
return compile(ctx, ForStatement(
f.variable,
LiteralExpression(0, 1),
LiteralExpression(arr.sizeInBytes, Constant.minimumSize(arr.sizeInBytes - 1)),
ForDirection.Until,
f.body
))
case _ =>
}
ctx.env.get[Thing](id) match {
case EnumType(_, Some(count)) =>
return compile(ctx, ForStatement(
@ -339,14 +328,9 @@ abstract class AbstractStatementCompiler[T <: AbstractCode] {
}
case _ =>
}
return compile(ctx, ForStatement(
f.variable,
LiteralExpression(0, 1),
expr,
ForDirection.Until,
f.body
))
ctx.log.error("Not a valid enum type or an inline array", expr.position)
compile(ctx, f.body)
return Nil -> Nil
case Right(vs) => vs
}
val endLabel = ctx.nextLabel("fe")

View File

@ -115,20 +115,6 @@ class ForLoopSuite extends FunSuite with Matchers {
""".stripMargin)(_.readByte(0xc000) should equal(15))
}
test("For-until 2") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)(
"""
| word output @$c000
| void main () {
| byte i
| output = 0
| for i : 6 {
| output += i
| }
| }
""".stripMargin)(_.readByte(0xc000) should equal(15))
}
test("For-parallelto") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)(
"""
@ -214,24 +200,6 @@ class ForLoopSuite extends FunSuite with Matchers {
}
}
test("Memcpy 2") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)(
"""
| array output[5]@$c001
| array input = [0,1,4,9,16,25,36,49]
| void main () {
| byte i
| for i : output {
| output[i] = input[i+1]
| }
| }
| void _panic(){while(true){}}
""".stripMargin){ m=>
m.readByte(0xc001) should equal (1)
m.readByte(0xc005) should equal (25)
}
}
test("Memset with index") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)(
"""
@ -249,23 +217,6 @@ class ForLoopSuite extends FunSuite with Matchers {
}
}
test("Memset with index 2") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)(
"""
| array output[5]@$c001
| void main () {
| byte i
| for i : output {
| output[i] = 22
| }
| }
| void _panic(){while(true){}}
""".stripMargin){ m=>
m.readByte(0xc001) should equal (22)
m.readByte(0xc005) should equal (22)
}
}
test("Memset with pointer") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)(
"""