board_inspector: return from method call invocation on DefReturn
The current implementation of the AML interpreter continues interpreting a method after meeting a DefReturn object, which is incorrect. This patch fixes this issue by raising a dedicated exception on return and catching that exception on the caller side. Tracked-On: #6298 Signed-off-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
parent
09e5df01b1
commit
e56eb6238d
|
@ -7,6 +7,11 @@ from .context import *
|
||||||
from .datatypes import *
|
from .datatypes import *
|
||||||
from .tree import Tree, Interpreter
|
from .tree import Tree, Interpreter
|
||||||
|
|
||||||
|
class MethodReturn(Exception):
|
||||||
|
""" A pseudo exception to return from a method"""
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
class ConcreteInterpreter(Interpreter):
|
class ConcreteInterpreter(Interpreter):
|
||||||
class Argument(Object):
|
class Argument(Object):
|
||||||
def __init__(self, frame, index):
|
def __init__(self, frame, index):
|
||||||
|
@ -188,7 +193,10 @@ class ConcreteInterpreter(Interpreter):
|
||||||
# Evaluate the statements of the callee
|
# Evaluate the statements of the callee
|
||||||
self.stack.append(self.StackFrame(realpath, args))
|
self.stack.append(self.StackFrame(realpath, args))
|
||||||
logging.debug(f"Calling {realpath} with args {args}")
|
logging.debug(f"Calling {realpath} with args {args}")
|
||||||
|
try:
|
||||||
self.interpret(value.body)
|
self.interpret(value.body)
|
||||||
|
except MethodReturn:
|
||||||
|
pass
|
||||||
frame = self.stack.pop()
|
frame = self.stack.pop()
|
||||||
self.context.pop_scope()
|
self.context.pop_scope()
|
||||||
|
|
||||||
|
@ -335,6 +343,7 @@ class ConcreteInterpreter(Interpreter):
|
||||||
if isinstance(obj, (self.Argument, self.LocalVariable)):
|
if isinstance(obj, (self.Argument, self.LocalVariable)):
|
||||||
obj = obj.get_obj()
|
obj = obj.get_obj()
|
||||||
self.stack[-1].return_value = obj
|
self.stack[-1].return_value = obj
|
||||||
|
raise MethodReturn()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def DefSignal(self, tree):
|
def DefSignal(self, tree):
|
||||||
|
|
Loading…
Reference in New Issue