dcbaker / meson-plus-plus

An experimental and incomplete implementation of Meson in C++, for solving Meson's bootstrapping issue.
Apache License 2.0
45 stars 7 forks source link

implmenet foreach loops #21

Open dcbaker opened 3 years ago

dcbaker commented 3 years ago

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:

Block(..., condition(on_true: self, on_false: next)

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

dcbaker commented 1 year 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...