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

Fix and document for-each loops

This commit is contained in:
Karol Stasiak 2019-06-24 23:51:17 +02:00
parent 25c440f17d
commit d8defaad82
4 changed files with 10 additions and 4 deletions

View File

@ -66,6 +66,8 @@
* Fixed `@long` and `@long_be` array filters.
* Fixed for-each loops with non-constant arrays.
* 8080 and LR35902: fixed large stack variables.
* Other bug fixes.

View File

@ -312,11 +312,13 @@ for <variable> : [ <comma separated expressions> ] {
* `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
* `<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

View File

@ -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 {
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 flatMap(f: ExecutableStatement => Option[ExecutableStatement]): Option[ExecutableStatement] = {

View File

@ -351,7 +351,9 @@ class ForLoopSuite extends FunSuite with Matchers {
| for p:[$c000, $c003, $c005, $c007]{
| p[0] = 34
| }
| for p:[$c001, $c004, $c006, $c008]{
| word w
| w = $c004
| for p:[$c001, w, $c006, w+4]{
| p[0] = 42
| }
| }