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

feat: add assignments to tuples and lists #22

Merged
merged 1 commit into from
Jan 22, 2025
Merged

feat: add assignments to tuples and lists #22

merged 1 commit into from
Jan 22, 2025

Conversation

govereau
Copy link
Collaborator

This change adds support for assignment like: x, y = z. Python calls this "unpacking", and you can convert between lists and tuples as long as they are the right length.

@govereau govereau added the enhancement New feature or request label Jan 21, 2025
@govereau govereau requested a review from seanmcl January 21, 2025 18:29
@govereau govereau self-assigned this Jan 21, 2025
@govereau govereau requested a review from jtristan as a code owner January 21, 2025 18:29
| .expr e _ => add_stmt (.expr e)
| _ => return () -- effects are done, can be removed from KLR
let t <- term e
let _ <- RValue t
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is clear. But my thinking is that if you have an expression as a statement, then we can use the RValue conversion to figure out if it "has side-effects". If it does, the RValue translation will insert an assignment to a fresh variable, otherwise we just discard the expression (e.g. doc strings, etc.)


-- Top-level assignment handling
-- e.g. x1 = x2 = e
def assign (xs : List Term) (e : Term) : Tracer Unit := do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty.

@govereau govereau force-pushed the pg-pretty branch 2 times, most recently from 00e1cbb to b94f357 Compare January 22, 2025 14:06
Base automatically changed from pg-pretty to main January 22, 2025 14:37
This change adds support for assignment like: `x, y = z`.
Python calls this "unpacking", and you can convert between lists
and tuples as long as they are the right length.
@govereau govereau merged commit 2f03c87 into main Jan 22, 2025
1 check passed
@govereau govereau deleted the pg-assign branch January 22, 2025 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants