From abd70c99291f41fce57ed8d8b0692faa63117b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Borgna?= <121866228+aborgna-q@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:08:54 +0100 Subject: [PATCH] feat(py): Parametric int type helper, and arbitrary width int constants (#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 --- hugr-py/src/hugr/std/int.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hugr-py/src/hugr/std/int.py b/hugr-py/src/hugr/std/int.py index 67e7137d8..722fd3c24 100644 --- a/hugr-py/src/hugr/std/int.py +++ b/hugr-py/src/hugr/std/int.py @@ -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 @@ -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: @@ -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"