Skip to content

Commit

Permalink
feat(py): Parametric int type helper, and arbitrary width int constan…
Browse files Browse the repository at this point in the history
…ts (#1406)

- Adds an `int_tv` method to create parametric integer types
- Adds a `width` member to `IntVal`, so we can define constants for
other integer widths
  • Loading branch information
aborgna-q authored Aug 12, 2024
1 parent fa0f5a4 commit abd70c9
Showing 1 changed file with 4 additions and 3 deletions.
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

0 comments on commit abd70c9

Please sign in to comment.