Open dcbaker opened 3 years ago
To make this more complicated than when I first wrote the issue, we have a range()
function now, which means that while the number of iterations of a foreach loop is bounded, it can be practically unbounded when using range()
, since you could write:
foreach f : range(100000000000000000000000000)
...
endforeach
Which is both easy to write, and could be a problem if we unrolled the whole loop
Although we might run into issues with the maximum size of numbers too...
I think for a first pass we just want to unroll. That might require some reworking for more complicated situations, but this should be sufficient for self-hosting, and for most real-world Meson programs
Foreach loops leak from their context, so in a case like:
a = 'b'
message(a)
foreach a : ['a']
message(a)
endforeach
message(a)
the result will be:
b
a
a
This one is actually rather annoying to think about, as it's complex control flow.
I think, since
foreach
is determanisticly sized, we can basically implement it as something like:where the on true (more iterations required) we loop back to self, but on false (break, continue, end of loop) we jump to the next block. This could of course be very annoying to code due to
unique_ptr