execute method
dynamic
execute({
- bool createStackFrame = true,
- bool propagateValue = true,
- HTContext? context,
- HTStackFrame? stackFrame,
- dynamic localValue,
Interpret a loaded module with the key of module
Starting from the instruction pointer of ip
This function will return current expression value
when encountered OpCode.endOfExec or OpCode.endOfFunc.
Changing library will create new stackframe. Such as currrent value, current symbol, current line & column, etc.
Implementation
dynamic execute({
bool createStackFrame = true,
bool propagateValue = true,
HTContext? context,
HTStackFrame? stackFrame,
dynamic localValue,
}) {
createStackFrame = createStackFrame || context != null;
HTContext? savedContext;
if (context != null) {
savedContext = getContext();
setContext(context);
}
if (stackFrame != null) {
_stackFrames.add(stackFrame);
createStackFrame = true;
} else if (createStackFrame) {
_createStackFrame();
}
dynamic result;
var completed = false;
try {
if (localValue != null) stack.push(localValue);
result = _execute();
completed = true;
return result;
} catch (error) {
throw _errorWithExecutionLocation(error);
} finally {
if (context != null) {
setContext(savedContext);
}
if (createStackFrame || stackFrame != null) {
if (propagateValue && completed && result is! FutureExecution) {
_retractStackFrameAndPropagate();
} else {
_retractStackFrame();
}
}
}
}