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

Convert to pass-by-reference instead of pass-by-value #678

Merged
merged 1 commit into from
Mar 17, 2024

Conversation

dfellis
Copy link
Member

@dfellis dfellis commented Mar 17, 2024

Beyond toy programs, the translation of Alan code needs to normally be pass-by-reference under the hood in Rust so variable names remain available after being used on a function call. Most developers would not expect their variable name to no longer be valid after they provided it to a function.

Further, some functions will need to be mutable references to allow mutation of a provided variable. This can make the state of your own code harder to follow since your own variables may be mutated by the functions you're calling, instead of returning a new variable with a new value, but in certain situations it is both more performant and is expected, for instance with arrays/vectors. How the clarity of mutable variables is dealt with is beyond this PR, and also probably beyond the first major demo, since I can get away with binding Rust functions that have mutable arguments and not worry about how this will be handled in pure Alan code for now.

At the moment, I'm butchering the intent of pass-by-reference by then immediately .clone()ing every argument passed in for pure-Alan functions (but also not a problem with the bound functions). I figure later I will introduce a ref/val flag on variable names in the Microstatements, as well as a mutability flag (which is partially implemented) that may or may not be used to inform function generation. But this PR has gotten large enough as it is, so I figured it's best to stop here now that the test suite is back to the watermark on main.

@dfellis dfellis self-assigned this Mar 17, 2024
@dfellis dfellis merged commit a7f3342 into main Mar 17, 2024
1 of 2 checks passed
@dfellis dfellis deleted the pass-by-reference branch March 17, 2024 21:25
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