mirror of
https://github.com/KarolS/millfork.git
synced 2024-11-17 01:07:08 +00:00
Fix and document for-each loops
This commit is contained in:
parent
25c440f17d
commit
d8defaad82
@ -66,6 +66,8 @@
|
|||||||
|
|
||||||
* Fixed `@long` and `@long_be` array filters.
|
* Fixed `@long` and `@long_be` array filters.
|
||||||
|
|
||||||
|
* Fixed for-each loops with non-constant arrays.
|
||||||
|
|
||||||
* 8080 and LR35902: fixed large stack variables.
|
* 8080 and LR35902: fixed large stack variables.
|
||||||
|
|
||||||
* Other bug fixes.
|
* Other bug fixes.
|
||||||
|
@ -312,11 +312,13 @@ for <variable> : [ <comma separated expressions> ] {
|
|||||||
|
|
||||||
* `paralleluntil` – the same as `until`, but the iterations may be executed in any order
|
* `paralleluntil` – the same as `until`, but the iterations may be executed in any order
|
||||||
|
|
||||||
There is no `paralleldownto`, because it would do the same as `parallelto`.
|
There is no `paralleldownto`, because it would do the same as `parallelto` with swapped arguments.
|
||||||
|
|
||||||
* `<enum type>` – traverse enum constants of given type, in arbitrary order
|
* `<enum type>` – traverse enum constants of given type, in arbitrary order
|
||||||
|
|
||||||
* `<comma separated expressions>` – traverse every value in the list
|
* `<comma separated expressions>` – traverse every value in the list, in the given order.
|
||||||
|
Values do not have to be constant.
|
||||||
|
If a value is not a constant and its value changes while executing the loop, the behaviour is undefined.
|
||||||
|
|
||||||
### `break` and `continue` statements
|
### `break` and `continue` statements
|
||||||
|
|
||||||
|
@ -515,7 +515,7 @@ case class ForStatement(variable: String, start: Expression, end: Expression, di
|
|||||||
}
|
}
|
||||||
|
|
||||||
case class ForEachStatement(variable: String, values: Either[Expression, List[Expression]], body: List[ExecutableStatement]) extends CompoundStatement {
|
case class ForEachStatement(variable: String, values: Either[Expression, List[Expression]], body: List[ExecutableStatement]) extends CompoundStatement {
|
||||||
override def getAllExpressions: List[Expression] = VariableExpression(variable) :: body.flatMap(_.getAllExpressions)
|
override def getAllExpressions: List[Expression] = VariableExpression(variable) :: (values.fold[List[Expression]](_ => Nil, identity) ++ body.flatMap(_.getAllExpressions))
|
||||||
|
|
||||||
override def getChildStatements: Seq[Statement] = body
|
override def getChildStatements: Seq[Statement] = body
|
||||||
override def flatMap(f: ExecutableStatement => Option[ExecutableStatement]): Option[ExecutableStatement] = {
|
override def flatMap(f: ExecutableStatement => Option[ExecutableStatement]): Option[ExecutableStatement] = {
|
||||||
|
@ -351,7 +351,9 @@ class ForLoopSuite extends FunSuite with Matchers {
|
|||||||
| for p:[$c000, $c003, $c005, $c007]{
|
| for p:[$c000, $c003, $c005, $c007]{
|
||||||
| p[0] = 34
|
| p[0] = 34
|
||||||
| }
|
| }
|
||||||
| for p:[$c001, $c004, $c006, $c008]{
|
| word w
|
||||||
|
| w = $c004
|
||||||
|
| for p:[$c001, w, $c006, w+4]{
|
||||||
| p[0] = 42
|
| p[0] = 42
|
||||||
| }
|
| }
|
||||||
| }
|
| }
|
||||||
|
Loading…
Reference in New Issue
Block a user