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

Add support for initializers in interpreter #8

Conversation

janvrany
Copy link
Collaborator

This PR depends on #7 (for parsing let and register initializers).

This commit add support for let's and register's initializers. These
initializers are executed before the main entry point.

This prompted some changes in the interpreter. Since there's no longer
a single "entry" function but rather a list of initializers followed
by the "entry" function, the interpreter maintains a worklist of
functions to execute (in `todo` instvar) and when the bottom-most context
returns, it simply executes next function in the worklist. Interpretation
finishes once all functions from worklist are executed and return (see
`JibInterpreter >> interpretEnd:`).

Another little complication comes from the fact that - for some unknown
reason - initializers do not have explicit `end` instruction. To deal
with this, after each instruction executed the interpreter checks if the
PC (of next instruction) is beyond the end of instruction sequence and
if it is, executes fabricated `end`. This way, the function return logic
is at single place (`JibInterpreter >> interpretEnd:`).
@janvrany janvrany force-pushed the pr/add-support-for-initializers-in-interpreter branch from 6cfbb5d to 39f88ef Compare March 20, 2025 21:25
@janvrany janvrany marked this pull request as ready for review March 20, 2025 21:25
@janvrany janvrany merged commit 65b6625 into shingarov:master Mar 20, 2025
1 check passed
@janvrany janvrany deleted the pr/add-support-for-initializers-in-interpreter branch March 20, 2025 21:27
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 this pull request may close these issues.

1 participant