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();
}
if (localValue != null) stack.push(localValue);
final result = _execute();
if (context != null) {
setContext(savedContext);
}
// Always remove frames we created (prevent leaks), but only propagate when requested.
if (createStackFrame || stackFrame != null) {
if (propagateValue) {
_retractStackFrameAndPropagate();
} else {
_retractStackFrame();
}
}
return result;
}