feat: add pattern variable binding to C backend

Implements full pattern matching with variable binding for the C backend:

- Extract variable bindings from patterns (Var, Constructor, Tuple, Record)
- Infer C types for bound variables using variant field type tracking
- Handle recursive ADTs with pointer fields and heap allocation
- Dereference pointer bindings automatically for value semantics

Key implementation details:
- variant_to_type: Maps variant names to parent type for tag generation
- variant_field_types: Maps (type, variant) to field types for inference
- Recursive type fields use Type* pointers with malloc/memcpy
- Pattern bindings dereference pointers to maintain value semantics

Examples that now work:
- match opt { Some(x) => x, None => 0 }
- match tree { Leaf(n) => n, Node(l, r) => sum(l) + sum(r) }

Updates documentation to reflect C backend progress.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-14 04:23:44 -05:00
parent 6ec1f3bdbb
commit d284ee58a8
3 changed files with 316 additions and 22 deletions

View File

@@ -221,7 +221,9 @@
| Task | Priority | Effort | Status |
|------|----------|--------|--------|
| C backend (basic) | P1 | — | ✅ Complete (functions, Console.print) |
| Extend C backend (closures, lists) | P1 | 2 weeks | ❌ Missing |
| Extend C backend (closures) | P1 | — | ✅ Complete |
| Extend C backend (pattern matching) | P1 | — | ✅ Complete |
| Extend C backend (lists) | P1 | 1 week | ❌ Missing |
| JS backend | P2 | 4 weeks | ❌ Missing |
| WASM backend | P3 | 4 weeks | ❌ Missing |