You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Second S4 slice: env + argv counts via WASI preview1 sizes_get
imports. Also a small principled refactor: ctx.wasi_func_indices
records each WASI import's func idx, so multi-import-on-use
indexing is no longer fragile-hardcoded (S4a's `clock_func_idx = 1`
becomes a `List.assoc` lookup; future WASI builtins just append).
- `lib/wasi_runtime.ml`: `create_environ_sizes_get_import` +
`create_args_sizes_get_import` + shared
`gen_count_via_sizes_get` emitter (alloc 8B scratch, call
sizes_get(count_ptr, bufsize_ptr), drop errno, return *count).
- `lib/codegen.ml`:
• `context.wasi_func_indices : (string * int) list` (additive
field; default []).
• Module-assembly refactored: canonical optional WASI imports
list (clock_time_get, environ_sizes_get, args_sizes_get) added
on-demand via the existing Effect_sites pre-scan, indices
assigned by position (fd_write=0; others 1..). The
`clock_now_ms` builtin now looks up its idx by name (no more
hardcoded 1) — fully backward-compatible.
• `env_count(u: Unit) -> Int / Time` and `arg_count(u: Unit) -> Int
/ Time` builtin special-cases. Unit arg = the zero-param-fn
collapse wart workaround (per existing memory).
- `lib/typecheck.ml` + `lib/resolve.ml`: register the two builtins.
Tests:
- `tests/codegen/env_count.{affine,mjs}` — host stubs
environ_sizes_get with count 7; asserts 7.
- `tests/codegen/arg_count.{affine,mjs}` — same shape, count 3.
- `tests/codegen/wasi_combo.{affine,mjs}` — **the critical
regression**: a single unit using ALL three optional WASI imports
(clock + env + args). Each lookup in `ctx.wasi_func_indices` must
return the right idx; stubbed values chosen so the sum (100+20+3
= 123) uniquely identifies any indexing mistake. PASSED.
- `clock_now_ms` (S4a) still passes through the refactor — proves
the indexing change is lossless.
String accessors (env_at/arg_at) need byte-level wasm IR ops
(I32Load8U/I32Store8 absent in lib/wasm.ml today) — tracked
follow-up as a small wasm-IR extension PR before/with S5.
Gate: `dune test --force` 295/295; full
`tools/run_codegen_wasm_tests.sh` PASSED incl. all 4 new tests
(print, #199 closure ABI, #234 effect-table, #225 CPS, S4a clock,
S4b env/arg/combo, all green). Zero regression.
Refs #180 — S4 done (counts); next: byte-ops slice for strings,
then S5 wasi:filesystem (unblocks INT-06), then S6 flip default +
WIT export lifting. Not Closes.
0 commit comments