execute method

dynamic execute({
  1. bool createStackFrame = true,
  2. bool propagateValue = true,
  3. HTContext? context,
  4. HTStackFrame? stackFrame,
  5. 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();
      }
    }
  }
}