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 Definition.compile producing Hugr Package #504

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions guppylang/definition/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import TYPE_CHECKING, ClassVar, TypeAlias

from hugr.build.dfg import DefinitionBuilder, OpVar
from hugr.ext import Package

if TYPE_CHECKING:
from guppylang.checker.core import Globals
Expand Down Expand Up @@ -72,6 +73,10 @@ def description(self) -> str:
a function, but got {description of this definition} instead".
"""

def compile(self) -> Package:
assert self.id.module is not None
return self.id.module.compile()


class ParsableDef(Definition):
"""Abstract base class for raw definitions that still require parsing.
Expand Down
4 changes: 2 additions & 2 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def compile_guppy(fn) -> Package:
), "`@compile_guppy` does not support extra arguments."

module = GuppyModule("module")
guppylang.decorator.guppy(module)(fn)
return module.compile()
defn = guppylang.decorator.guppy(module)(fn)
return defn.compile()


def dump_llvm(hugr: Hugr | Package):
Expand Down
Loading