Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@ The Dart implementation of the framework-independent part of the Craft engine (`
- **Binary format**: `lib/src/rfw/binary.dart`, forked from RFW 2.0.0 like the text format. It writes the Craft signatures, version header and declaration flags, decodes RFW blobs as version 0, skips extension values, and reports every decoding error as a `BlobFormatException` with a `BlobErrorKind` and a byte offset.
- **Name resolution**: `lib/src/name_resolution.dart`. `NameResolver` applies the `craft_libraries_and_names` rules over a live map of registered libraries (template libraries and `PrimitiveLibrary` implementations provided by framework adapters) and caches results until `invalidate`.
- **Functions**: `lib/src/functions.dart` defines a function (`LocalFunction`: parameters with a `FunctionArgType` and an implementation), the `FunctionRegistry` of standard and host functions, which checks host keys, and the value helpers the functions share (equality, exact number comparison, number display). `lib/src/standard_functions.dart` holds the standard functions. `lib/src/evaluator.dart` evaluates the values that need no runtime (literals, lists, maps, `absent`, args/data/state references, function calls), tells function calls from widget calls with `NameResolver`, and reports every failure as an `EvaluationException` with an `EvaluationErrorKind`.
- **Template registry**: `lib/src/template_registry.dart`. `TemplateRegistry` holds the registered template and primitive libraries (primitive libraries as a copy of their names and metadata) and the host functions, owns the `NameResolver` over them, builds each library's function table (standard functions, the introspection functions answering for that library, host functions), reads symbol references through the evaluator's `SymbolReader`, and computes the availability of libraries and components as a fixed point. Every registration drops the derived results. `lib/src/dependencies.dart` holds the declared dependencies (`LibraryDependencies`, `Requirement`) and the availability reports.
- **Runtime**: `lib/src/expansion.dart` defines the expansion: primitive, error and builder nodes, the handler nodes (`EventValue`, `SetStateValue`, `HandlerCallValue`, `HostHandler`), stateful instances, and the canonical JSON form. `lib/src/runtime.dart` holds `CraftRuntime`, which expands a root over a `TemplateRegistry`, keeps the state of its instances (reset when the registry's generation of the declaring library changes, so also when the same object is registered again; `TemplateRegistry.generation` counts each name's registrations and removals), expands builder outputs, fires handlers and notifies listeners. A failure records the scope and the source range of the innermost node it passes through (each evaluation, and a primitive call while its arguments evaluate), which become the `template` and `source` of the `ErrorNode`. Evaluation happens in two phases: a node evaluates in a scope to a value or to a widget call not yet expanded (template arguments are evaluated on first read and kept), and placing that value at a path expands its widget calls, catching failures at the innermost widget. It calls functions through `checkCallArguments` and `invokeFunction`, shared with `lib/src/evaluator.dart`. The whole tree is expanded again after every change; there is no fine-grained invalidation.
- **Template registry**: `lib/src/template_registry.dart`. `TemplateRegistry` holds the registered template and primitive libraries (primitive libraries as a copy of their names and metadata) and the host functions, owns the `NameResolver` over them, builds each library's function table (standard functions, the introspection functions answering for that library, host functions), reads symbol references through the evaluator's `SymbolReader`, and computes the availability of libraries and components as a fixed point. Every registration drops the derived results and then calls the registry's listeners. `lib/src/dependencies.dart` holds the declared dependencies (`LibraryDependencies`, `Requirement`) and the availability reports.
- **Runtime**: `lib/src/expansion.dart` defines the expansion: primitive, error and builder nodes, the handler nodes (`EventValue`, `SetStateValue`, `HandlerCallValue`, `HostHandler`), stateful instances, and the canonical JSON form. `lib/src/runtime.dart` holds `CraftRuntime`, which expands a root over a `TemplateRegistry`, keeps the state of its instances (reset when the registry's generation of the declaring library changes, so also when the same object is registered again; `TemplateRegistry.generation` counts each name's registrations and removals; `refresh` drops such instances at once, the next expansion otherwise), expands builder outputs, fires handlers and notifies listeners. A failure records the scope and the source range of the innermost node it passes through (each evaluation, and a primitive call while its arguments evaluate), which become the `template` and `source` of the `ErrorNode`. Evaluation happens in two phases: a node evaluates in a scope to a value or to a widget call not yet expanded (template arguments are evaluated on first read and kept), and placing that value at a path expands its widget calls, catching failures at the innermost widget. It calls functions through `checkCallArguments` and `invokeFunction`, shared with `lib/src/evaluator.dart`. The whole tree is expanded again after every change; there is no fine-grained invalidation.
- **A2UI integration**: the framework-independent part of `craft_a2ui_integration` (requirements 1 to 6; requirement 7, rendering, is implemented for Flutter by `a2ui_craft_renderer_flutter`). `lib/src/a2ui_catalog.dart` derives each offered component's `TemplateInterface` (its properties with their `ArgKind`, and whether it is checkable) by walking its declaration's root with the kind of each position, following template calls with a per-declaration cache that skips results computed through a call back into a declaration under analysis, and writes the A2UI v1.0 component schema (`templateCatalogSchemas`). `lib/src/a2ui_props.dart` maps resolved props, described with `A2uiProp` (each holding the renderer's own object, which this package never looks into), to `TemplateArgs`: the arguments with their host handlers and host widgets, and the `A2uiEffect`s of each event that firing gives. `TemplateRegistry.primitiveMeta` gives the analysis the metadata of a primitive. The runtime carries host widgets (`HostWidget`, placed as `HostWidgetNode`s) for the renderer's child nodes.
- **Media context**: `lib/src/media_context.dart` defines `MediaContext` (made from its properties or with `MediaContext.fromSize`, whose breakpoints are in `WidthClass.of` and `HeightClass.of`), `SurfaceOrientation` and `HostPlatform`, the media map (`toMap`), `readMedia`, which both the evaluator and the runtime use for media references, and `mediaFunctions` (`atLeast`), which `TemplateRegistry.functionsFor` adds to every function table next to the standard and introspection functions. `Evaluator.evaluate` and `TemplateRegistry.evaluate` take a media context; `CraftRuntime.media` holds the runtime's; its setter notifies only when the new one is not equal, and `setMedia(notify: false)` replaces it without notifying, for a host that calls `refresh` later.
- **Limits**: `lib/src/limits.dart` defines `CraftLimits` (the six limits, their defaults and JSON form), `CraftLimitException`, `checkLibraryLimits` (the declaration measures, which `TemplateRegistry.setTemplateLibrary` applies) and `limitedValue` (the conversion of host values and function results with the depth and string checks, which fails at a `BeyondLimits` marker; `TemplateArgs.from` puts one in place of a prop value beyond the limits). The parser (`lib/src/rfw/text.dart`) counts the depth and nodes of the library it builds as it reads, keeping each `let` binding's depth and node count to add them at each use, and reports a `ParserException` with a `limit`; the decoder (`lib/src/rfw/binary.dart`) counts tagged values and reports `BlobErrorKind.limitExceeded`. The evaluator and the runtime count the depth of the node being evaluated; the runtime's pass also counts steps and nodes, throws a private stop exception past either budget (never cached by a template argument), and gives back the instances it had before the pass.
- **Canonical JSON form**: `lib/src/canonical_json.dart`, used by the conformance harness.
- **Public libraries**: `lib/a2ui_craft.dart` exports everything a host uses. Of the library model it exports a library's structure (`RemoteWidgetLibrary`, `WidgetLibrary`, `Import`, `WidgetDeclaration`, `BlobNode`) and every other model type that its API names (`LibraryName`, `FullyQualifiedWidgetName`, `Missing` and `missing`, `DynamicMap`, `DynamicList`, `SourceLocation`, `SourceRange`, `SymbolReference`); `test/public_api_test.dart` names each of them through that import alone. The other nodes of a declaration's body (`Switch`, `Loop`, `ConstructorCall`, references, handlers, builders) are in `lib/model.dart`, for tools and tests that inspect or build libraries. `checkCallArguments`, shared by the evaluator and the runtime, is not exported.
- **Conformance harness** (`dart-craft`): `test/conformance/conformance_harness.dart` loads each suite of `conformance/craft/`, runs every case with the handler of its `action` (handlers shared by several suites are in `parse_cases.dart`, `resolution_cases.dart` and `runtime_engine.dart`), fails a case with an unknown action or key, and writes an executed-case manifest when `A2UI_CONFORMANCE_MANIFEST_DIR` is set. `suite_registry.dart` names the test file of each suite.

## **Local Technical Decisions & Overrides**

- **Library model in its own library**: a host file usually imports `package:material_ui/material_ui.dart` too, whose `Switch` widget would clash with the model's `Switch` node; keeping the nodes out of the main library lets both be imported without `hide`.
- **Registry notifications without Flutter**: `TemplateRegistry.addListener` takes plain callbacks, as `CraftRuntime` does, so the package keeps no Flutter dependency; a listener that throws goes to `onListenerError`, by default to the zone's uncaught error handler (Flutter reports those), rather than out of the registration that already took effect; a runtime does not listen to its registry itself (it would need disposing), the adapter tells it with `refresh`.
- **Depth ceiling**: `CraftLimits` refuses a `maxDepth` above 1,000 (`CraftLimits.maxDepthCeiling`). At 2,000 a chain of templates overflowed the stack of a desktop VM; the default, 100, leaves a margin for smaller stacks.
- **Encoders are not limited**: `encodeLibraryBlob` and `encodeDataBlob` write what the host gives them, so a library or value that the host builds deeper than the stack allows overflows there; everything the parser, decoders and registry accept encodes.
- **Numbers on the web**: compiled with dart2js, every number is a JavaScript number (a double), and a whole one is also an `int`, so integers and doubles cannot be told apart and integers are exact only up to 2^53 in magnitude. There the standard functions follow the double rules of `craft_functions` wherever they differ from the integer rules: `add`, `subtract` and `multiply` give absent only for a result that is not finite, `round`, `floor` and `ceil` give absent outside the 64-bit range, `abs` never gives absent, a number displays as a double does, and comparisons compare the doubles, which is exact. The canonical JSON form gives every whole number the integer form, so the conformance cases that tell integers from doubles or need integers beyond 2^53 are skipped there (`test/conformance/js_skips.dart`). Compiled with dart2wasm, numbers behave as on the VM.
Expand Down
Loading
Loading