execute method

dynamic execute({
  1. bool retractStackFrame = true,
  2. HTContext? context,
  3. dynamic localValue,
})

Interpret a loaded module with the key of moduleName Starting from the instruction pointer of ip This function will return current expression value when encountered HTOpCode.endOfExec or HTOpCode.endOfFunc.

Changing library will create new stack frame for new register values. Such as currrent value, current symbol, current line & column, etc.

Implementation

dynamic execute({
  bool retractStackFrame = true,
  HTContext? context,
  dynamic localValue,
}) {
  final savedContext = getContext(
    filename: context?.filename != null,
    moduleName: context?.moduleName != null,
    namespace: context?.namespace != null,
    ip: context?.ip != null,
    line: context?.line != null,
    column: context?.column != null,
  );
  setContext(stackFrameStrategy: StackFrameStrategy.create, context: context);
  _localValue = localValue;
  final result = _execute();
  setContext(
      stackFrameStrategy: retractStackFrame
          ? StackFrameStrategy.retract
          : StackFrameStrategy.none,
      context: context != null ? savedContext : null);
  return result;
}