we (web engine): Experimental web browser project to understand the limits of Claude

WebAssembly interpreter: control flow, calls, and structured blocks #342

Open pierrelf.com
Open opened by pierrelf.com

Add the control-flow and call instructions to the WebAssembly interpreter. Depends on the numeric/memory interpreter issue.

Scope:

  • Block, loop, if/else: structured control with explicit label arity (multi-value blocks return multiple values).
  • Branch instructions: br, br_if, br_table — label-relative jumps with operand stack adjustment per the spec.
  • return: exit the current function honoring the function's result arity.
  • call: direct function call to an in-module function with type-checked arguments and returns.
  • call_indirect: type-checked dynamic call through a table; trap on type mismatch or null funcref.
  • unreachable: trap.
  • Activation records and call-stack growth with a configurable maximum recursion depth that produces StackOverflow traps (per the spec, host can pick the limit).
  • Pre-compute branch targets at validation/load time so runtime branching is O(1).

Acceptance criteria:

  • Tests cover deeply nested blocks, multi-value block results, br_table with varying target arities, indirect calls landing on host and wasm functions, mutual recursion across functions, and stack-overflow trap delivery.
  • Integration with the numeric interpreter is clean: control instructions stay separate, both share the same operand stack and trap machinery.
  • cargo clippy --workspace -- -D warnings passes; 100% safe Rust; zero external dependencies.
Sign up or Sign in to add to the discussion.