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: Allow lists in py expressions #113

Merged
merged 5 commits into from
Feb 1, 2024
Merged

feat: Allow lists in py expressions #113

merged 5 commits into from
Feb 1, 2024

Conversation

mark-koch
Copy link
Collaborator

@mark-koch mark-koch commented Jan 18, 2024

Closes #114

node,
) from e

python_val = eval_py_expr(node, self.ctx)
if ty := python_value_to_guppy_type(python_val, node, self.ctx.globals):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand why we're converting python_val to a type. It's an arbitrary python value right? Just something inside a py(...)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, I'm looking up how python match works...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here, we're checking that the Python expression inside py(...) evaluates to something that is valid in Guppy and compute the corresponding Guppy type

@@ -67,6 +74,11 @@ def float_value(f: float) -> val.Value:
return val.ExtensionVal(c=(ConstF64(value=f),))


def list_value(v: list[val.Value]) -> val.Value:
"""Returns the Hugr representation of a list value."""
return val.ExtensionVal(c=(ListValue(value=v),))
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does the , do here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(x,) is a unary tuple. We need this because of some serialisation shenanigans...

@mark-koch mark-koch requested a review from croyzor January 30, 2024 09:54
@mark-koch mark-koch merged commit caaf562 into main Feb 1, 2024
2 checks passed
@mark-koch mark-koch deleted the feat/py-lists branch February 1, 2024 10:27
This was referenced Apr 10, 2024
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.

Support lists in py() expressions
2 participants