2424
2525
2626class InterpreterMeta (ABCMeta ):
27+ """A metaclass for interpreters."""
28+
2729 pass
2830
2931
@@ -35,8 +37,8 @@ class BaseInterpreter(ABC, Generic[FrameType, ValueType], metaclass=InterpreterM
3537 designed to be subclassed to provide the actual implementation of
3638 the interpreter.
3739
38- When subclassing, if the bases contains `ABC` no checks will be
39- performed on the subclass. If the subclass does not contain `ABC`,
40+ ### Required Overrides
41+ When subclassing, if the subclass does not contain `ABC`,
4042 the subclass must define the following attributes:
4143
4244 - `keys`: a list of strings that defines the order of dialects to select from.
@@ -83,12 +85,13 @@ def __post_init__(self) -> None:
8385 self .registry = self .dialects .registry .interpreter (keys = self .keys )
8486
8587 def initialize (self ) -> Self :
86- """Initialize the interpreter global states.
87-
88- This method is called before calling `eval` to initialize the
88+ """Initialize the interpreter global states. This method is called before
89+ calling [`run`][kirin.interp.base.BaseInterpreter.run] to initialize the
8990 interpreter global states.
9091
91- Override this method to add custom global states.
92+ !!! note "Default Implementation"
93+ This method provides default behavior but may be overridden by subclasses
94+ to customize or extend functionality.
9295 """
9396 self .symbol_table : dict [str , Statement ] = {}
9497 self .state : InterpreterState [FrameType ] = InterpreterState ()
@@ -119,7 +122,16 @@ def run(
119122 args : tuple [ValueType , ...],
120123 kwargs : dict [str , ValueType ] | None = None ,
121124 ) -> Result [ValueType ]:
122- """Run a method."""
125+ """Run a method. This is the main entry point of the interpreter.
126+
127+ Args:
128+ mt (Method): the method to run.
129+ args (tuple[ValueType]): the arguments to the method, does not include self.
130+ kwargs (dict[str, ValueType], optional): the keyword arguments to the method.
131+
132+ Returns:
133+ Result[ValueType]: the result of the method.
134+ """
123135 if self ._eval_lock :
124136 raise InterpreterError (
125137 "recursive eval is not allowed, use run_method instead"
@@ -340,6 +352,15 @@ def build_signature(self, frame: FrameType, stmt: Statement) -> "Signature":
340352 def lookup_registry (
341353 self , frame : FrameType , stmt : Statement
342354 ) -> Optional ["StatementImpl[Self, FrameType]" ]:
355+ """Lookup the statement implementation in the registry.
356+
357+ Args:
358+ frame: the current frame
359+ stmt: the statement to run
360+
361+ Returns:
362+ Optional[StatementImpl]: the statement implementation if found, None otherwise.
363+ """
343364 sig = self .build_signature (frame , stmt )
344365 if sig in self .registry .statements :
345366 return self .registry .statements [sig ]
@@ -348,7 +369,17 @@ def lookup_registry(
348369 return
349370
350371 @abstractmethod
351- def run_ssacfg_region (self , frame : FrameType , region : Region ) -> ValueType : ...
372+ def run_ssacfg_region (self , frame : FrameType , region : Region ) -> ValueType :
373+ """This implements how to run a region with MLIR SSA CFG convention.
374+
375+ Args:
376+ frame: the current frame.
377+ region: the region to run.
378+
379+ Returns:
380+ ValueType: the result of running the region.
381+ """
382+ ...
352383
353384 class FuelResult (Enum ):
354385 Stop = 0
0 commit comments