executeBundle method
dynamic
executeBundle(})
Execute an AstBundle with full import resolution.
Unlike execute, this method supports cross-module imports by creating an AstModuleLoader that resolves imports from the bundle's module map.
The entry point module is determined by:
- The
entryPointparameter (if provided) - The bundle's AstBundle.entryPointUri
Example
final runner = D4rtRunner();
// register bridges...
final bundle = AstBundle.fromFile('app.d4rtbundle');
final result = runner.executeBundle(bundle);
Implementation
dynamic executeBundle(
AstBundle bundle, {
String? entryPoint,
String name = 'main',
List<Object?>? positionalArgs,
Map<String, Object?>? namedArgs,
}) {
// Determine entry point URI
final entryUri = entryPoint ?? bundle.entryPointUri;
final entryAst = bundle.modules[entryUri];
if (entryAst == null) {
throw ArgumentD4rtException(
'Entry point "$entryUri" not found in bundle. '
'Available: ${bundle.modules.keys.join(", ")}',
);
}
// Initialize environment
InterpretedFunction.clearParentMap();
final executionEnvironment = _initEnvironment();
// Create AstModuleLoader for import resolution
final moduleLoader = AstModuleLoader(
modules: bundle.modules,
globalEnvironment: executionEnvironment,
runner: this,
);
moduleLoader.currentLibrary = Uri.parse(entryUri);
Logger.debug(
'[D4rtRunner.executeBundle] Entry point: $entryUri '
'(${bundle.modules.length} modules in bundle)',
);
// Execute with full module context
return _executeInEnvironment(
compilationUnit: entryAst,
executionEnvironment: executionEnvironment,
moduleContext: moduleLoader,
name: name,
positionalArgs: positionalArgs,
namedArgs: namedArgs,
);
}