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
feat(wasm): byte-level load/store IR + env_at/arg_at (ADR-015 S5)
Unblock INT-03 S5 (#180) by extending the wasm IR with the full
WebAssembly 1.0 §5.4.6 byte-level load/store family (opcodes
0x2C..0x35, 0x3A..0x3E) and shipping the env_at(i)/arg_at(i)
string accessors that were waiting on them.
IR + encoder (lib/wasm.ml + lib/wasm_encode.ml):
14 new instr constructors — I32Load8{S,U}, I32Load16{S,U},
I64Load8{S,U}, I64Load16{S,U}, I64Load32{S,U}, I32Store8,
I32Store16, I64Store{8,16,32}. Encoder pattern mirrors the
existing full-width family one-for-one.
env_at / arg_at lowering (lib/typecheck.ml + lib/codegen.ml +
lib/wasi_runtime.ml):
Bind Int -> String / { Time }; lower via on-demand
`wasi_snapshot_preview1.{environ,args}_get` imports paired with
the existing `_sizes_get` import. Emit a 7-phase sequence:
sizes_get -> alloc ptrvec+bytebuf -> _get -> resolve src ptr
via ptrvec[n] -> null-terminator scan (I32Load8U) -> alloc
length-prefixed AS string -> byte-copy (I32Load8U/I32Store8).
Codegen helper takes 11 pre-allocated locals; each call site
scopes its own to keep slot reuse clean.
Import-table dedup (lib/codegen.ml):
`env_count` and `env_at` both require `environ_sizes_get`
(ditto arg_count/arg_at). The optional_wasi table now lists
every (builtin, wasi_import) pair and the assembly pass dedupes
by wasi import name, keeping first occurrence — preserves the
canonical-order indexing the existing combo-regression hardened.
Tests (tests/codegen/{env_at,arg_at,env_count_and_at}.{affine,mjs}):
Smoke for env_at(0) length, arg_at(1) length (exercises the
n*4 ptrvec offset, not just index 0), and a dedup regression
that drives a unit using BOTH env_count and env_at through one
shared environ_sizes_get import.
Closes the "byte-level wasm IR" blocker called out in
docs/ECOSYSTEM.adoc, docs/TECH-DEBT.adoc, and the codegen/
typecheck/wasi_runtime comments (all updated).
0 commit comments