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

Fix/local variables #58

Merged
merged 16 commits into from
Mar 26, 2023
Merged

Fix/local variables #58

merged 16 commits into from
Mar 26, 2023

Conversation

frendsick
Copy link
Owner

Resolves #54

Fix recursion by using the return stack for local variables.

Functions perform the following procedure:

  1. Push the return address to the return stack
  2. Push parameters to the return stack
  3. Run the function
  4. At the end of the function, drop its parameters from the return stack
  5. Pop the return address from the return stack
  6. Return to the popped return address

Note: The torth.torth compiler version can correctly compile all other known Torth programs except for itself. For some reason, the compiler version compiled by itself cannot compile another program anymore, as some list reference is zeroed. It causes a segfault at the first step of compilation, which includes all of the included files from every file referenced. A new issue will be opened for that bug which needs more debugging. In any case, I decided to merge the current version because it seems to work in other occurrences. The original compiler could even have worked because of some bug fixed alongside recursion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Function parameter and variable values are shared between recursive function calls
1 participant