execute method

dynamic execute({
  1. required SCompilationUnit ast,
  2. String name = 'main',
  3. List<Object?>? positionalArgs,
  4. Map<String, Object?>? namedArgs,
})

Execute an AST.

ast The parsed SCompilationUnit to execute. name The function to call (default: 'main'). positionalArgs Positional arguments to pass to the function. namedArgs Named arguments to pass to the function.

Returns the result of the function call.

Implementation

dynamic execute({
  required SCompilationUnit ast,
  String name = 'main',
  List<Object?>? positionalArgs,
  Map<String, Object?>? namedArgs,
}) {
  // Initialize fresh environment
  InterpretedFunction.clearParentMap();
  final executionEnvironment = _initEnvironment();

  // Create module context with permission checking
  final moduleContext = NoOpModuleContext(
    globalEnvironment: executionEnvironment,
    permissionChecker: checkPermission,
  );

  // Execute
  return _executeInEnvironment(
    compilationUnit: ast,
    executionEnvironment: executionEnvironment,
    moduleContext: moduleContext,
    name: name,
    positionalArgs: positionalArgs,
    namedArgs: namedArgs,
  );
}