D4rtRunner class

D4rtRunner - Execute pre-parsed AST trees without analyzer dependency.

This class provides the core interpreter functionality for executing SAstNode trees. Unlike the full D4rt class in tom_d4rt_exec, D4rtRunner works exclusively with pre-parsed AST and does not require the analyzer.

Use Cases

  • Execute AST loaded from JSON files
  • Execute AST from precompiled scripts
  • Embedded interpreter without heavy analyzer dependency

Example:

// From JSON string
final runner = D4rtRunner();
final ast = runner.parseJson(jsonString);
final result = runner.execute(ast: ast);

// From JSON file
final result = await runner.executeFromJsonFile('script.ast.json');

For source code parsing and execution, use the D4rt class from tom_d4rt_exec which provides full integration with tom_ast_generator.

Constructors

D4rtRunner()
Creates a D4rtRunner instance for executing pre-parsed AST.

Properties

bridgedClasses List<Map<String, LibraryClass>>
Registered bridged class definitions keyed by library URI.
no setter
bridgedEnumDefinitions List<Map<String, LibraryEnum>>
Registered bridged enum definitions keyed by library URI.
no setter
bridgedExtensions List<Map<String, LibraryExtension>>
Registered bridged extension definitions keyed by library URI.
no setter
bridgedLibraryUris Set<String>
The set of library URIs that have at least one registered bridge (class, enum, extension, function, variable, getter, or setter).
no setter
bridgesFinalized bool
Whether finalizeBridges has been called on this runner. Step 6.
no setter
classAliases List<({String aliasName, String library, String targetName})>
Registered class aliases keyed by library URI.
no setter
functionTypedefs List<({String library, String name})>
Registered function typedefs.
no setter
hashCode int
The hash code for this object.
no setterinherited
libraryFunctions List<Map<String, LibraryFunction>>
Registered library functions keyed by library URI.
no setter
libraryGetters List<Map<String, LibraryGetter>>
Registered library getters keyed by library URI.
no setter
libraryReExports Map<String, List<({Set<String>? hide, Set<String>? show, String uri})>>
GEN-107: Registered library re-exports keyed by source library URI.
no setter
librarySetters List<Map<String, LibrarySetter>>
Registered library setters keyed by library URI.
no setter
libraryVariables List<Map<String, LibraryVariable>>
Registered library variables keyed by library URI.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
visitor InterpreterVisitor?
Gets the current interpreter visitor instance.
no setter

Methods

checkPermission(dynamic operation) bool
Checks if any permission allows the given operation.
eval(String expression) → dynamic
Evaluate an expression in the current context.
execute({required SCompilationUnit ast, String name = 'main', List<Object?>? positionalArgs, Map<String, Object?>? namedArgs}) → dynamic
Execute an AST.
executeBundle(AstBundle bundle, {String? entryPoint, String name = 'main', List<Object?>? positionalArgs, Map<String, Object?>? namedArgs}) → dynamic
Execute an AstBundle with full import resolution.
executeBundleAs<T>(AstBundle bundle, {String? entryPoint, String name = 'main', List<Object?>? positionalArgs, Map<String, Object?>? namedArgs}) → T
Execute bundle and unwrap the result to type T via D4.unwrapAs.
executeBundleAsAsync<T>(AstBundle bundle, {String? entryPoint, String name = 'main', List<Object?>? positionalArgs, Map<String, Object?>? namedArgs}) Future<T>
Async variant of executeBundleAs — awaits the result if it is a Future before unwrapping to T.
executeFromJson({required String jsonString, String name = 'main', List<Object?>? positionalArgs, Map<String, Object?>? namedArgs}) → dynamic
Execute from a JSON string.
executeFromJsonFile({required String path, String name = 'main', List<Object?>? positionalArgs, Map<String, Object?>? namedArgs}) Future
Execute from a JSON file.
finalizeBridges() → void
Runs every extension callback registered via registerExtensions in registration order, then marks the runner as finalized.
grant(Permission permission) → void
Grants a permission.
hasPermission(Permission permission) bool
Checks if a specific permission is granted.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parseJson(String jsonString) SCompilationUnit
Parses an AST from a JSON string.
parseJsonFile(String path) Future<SCompilationUnit>
Parses an AST from a JSON file.
registerBridgedClass(BridgedClass definition, String library, {String? sourceUri}) → void
Registers a bridged class definition.
registerBridgedEnum(BridgedEnumDefinition<Enum> definition, String library, {String? sourceUri}) → void
Registers a bridged enum definition.
registerBridgedExtension(BridgedExtensionDefinition definition, String library, {String? sourceUri}) → void
Registers a bridged extension.
registerClassAlias(String aliasName, String targetName, String library) → void
GEN-074: Registers a class alias (type alias).
registerExtensions(String packageName, void body()) → void
Registers a body callback that wires additional bridge state (e.g. registerRelaxers(), registerD4rtRuntimeExtensions(), registerD4rtInterfaceProxyOverrides()) after the main registerBridgedClass/registerBridgedEnum/etc. registrations for packageName have happened.
registerFunctionTypedef(String name, String library) → void
Registers a function typedef so it can be resolved as a type.
registerGenericConstructor(String className, String constructorName, GenericConstructorFactory factory) → void
Registers a generic-constructor factory for className.constructorName.
registerGlobalGetter(String name, Object? getter(), String library, {String? sourceUri}) → void
Registers a global getter.
registerGlobalSetter(String name, void setter(Object?), String library, {String? sourceUri}) → void
Registers a global setter.
registerGlobalVariable(String name, Object? value, String library, {String? sourceUri}) → void
Registers a global variable.
registerInterfaceProxy(String bridgedTypeName, InterfaceProxyFactory factory) → void
Registers an interface-proxy factory for bridgedTypeName.
registerLibraryReExport(String sourceUri, String targetUri, {Set<String>? show, Set<String>? hide}) → void
GEN-107: Registers a re-export from one library to another.
registerRelaxerFactory(String baseTypeName, GenericTypeWrapperFactory factory) → void
Registers a relaxer (generic-type-wrapper) factory for baseTypeName.
registerTopLevelFunction(String? name, NativeFunctionImpl function, String library, {String? sourceUri, String? signature}) → void
Registers a top-level native function.
registertopLevelFunction(String? name, NativeFunctionImpl function, String library, {String? sourceUri, String? signature}) → void
Lower-case alias for registerTopLevelFunction.
resetScriptDeclarations() → void
§U28 / TODO #14 — Evict script-declared entries from the current global environment so a follower executeBundle call starts with the same name-set the first build saw.
revoke(Permission permission) → void
Revokes a permission.
setDebug(bool enabled) → void
Enables or disables debug logging.
toString() String
A string representation of this object.
inherited
warmup() → void
OPEN B.11 / U25 — Pre-builds the bridge + stdlib infrastructure so the first real execute/executeBundle call does not cold-start mid-test.

Operators

operator ==(Object other) bool
The equality operator.
inherited