-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Closure iterators are not supported by VM #15818
Conversation
At call site, the only difference with you need to add an explicit for k,v in myIter2(2,5):
echo k, v
if k == 0: continue
if k == 1: break
=>
for k,v in iterate myIter2(2,5):
echo k, v
if k == 0: continue
if k == 1: break At declaration site, you use a regular proc instead of an iterator to implement it, see details in #15655 This is already useful today, for code that needs functionality equivalent to closure iterators in VM or js. |
Yes but "moved feature X from the compiler to the libraries" always causes lots of work for anybody involved and plenty of subtle regressions. We should simply fix the compiler so that closure iterators are supported in the VM etc. Let's fix what we have. |
(cherry picked from commit 5b4c17b)
* follow nim-lang#15818 and close nim-lang#7109 * Update compiler/jsgen.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
* follow nim-lang#15818 and close nim-lang#7109 * Update compiler/jsgen.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
* follow nim-lang#15818 and close nim-lang#7109 * Update compiler/jsgen.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
* follow nim-lang#15818 and close nim-lang#7109 * Update compiler/jsgen.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
fixes #4695 ref #15818 Since `nkState` is only for the main loop state labels and `nkGotoState` is used only for dispatching the `:state` (since #7770), it's feasible to rewrite the loop body into a single case-based dispatcher, which enables support for JS, VM backend. `nkState` Node is replaced by a label and Node pair and `nkGotoState` is only used for intermediary processing. Backends only need to implement `nkBreakState` and `closureIterSetupExc` to support closure iterators. pending #23484 <del> I also observed some performance boost for C backend in the release mode (not in the danger mode though, I suppose the old implementation is optimized into computed goto in the danger mode) </del> allPathsAsgnResult???
I can raise error messages in JS backend too.
Are there some plans or ideas to implement closure iterators in VM or JS backend.