@@ -94,11 +94,11 @@ def run_method(
9494 This is defined by subclasses to describe what's the corresponding
9595 value of a method during the interpretation.
9696
97- Args
97+ Args:
9898 method (Method): the method to run.
9999 args (tuple[ValueType]): the arguments to the method, does not include self.
100100
101- Returns
101+ Returns:
102102 ValueType: the result of the method.
103103 """
104104 ...
@@ -108,12 +108,12 @@ def run_callable(
108108 ) -> MethodResult [ValueType ]:
109109 """Run a callable statement.
110110
111- Args
111+ Args:
112112 code (Statement): the statement to run.
113113 args (tuple[ValueType]): the arguments to the statement,
114114 includes self if the corresponding callable region contains a self argument.
115115
116- Returns
116+ Returns:
117117 ValueType: the result of the statement.
118118 """
119119 interface = code .get_trait (traits .CallableStmtInterface )
@@ -133,10 +133,13 @@ def run_callable_region(
133133 self , frame : FrameType , code : Statement , region : Region
134134 ) -> MethodResult [ValueType ]:
135135 """A hook defines how to run the callable region given
136- the interpreter context. This is experimental API, don't
137- subclass it. The current reason of having it is mainly
138- because we need to dispatch back to the MethodTable for
139- emit.
136+ the interpreter context.
137+
138+ Note:
139+ This is experimental API, don't
140+ subclass it. The current reason of having it is mainly
141+ because we need to dispatch back to the MethodTable for
142+ emit.
140143 """
141144 return self .run_ssacfg_region (frame , region )
142145
@@ -149,8 +152,10 @@ def finalize(
149152 self , frame : FrameType , results : MethodResult [ValueType ]
150153 ) -> MethodResult [ValueType ]:
151154 """Postprocess a frame after it is popped from the stack. This is
152- called after a method is evaluated and the frame is popped. Default
153- implementation does nothing.
155+ called after a method is evaluated and the frame is popped.
156+
157+ Note:
158+ Default implementation does nothing.
154159 """
155160 return results
156161
@@ -175,11 +180,10 @@ def permute_values(
175180 the given keyword arguments, where the keyword argument names
176181 refer to the last n arguments in the values tuple.
177182
178- Args
179-
180- mt: the method
181- values: the values tuple (should not contain method itself)
182- kwarg_names: the keyword argument names
183+ Args:
184+ arg_names: the argument names
185+ values: the values tuple (should not contain method itself)
186+ kwarg_names: the keyword argument names
183187 """
184188 n_total = len (values )
185189 if kwarg_names :
@@ -194,7 +198,32 @@ def permute_values(
194198 return args
195199
196200 def run_stmt (self , frame : FrameType , stmt : Statement ) -> StatementResult [ValueType ]:
197- "run a statement within the current frame"
201+ """Run a statement within the current frame
202+
203+ Args:
204+ frame: the current frame
205+ stmt: the statement to run
206+
207+ Returns:
208+ StatementResult: the result of running the statement
209+
210+ Note:
211+ In the case of implementing the fallback, subclass this method,
212+ and filter the statement type you want to handle.
213+
214+ Example:
215+ * implement an interpreter that only handles MyStmt:
216+ ```python
217+ class MyInterpreter(BaseInterpreter):
218+ ...
219+ def run_stmt(self, frame: FrameType, stmt: Statement) -> StatementResult[ValueType]:
220+ if isinstance(stmt, MyStmt):
221+ return self.run_my_stmt(frame, stmt)
222+ else:
223+ return ()
224+ ```
225+
226+ """
198227 # TODO: update tracking information
199228 return self .eval_stmt (frame , stmt )
200229
0 commit comments