Repository navigation
v0.1.27
0.1.27
-
Wasm collections — compound subscript assignment (P3, part 9):
m[k] += v(and-=,*=,/=,~/=) and the same for list indicesa[i] += vnow compile to Wasm. Lowered by desugaringc[k] OP= vintoc[k] = c[k] OP v, so it reuses the existing get/set codegen and works for maps (int/Stringkeys) and lists acrossint/doublevalues. Matches the interpreter on bothwasm_runand Chrome (e.g. a frequency counter can now usem[w] += 1directly).
-
Wasm collections — map parameters & returns (P3, part 8):
- Functions can now accept and return whole
Maps across the host boundary. The runner marshals a DartMapinto the module's map layout (header + parallel key/value buffers, via the exported__alloc) forMapparameters, and decodes a returned map-header pointer back into a DartMap. Coversint/Stringkeys ×int/double/String/boolvalues, including round-tripping and returning a map built withm[k] = v. - The
apollovm_sigcustom section now encodes a map type as[7, <key tag>, <value tag>], so raw-byte modules self-describe their key/value types. Element read/write was factored into shared helpers used by both list and map marshalling.
- Functions can now accept and return whole
-
Wasm collections — map
.keys/.values+ iteration (P3, part 7):m.keysandm.valuesnow compile to Wasm: each materializes a fresh list by copying the map's parallel key (or value) buffer (which already has the list element layout), sofor (var k in m.keys)/for (var v in m.values)work via the existing list for-each. Matches the interpreter on bothwasm_runand Chrome.- The for-each loop-variable type resolver now derives the element type from the map (
m.keys→ key type,m.values→ value type) so the loop variable is correctly typed.
-
Wasm collections — maps with
Stringkeys (P3, part 6):Map<String, V>now compiles to Wasm (V=int/double/String/bool): literals,m[k]get,m[k] = vset,.length/.isEmpty/.isNotEmpty, and.containsKey(k). Matches the interpreter on bothwasm_runand Chrome.- String keys are stored as i32 pointers and compared by content via a synthesized
__streq(a, b)helper (length check + byte loop), so e.g.containsKey("app")correctly returnsfalsefor a map keyed by"apple", and multi-byte UTF-8 keys work.
-
Wasm collections — maps with
intkeys (P3, part 5):Map<int, V>now compiles to Wasm (V=int/double/String/bool). A map value is an i32 pointer to a 16-byte header[length][capacity][keysPtr][valuesPtr]with parallel key/value buffers; lookup/set is a linear scan withi64key equality. Matches the interpreter on bothwasm_runand Chrome.- Supported: map literals (incl. empty
{}),m[k]get,m[k] = vset (in-place update or append, growing both buffers when full),.length,.isEmpty/.isNotEmpty, and.containsKey(k). - Also adds Wasm list index assignment
a[i] = v(the subscript-assignment AST node now lowers to Wasm for both maps and lists). - Out of scope for this slice:
Stringkeys (need a string-equality helper),.keys/.values/iteration, map parameters/returns, and compound subscript assignment (m[k] += v) — notem[k] = m[k] + 1already works.
-
Dart subscript assignment —
m[k] = vanda[i] = v(frontend + interpreter):- The grammar now parses container-entry assignment targets (previously the assignment left-hand side was only a bare variable, so
m[k] = v/a[i] = vfailed with aSyntaxError). Compound operators (+=,-=,*=,/=,~/=) are supported, e.g.m["x"] += 1for building a frequency map. - New AST node
ASTExpressionVariableEntryAssignment; newASTValue.writeKey/writeIndexwrite into the underlyingMap/Listin place. AMapis always written by key (even a numeric one); aListby index. Round-trips through the code generators (parse → regenerate → re-parse). - Empty collection inference fix: an empty
{}literal (typedMap<dynamic,dynamic>) is now assignable to a typed map such asMap<String,int>—ASTTypeMap.acceptsTypetreats adynamickey/value component as a wildcard, matching how lists already ignore their element type for assignment (soMap<String,int> m = {};works, likeList<int> a = [];).
- The grammar now parses container-entry assignment targets (previously the assignment left-hand side was only a bare variable, so
-
Dart
Mapsupport — frontend + interpreter (read/query; prerequisite for Wasm maps):- Grammar fix:
Map<K,V>type annotations now parse.mapTyped()was missing the value-type parser (it accepted onlyMap<K,>and read the,token as the value type), so everyMap<int,int>declaration failed with aSyntaxError. Key/value types also acceptList<...>(e.g.Map<String,List<int>>). - Map literals now infer their key/value types from entries (mirroring list literals) instead of being hardcoded to
Map<dynamic,dynamic>, soMap<int,int> m = {1:10}assigns cleanly.ASTExpressionMapLiteral.resolveTypereturns theMaptype (it previously returned just the value type). - Map index by key:
m[k]now does a key lookup for anyMap(the access was incorrectly routed to positional/list indexing whenever the key was numeric, so int-keyed maps failed). - New core
Mapclass (CoreClassMap): getters.length/.isEmpty/.isNotEmpty/.keys/.valuesand methods.containsKey/.containsValue/.remove/.clear..keys/.valuesresolve toList<keyType>/List<valueType>so iterating them yields properly-typed elements. - Maps work as function parameters.
- Note: map subscript assignment (
m[k] = v) is a follow-up (the grammar's assignment target is still a bare variable). - Functions can now accept and return whole lists across the host boundary. The runner marshals a Dart
Listinto module memory (header + elements buffer, via the exported__alloc) forListparameters, and decodes a returned list-header pointer back into a DartList. Coversint/double/String/boolelement lists, including round-tripping (List<int> echo(List<int> a)) and building a result with.addbefore returning it. - The
apollovm_sigcustom section now carries list types as[6, <element tag>](was a single opaque tag), so modules loaded from raw bytes self-describe their list element types; the runner uses 64-bit element reads/writes viaBigIntso it works on both the Dart VM and dart2js (Chrome). - A
String/Listparameter now also forces an exported__alloc(previously only String params did), so list-only functions can be fed their arguments.
- Grammar fix:
-
Wasm collections —
String&boolelement lists (P3, part 3):List<String>andList<bool>now compile to Wasm: literals, index readsa[i],for (var e in a),.add, and the.first/.last/.isEmpty/.isNotEmpty/.lengthgetters all work (elements stored as i32 — a string pointer or a0/1boolean). Matches the interpreter on bothwasm_runand Chrome.- Maps remain a later slice.
-
Wasm collections — growable lists
.add+ getters (P3, part 2):- List values are now an indirect handle: a 12-byte header
[length:i32][capacity:i32][dataPtr:i32]pointing at a separately-allocated elements buffer. This makes.addaliasing-safe — growing reallocates the data buffer (doubling capacity,memory.copying existing elements) and updates the header in place, so existing references observe the new length/contents. list.add(x)now compiles to Wasm forint/doublelists (including starting from an empty[]literal), growing linear memory on demand.- New list getters compiled to Wasm:
.first,.last,.isEmpty,.isNotEmpty. bool-returning functions loaded from raw Wasm bytes now decode correctly: theapollovm_sigcustom section is emitted forboolreturns (not just String signatures), and the runner maps the i320/1back to a Dartbool.
- List values are now an indirect handle: a 12-byte header
-
Wasm collections — lists, read + iterate (P3, part 1):
int/doublelist literals compile to linear-memory blocks; index readsa[i], the.lengthgetter, andfor (var e in a)now compile to Wasm (matching the interpreter, on bothwasm_runand Chrome).- Lists currently stay internal (return scalars); list parameters/returns and maps are later slices.
-
Wasm generator — major feature expansion (
ApolloGeneratorWasm), moving toward full Dart parity:- Loops:
whileandforloops now compile to Wasm (block/loop/br_if/br), includingreturnfrom inside a loop. Added thebropcode helper and recursion into loop bodies when collecting function locals. - Function calls: local function invocation (calling other top-level functions, including recursion) via a function-index table threaded through the generator and a
Wasm.call. - Operators: integer modulo
%(i64.rem_s), logical&&/||(i32.and/i32.or), logical negation!(i32.eqz), and unary minus-(f64.neg/i64multiply-by--1). - Booleans:
boolliterals andbool-typed locals (represented as Wasmi32). - Bug fix: the
== 0fast-path (i64.eqz) was incorrectly applied to any operator with a literal-0right operand (e.g.x > 0compiled asx == 0). It is now restricted to theequalsoperator. - Short-circuit
&&/||: now compile to anif/elseso the right operand is only evaluated when needed. The AST interpreter was also made short-circuiting, so interpreted and compiled execution stay consistent (and match Dart). - Full Dart
%semantics: integer and double modulo now return the Dart-correct non-negative result in[0, |b|)for negative operands (sign-corrected via scratch locals); double%is computed asa - trunc(a / b) * b. - Fix: compound assignment (
+=,-=,*=, …) emitted its operation to a discarded buffer (missingout/context), producing broken code; now applied to the real output.
- Loops:
-
Tests: added Wasm coverage for every feature above plus a combined integration test (prime counting / sum-of-squares using loops + calls + logic + modulo), all executed against the real compiled-and-run Wasm module.
-
Wasm strings — String parameters +
memory.grow(P2, part 5, completes the strings milestone):- Functions taking
Stringparameters now work: the runner encodes the Dart string into module memory (via the exported__alloc, guided by theapollovm_sigparam tags) and passes the i32 pointer. EnablesString echo(String s),String greet(String name), etc. - The allocator (both the exported
__allocand the inline concat allocator) now grows linear memory on demand (memory.size/memory.grow), so large strings/concatenations no longer trap.
- Functions taking
-
Wasm strings — number→string interpolation (P2, part 4):
- Interpolation of
int/double("n=$n","${a + b}") now compiles to Wasm via host importsenv.int_to_str/env.double_to_str; the host formats the number (matching the interpreter; doubles viaASTTypeDouble.doubleToString) and writes it into module memory. - Adds a synthesized, exported
__allocbump-allocator function so host imports can allocate strings in the module's memory (reentrant host→module calls), plus value-returning host imports and i64↔BigInt marshalling on the web.
- Interpolation of
-
Wasm strings — String-returning functions (P2, part 3):
- Functions returning
Stringnow work: the value is an i32 pointer the runner decodes back into a DartString. - Modules are now self-describing: a custom
apollovm_sigsection records each public function's high-level return/parameter type tags, so the runner can marshal strings even for modules loaded from raw bytes. Emitted only when a public signature involves aString(pure-numeric modules stay byte-identical).
- Functions returning
-
Wasm strings — concatenation + bump allocator (P2, part 2):
- A mutable heap-pointer Global (
$hp) bump allocator; runtime string allocation via__alloc+memory.copy. - String
+, adjacent string literals, and$varinterpolation ofStringvariables now compile to Wasm (left-folded binary concatenation producing a fresh[len:i32][utf8]string). Validated onwasm_runand Chrome. - Note: bump-and-leak (no free yet); number→string interpolation and string returns are later slices.
- A mutable heap-pointer Global (
-
Wasm linear-memory foundation + strings (P2, part 1 —
printof string literals):- The generator now emits Import / Memory / Global / Data sections and offsets the function-index space past imported functions (a body-first two-pass build). Modules with no strings/imports remain byte-identical.
- String literals are interned into a static data segment as
[len:i32][utf8]; aStringvalue is ani32pointer into the exported linear memory. print(stringLiteral)lowers to a host importenv.print(i32). The runtime layer (WasmRuntime/WasmModule) now wires host imports at instantiation and exposes exported memory reads, on both the native (wasm_run) and browser runtimes; the runner decodes the pointer and routes toexternalPrintFunction.- New
wasm.dartmemory opcodes (i32/i64 load/store, load8_u/store8, memory.size/grow/copy/fill) and section-id helpers.
-
Test infrastructure — WebAssembly GC validation path:
- Established a browser (
dart test -p chrome) parity harness that runs generated Wasm on Chrome's own engine. The nativewasm_runbackend (wasmtime 14 / wasmi 0.31) does not support the WebAssembly GC proposal; Chrome (v119+) does. - Added a
wasm-gctest tag (dart_test.yaml) and a WasmGC capability spike; CI'swasm_run-based jobs exclude the tag (--exclude-tags wasm-gc) while the Chrome job runs it. This gates the planned dual-target (linear-memory + WasmGC) backend work.
- Established a browser (
-
Bug fixes:
- Loop
returnpropagation: areturninside afor,while, orfor-eachloop was ignored (the loop shadowedrunStatuswith a fresh instance and never broke on return). Returns now propagate and stop iteration correctly. ASTTypeequality:ASTTypeBool,ASTTypeString,ASTTypeObject,ASTTypeConstructorThis,ASTTypeVar,ASTTypeDynamic,ASTTypeNull, andASTTypeVoidmistakenly checkedother is ASTTypeInt, so equal instances never compared equal. Each now checks its own type.ASTTypeMap: building a map from a flat key/value list read from the (empty) target map instead of the input list, producing an empty map.- Java generator (
_escapeString): backslashes were not escaped, producing invalid Java string literals (e.g."a\b"instead of"a\\b"). ASTExpression.literalNumTypereturnedASTNumType.intfordoubleliterals.- Corrected the operator symbol shown in
ASTValueString/ASTValueNumcomparison/equality error messages.
- Loop
-
Tests:
- Increased line coverage from ~64.6% to ~70.9%.
- Added regression tests for all the fixes above and extensive unit/integration tests for
ASTValue,ASTType,ApolloVM, expressions, the core library, and the Wasm generator.