visitReturnStmt method

  1. @override
void visitReturnStmt(
  1. ReturnStmt stmt
)

Visitor method for executing a ReturnStmt. Evaluates the optional return value and throws a ReturnValue exception to unwind the stack to the function call site.

Implementation

@override
void visitReturnStmt(ReturnStmt stmt) {
  Object? value;
  if (stmt.value != null) {
    value = evaluate(stmt.value!); // Evaluate the return value expression
  }
  // Throw the special ReturnValue exception to unwind the stack to the function call boundary
  throw ReturnValue(value);
}