Skip to content
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

nested loops are broken #10

Closed
skx opened this issue Sep 17, 2020 · 2 comments · Fixed by #14
Closed

nested loops are broken #10

skx opened this issue Sep 17, 2020 · 2 comments · Fixed by #14
Assignees

Comments

@skx
Copy link
Owner

skx commented Sep 17, 2020

We use the stack, secretly, to implement do and while, for our loops.

This works (also in word-definitions):

10 0 do dup . loop

But the following fails:

10 0 do dup .  10 0 do dup .  loop loop

This is surprising since the stack should allow nesting properly, but still .. This should be fixed.

  • NOTE: Defining a loop in a word, then calling that in a loop works, which reinforces my point that the stack should be OK:
     > : foo 10 0 do dup 48 + emit loop cr ;
     > 10 0 do foo loop 
     > 0123456789
     > 0123456789
     > 0123456789
     > 0123456789
     > 0123456789
     > 0123456789
     > 0123456789
     > 0123456789
     > 0123456789
     > 0123456789
@skx
Copy link
Owner Author

skx commented Sep 17, 2020

  • Define a new Loop structure ("cur" + "max")
  • When DO is compiled add that to e.loops
    • immediately emit "-6 NN" - where "-6" is "do-loop"
    • Add a jump if-failed to LOOP+1
  • Compile the body.
  • When LOOP is emitted jump back to DO+1
  • LOOP+1 will pop the Loop entry off the stack.

Nothing gets stored on the stack. We'll have to define i to get the current iteration, of course..

@skx skx self-assigned this Sep 17, 2020
@skx
Copy link
Owner Author

skx commented Sep 17, 2020

Fixing this would also increase our test-coverage - perhaps to exceed 99% :)

@skx skx mentioned this issue Sep 18, 2020
@skx skx closed this as completed in #14 Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant