1+ from __future__ import annotations
2+
13import sys
24from abc import ABC , ABCMeta , abstractmethod
35from enum import Enum
4- from typing import (
5- TYPE_CHECKING ,
6- Any ,
7- Generic ,
8- TypeVar ,
9- ClassVar ,
10- Optional ,
11- Sequence ,
12- Generator ,
13- )
6+ from typing import Any , Generic , TypeVar , ClassVar , Optional , Sequence , Generator
147from contextlib import contextmanager
158from dataclasses import field , dataclass
169
1912from kirin .ir import Block , Method , Region , Statement , DialectGroup , traits
2013from kirin .exception import KIRIN_INTERP_STATE
2114
22- from .impl import Signature
2315from .frame import FrameABC
2416from .state import InterpreterState
17+ from .table import Signature , BoundedDef
2518from .value import Successor , ReturnValue , SpecialValue , StatementResult
2619from .exceptions import InterpreterError
2720
28- if TYPE_CHECKING :
29- from kirin .registry import StatementImpl , InterpreterRegistry
30-
3121ValueType = TypeVar ("ValueType" )
3222FrameType = TypeVar ("FrameType" , bound = FrameABC )
3323
@@ -57,9 +47,6 @@ class BaseInterpreter(ABC, Generic[FrameType, ValueType], metaclass=InterpreterM
5747 keys : ClassVar [list [str ]]
5848 """The name of the interpreter to select from dialects by order.
5949 """
60- Frame : ClassVar [type [FrameABC ]] = field (init = False )
61- """The type of the frame to use for this interpreter.
62- """
6350 void : ValueType = field (init = False )
6451 """What to return when the interpreter evaluates nothing.
6552 """
@@ -80,7 +67,7 @@ class BaseInterpreter(ABC, Generic[FrameType, ValueType], metaclass=InterpreterM
8067 """
8168
8269 # global states
83- registry : "InterpreterRegistry" = field (init = False , compare = False )
70+ registry : dict [ Signature , BoundedDef ] = field (init = False , compare = False )
8471 """The interpreter registry.
8572 """
8673 symbol_table : dict [str , Statement ] = field (init = False , compare = False )
@@ -433,7 +420,7 @@ def build_signature(self, frame: FrameType, stmt: Statement) -> "Signature":
433420
434421 def lookup_registry (
435422 self , frame : FrameType , stmt : Statement
436- ) -> Optional ["StatementImpl[Self, FrameType]" ]:
423+ ) -> Optional [BoundedDef ]:
437424 """Lookup the statement implementation in the registry.
438425
439426 Args:
@@ -444,10 +431,10 @@ def lookup_registry(
444431 Optional[StatementImpl]: the statement implementation if found, None otherwise.
445432 """
446433 sig = self .build_signature (frame , stmt )
447- if sig in self .registry . statements :
448- return self .registry . statements [sig ]
449- elif (class_sig := Signature (stmt .__class__ )) in self . registry . statements :
450- return self . registry . statements [ class_sig ]
434+ if sig in self .registry :
435+ return self .registry [sig ]
436+ elif (method := self . registry . get ( Signature (stmt .__class__ ))) is not None :
437+ return method
451438 return
452439
453440 @abstractmethod
0 commit comments