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

Interpreter: callProcedure with return values #352

Merged
merged 5 commits into from
Mar 12, 2025
Merged

Conversation

ailrst
Copy link
Contributor

@ailrst ailrst commented Mar 7, 2025

This refactors the interpreter entrypoint around the function callProcedure, which returns a future which immediately evaluates the call to the procedure and returns its return values (if the procedure has out-parameters defined). The goal here is to make it easier to write tests such that you can simply write a procedure literal, and evaluate it, and assert the return value.

This also lays the groundwork to cleanup the implementation of intrinsic functions. Currently we have intrinsics that expect to read/write global registers, so calls with formal parameters are stored to the expected global variables before the call, and read back after. This can be substantially cleaned up (and some indirection removed) by instead standardising intrinsics on the parameter form, and if the IR doesn't have parameters then storing the return values to the appropriate registers (i.e. the reverse).

This also simplifies the return value handling in the interpreter by putting it back in the DirectCall, because now we can immediately get the state & return value after the call. This is possible because callProcedure is evaluating the procedure immediately through the call to evalInterpreter(f, interpretContinuation(f)). (Recall our general approach to dealing with statemonad closures producing stack overflows is to perform eval at each interpreter step (ir statement), this is now additionally doing an eval at each call). I'm not sure what the downside to this is but it is not great.

@ailrst ailrst force-pushed the interpreter-eval-proc branch from 1080752 to 5afe207 Compare March 12, 2025 04:10
@ailrst ailrst merged commit 9b8fc6e into main Mar 12, 2025
5 checks passed
@katrinafyi katrinafyi deleted the interpreter-eval-proc branch March 13, 2025 06:17
@katrinafyi katrinafyi restored the interpreter-eval-proc branch March 13, 2025 06:21
@katrinafyi katrinafyi deleted the interpreter-eval-proc branch March 13, 2025 06:22
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