d4rt library
D4rt - A powerful Dart code interpreter and runtime environment.
D4rt provides a complete Dart interpreter that can execute Dart code at runtime, with support for bridging between interpreted and native Dart code, async/await, classes, inheritance, enums, and more.
Key Features:
- Full Dart syntax support including classes, methods, functions
- Async/await execution with proper state management
- Bridged types for seamless native-interpreted code integration
- Standard library implementation
- Module system with import/export support
- Extension methods and mixins
Basic Usage:
final interpreter = D4rt();
final result = await interpreter.execute('''
int add(int a, int b) => a + b;
void main() {
print(add(5, 3));
}
''');
Classes
- AsyncExecutionState
- Represents the state of an ongoing asynchronous function execution. This object tracks the progress and context needed for resumption.
- AsyncSuspensionRequest
- Represents a request to suspend execution and wait for a Future. This object is returned by visitor methods when an await is encountered.
- BoundBridgedSuper
- Represents 'super' bound to an instance when the direct superclass is bridged.
- BoundExtensionMethodCallable
- Represents an extension method bound to a target instance.
- BoundSuper
- BridgedClass
- Represents a natively defined class that is accessible to the interpreter.
-
BridgedEnumDefinition<
T extends Enum> - BridgedEnumMixinMethodCallable
- Callable for bridged mixin methods on enum values
-
BridgedInstance<
T extends Object> - Represents an instance of a bridged native class.
- BridgedMethodCallable
- BridgedMixinMethodCallable
- Represents a method call on a bridged mixin applied to an interpreted instance.
- BridgedStaticMethodCallable
- Represents a static method from a bridged class that can be passed as a value
- BridgedSuperMethodCallable
- Represents a method call on a bridged superclass object. Stores the specific native super object and the method adapter.
- Callable
- ClassInfo
- Information about a class declaration.
- D4rt
- The main D4rt interpreter class.
- DangerousPermission
- Dangerous permissions that should be granted with extreme caution.
- DeclarationInfo
- Represents information about a declaration in the executed code. This is the base class for all introspection results.
- DeclarationVisitor
- Visitor for the first pass: Declares class and mixin placeholders.
- EnumInfo
- Information about an enum declaration.
- Environment
- Represents the execution environment for interpreted code.
- ExtensionInfo
- Information about an extension declaration.
- FilesystemPermission
- Filesystem permissions control file and directory operations.
- FunctionInfo
- Information about a function declaration.
- InterpretedClass
- Represents a class definition at runtime.
- InterpretedEnum
- Represents an enum definition at runtime.
- InterpretedEnumValue
- Represents a specific value within an enum at runtime.
- InterpretedExtension
- InterpretedExtensionMethod
- InterpretedFunction
- InterpretedInstance
- Represents an instance of an InterpretedClass at runtime.
- InterpretedRecord
- Represents an interpreted record value.
- InterpreterVisitor
- Main visitor that walks the AST and interprets the code. Uses a two-pass approach (DeclarationVisitor first).
- IntrospectionBuilder
- Helper class to build introspection results from an environment.
- IntrospectionResult
- Result of introspection containing all declarations found in the executed code.
- IsolatePermission
- Isolate permissions control isolate creation and communication.
- LateVariable
- Represents a late variable that supports lazy initialization
- Logger
- NativeFunction
- NetworkPermission
- Network permissions control network operations.
- Permission
- Base class for all permissions in the d4rt security system.
- ProcessRunPermission
- Process permissions control process execution.
- RuntimeType
- Common interface for types defined at runtime (interpreted or bridged).
- RuntimeValue
- Common interface for values defined at runtime (interpreted or bridged instances).
- Stdlib
- TypeParameter
- Represents a generic type parameter like T, U, etc.
- VariableInfo
- Information about a variable declaration.
- YieldValue
- Represents a yield operation in a generator function
Enums
Extensions
- InterpreterVisitorExtension on InterpreterVisitor
-
IterableExtensions
on Iterable<
T> -
ListExtension
on List<
T> -
MapExtension
on Map<
K, V>
Typedefs
-
BridgedConstructorCallable
= Object? Function(InterpreterVisitor visitor, List<
Object?> positionalArgs, Map<String, Object?> namedArgs) - Calls a native constructor.
- BridgedInstanceGetterAdapter = Object? Function(InterpreterVisitor? visitor, Object target)
- Adapter for bridged instance getters. Takes interpreter context, the native target object. Returns the result of the native instance getter.
- BridgedInstanceSetterAdapter = void Function(InterpreterVisitor? visitor, Object target, Object? value)
- Adapter for bridged instance setters. Takes interpreter context, the native target object, the value to set.
-
BridgedMethodAdapter
= Object? Function(InterpreterVisitor visitor, Object target, List<
Object?> positionalArguments, Map<String, Object?> namedArguments) - BridgedStaticGetterAdapter = Object? Function(InterpreterVisitor visitor)
- Adapter for bridged static getters. Takes interpreter context. Returns the result of the native static getter.
-
BridgedStaticMethodAdapter
= Object? Function(InterpreterVisitor visitor, List<
Object?> positionalArguments, Map<String, Object?> namedArguments) - Adapter for bridged static methods. Takes interpreter context, positional args, named args. Returns the result of the native static method call.
- BridgedStaticSetterAdapter = void Function(InterpreterVisitor visitor, Object? value)
- Adapter for bridged static setters. Takes interpreter context, the value to set.
-
NativeFunctionImpl
= Object? Function(InterpreterVisitor visitor, List<
Object?> arguments, Map<String, Object?> namedArguments, List<RuntimeType> ? typeArguments)
Exceptions / Errors
- BreakException
- Internal exception used to unwind the stack during a 'break' statement.
- ContinueException
- Internal exception used to unwind the stack during a 'continue' statement.
- InternalInterpreterException
- Internal exception wrapper for user-thrown exceptions.
- LateInitializationError
- Exception thrown when accessing an uninitialized late variable
- PatternMatchException
- Exception specifically for pattern matching failures.
- ReturnException
- Internal exception used to unwind the stack during a 'return' statement.
- RuntimeError
- Custom exception for runtime errors during interpretation.
- SourceCodeException
- Exception thrown when there's an issue with the source code itself, like parsing errors or missing files.