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(py): Parametric int type helper, and arbitrary width int constants #1406

Merged
merged 3 commits into from
Aug 12, 2024
Merged
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
7 changes: 4 additions & 3 deletions hugr-py/src/hugr/std/int.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from dataclasses import dataclass
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, ClassVar

from typing_extensions import Self
Expand All @@ -15,7 +15,7 @@


def int_t(width: int) -> tys.Opaque:
"""Create an integer type with a given log bit width.
"""Create an integer type with a fixed log bit width.


Args:
Expand Down Expand Up @@ -45,9 +45,10 @@ class IntVal(val.ExtensionValue):
"""Custom value for an integer."""

v: int
width: int = field(default=5)

def to_value(self) -> val.Extension:
return val.Extension("int", INT_T, self.v)
return val.Extension("int", int_t(self.width), self.v)


OPS_EXTENSION: tys.ExtensionId = "arithmetic.int"
Expand Down
Loading