-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request - Foreach over variable or constant lists #137
Comments
For further motivation, see this example (from #136)
|
That's a very good idea! I might just drop the explicit grouping of the values, so my syntax would look something like this (if it turns out to be easier to implement in the grammar):
I'm not entirely sure I understand this:
Generally, working with indexes is troublesome in mlog. I do plan to add memory-backed arrays eventually. For the time being, I plan to add a
This would set all variables to 1. In case of loops with several foreach variables we would need to specify which value are we assigning to, so maybe
Would this satisfy your needs? |
Awesome! The yield idea does indeed satisfy my I was expecting when I suggested in the foreach loop that these loops must be unrolled (this is the best way I can think of to get/set those values in mlog). You could potentially lift the loop body into a compiler generated "function" and then potentially trigger the standard "inline" optimisation if the body is small. Instead of yield (is that a ruby thing?) you might consider the C syntax i* = rand(5) (treat it like a pointer) or just auto-detect that you are treating i like a variable. Potentially
or
|
Oh, having reviewed #138 I think you should use the same syntax
|
This is an excellent idea - much better than yield! (Yield would be problematic - I'd probably need an extra variable to hold the result of the last yield in case the loop control variable was reassigned separately not using yield). Any assignments to an Also, when I mentioned I want to have memory-backed arrays, I actually meant processor-variables backed arrays. And yes, these would rock with loop unrolling :) |
Woah, it would really be something to have arrays without needing a memory processor thingie. I miss array access. I can see how that would be possible with unrolling or a syntax-sugar case statement. |
This is now covered by #142. |
Hey, you could achieve arrays by creating a set of assignments followed by jumps. This is kind of pseudocode but like this
And then you write into this array by loading Another block of similar code deals with reads into And if unrolling means you know the array index as a constant, you can just write or read directly from |
Yes, that's pretty much it. I just need to think of a good way of representing these operations in the pseudocode, so that the DFO can easily replace an access to a dynamic index with direct variable when the index is resolved as static. By the way, mlogjs already has these arrays. Not the optimization, though, as far as I'm aware. (Edit: it has the optimization for simple cases. It doesn't have loop unrolling and a general data flow optimization, I think). |
Instead of this construct:
It would be nice to write something like this
This is like list iteration and tuple unpacking in Python (I haven't used ruby). Even nicer if there is a way to take output values from a loop and assign those to various values depending on index also.
I guess the current workaround is to make a list of function calls instead, which is probably the process I'll need to start using. Though that would require #138
The text was updated successfully, but these errors were encountered: