Skip to content

Impl

AttributeImplDef dataclass

AttributeImplDef(signature: SigType, impl: ImplType)

Bases: Def[type[Attribute], 'AttributeFunction']

Definition of an interpreter implementation for an attribute.

Def dataclass

Def(signature: SigType, impl: ImplType)

Bases: Generic[SigType, ImplType]

Base class of an interpreter implementation definition.

ImplDef dataclass

ImplDef(
    signature: SigType,
    impl: ImplType,
    parent: Type[Statement],
)

Bases: Def[tuple[Signature, ...], 'MethodFunction']

Definition of an interpreter implementation for a statement.

Signature dataclass

Signature(
    stmt: Type[Statement],
    args: tuple[types.TypeAttribute, ...] | None = None,
)

Signature of a statement.

impl

impl(
    stmt_or_attribute: Type[HeadType],
    *args: types.TypeAttribute
)

Bases: Generic[HeadType]

Decorator to define an interpreter implementation for a statement or attribute.

Note

While the impl decorator accepts both statements and attributes, and optionally statements with its type signature, unlike a programming language, the actual dispatch behavior given an instance of a statement or attribute is defined by the implementation of the interpreter (via lookup_registry).

Example

@dialect.register
class MyMethods(interp.MethodTable):
    @impl(Add)
    def interp_add(
        self,
        interp: Interpreter,
        frame: Frame,
        stmt: Add,
    ) -> StatementResult:
        ...
Source code in src/kirin/interp/impl.py
120
121
122
123
124
125
126
def __init__(
    self, stmt_or_attribute: Type[HeadType], *args: types.TypeAttribute
) -> None:
    if args and issubclass(stmt_or_attribute, Attribute):
        raise ValueError("Attributes do not take arguments")
    self.stmt_or_attribute: type[HeadType] = stmt_or_attribute
    self.args = args