verachell / YeetWords

a domain-specific language for text substitution
GNU General Public License v3.0
13 stars 0 forks source link

Ruby runs out of stack space on large LOOP commands #4

Closed verachell closed 2 years ago

verachell commented 2 years ago

This issue relates to a previous issue https://github.com/verachell/YeetWords/issues/3 . In certain situations, large loops such as the one below can result in Ruby running out of stack space and dropping out into the interpreter.

LOOP 50000W
WRITE mysentences wfolder
LOOPEND

Most likely, the fix would be rewriting the loop_iterator function iteratively instead of recursively.

verachell commented 2 years ago

I am working on a fix. The loop_iterator function is difficult to rewrite iteratively because it involves a nested recursive function. Initially I'm going to make it partially recursive (i.e. switch one of the recursive calls to iterative; leave the other recursive).

I have reason to believe this approach will work, because as proof of concept I created a simple stripped-down analogous program with a fully recursive and partially recursive version of the function. See https://gist.github.com/verachell/bd16905547f0ff00014e6a8b49f65e82 The fully recursive version winds up running out of stack space with an end parameter of 20000, while the partially recursive one works fine with those same parameters (altho be aware parameters bear no direct relationship to the YeetWords parameters). I'll be updating the status of this issue more frequently in its project card, see https://github.com/verachell/YeetWords/projects/1#card-72017363 . I'll just comment here on this issue thread for "big-picture" type of updates.

So if you are interested in closely following the status of this issue, look at the project card instead. I'm planning to do as much as I can on it within the next 48h so you can expect some updates on the project card in the near future.

verachell commented 2 years ago

The 1.1.2 release reflects this fix. Fixed by refactoring loop_iterator function to be partially iterative (vs branching recursive before). Also included are: fix: END-style commands can be used interchangeably as intended. fix: created a more consistent indicator of progress to the user in long LOOP and WRITE commands. fix: user receives warning message for large LOOP and WRITE parameter values (program continues). These changes were made together instead of incrementally because testing of these fixes overlapped.