Skip to content

feat(codegen): complete .twasm front-end for the example corpus (2/6 → 6/6)#167

Merged
hyperpolymath merged 3 commits into
mainfrom
feat/twasm-frontend-corpus-2to6
Jun 16, 2026
Merged

feat(codegen): complete .twasm front-end for the example corpus (2/6 → 6/6)#167
hyperpolymath merged 3 commits into
mainfrom
feat/twasm-frontend-corpus-2to6

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Extends the v0 .twasm front-end + codegen so all six canonical examples parse, emit valid wasm, and round-trip through the verifier — the #130 round-trip soundness corpus over real .twasm (not just paint-type/example-01). Takes the corpus from 2/6 → 6/6.

Parser

  • ptr<T> / unique<T> / ref<T> field pointers → 03
  • optional/unnamed fn params + &mut/&/own region<T> borrow params → 05, 06
  • general annotation-clause skip (cost_bound { … }, etc.) → 05
  • import region X from "…" { … }/; with quoted module source → 06, 02
  • invariant { … } region constraint blocks → 02

Codegen

  • typed result stubs: Op::{I64Const,F32Const,F64Const} + instruction mappings, so representative bodies type-check against f32/i64/f64 result types → 03 (verify)

Tests

  • parsed_example_corpus_round_trips round-trips all six examples (build → emit → verify_from_module + access-sites). 31/31 codegen tests pass.

Honest scope

Still v0: type-correct representative bodies (no region.get/set/alloc lowering yet), and the six canonical examples (not arbitrary .twasm). Full body-lowering + general schemas are the next climb; this PR locks in + CI-enforces the front-end breadth at the v0 level.

🤖 Generated with Claude Code

hyperpolymath and others added 3 commits June 16, 2026 02:48
…-> 6/6)

Extends the v0 front-end + codegen so all six canonical examples parse, emit
valid wasm, and round-trip through the verifier (Phase 1 / #130):

- parser: ptr<T>/unique<T>/ref<T> field pointers (03); optional/unnamed fn
  params + &mut/&/own region<T> borrow params (05, 06); general annotation-clause
  skip (cost_bound { ... } etc., 05); import region X from "..." {...}|;
  with quoted module source (06, 02); invariant { ... } region constraint
  blocks (02).
- codegen: typed result stubs — Op::{I64Const,F32Const,F64Const} + mappings, so
  representative bodies type-check against f32/i64/f64 result types (03).
- tests: parsed_example_corpus_round_trips round-trips all six examples
  (the #130 soundness gate over real .twasm, not just paint-type/example-01).

Still v0 (type-correct representative bodies, not full region.get/set lowering;
the six canonical examples, not arbitrary .twasm). 31/31 codegen tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The error path in expect() sliced self.src[pos..pos+20], panicking with an
out-of-bounds (or non-UTF-8-boundary) slice when a parse error occurred near
end-of-input. peek_word() had the same self.src[start..] hazard. A malformed
.twasm must be a clean Err diagnostic, never a crash.

- expect/peek_word now use self.src.get(..) and a length-clamped error window.
- regression test parser_never_panics_on_malformed_input feeds char-boundary
  truncations of all six examples + adversarial fragments (unbalanced
  delimiters, UTF-8, partial type forms); previously 6 inputs panicked, now 0.

32/32 codegen tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@hyperpolymath
hyperpolymath merged commit 3fa11bf into main Jun 16, 2026
12 of 21 checks passed
@hyperpolymath
hyperpolymath deleted the feat/twasm-frontend-corpus-2to6 branch June 16, 2026 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant