Phase 5. Closures and higher-order functions
| Field | Value |
|---|---|
| MEP | MEP-45 §Phases · Phase 5 |
| Status | NOT STARTED |
| Started | — |
| Landed | — |
| Tracking issue | — |
| Tracking PR | — |
Gate
Higher-order fixture suite (~30 cases: map, filter, fold, flatMap, currying, captures by value + reference, closures returned from functions) compiles + runs byte-equal vs vm3 on host triple.
Goal-alignment audit
To be written before sub-phase 5.0 starts. Higher-order combinators are how Mochi expresses data transformation; Phase 8's query DSL leans on this. Aligns.
Sub-phases
| # | Scope | Status | Commit | PR |
|---|---|---|---|---|
| 5.0 | Closure-convert pass: transpiler3/c/lower/closure.go rewrites every closure into explicit (code, env_struct *) fat pointer | NOT STARTED | — | — |
| 5.1 | Free function as closure: env == NULL shim auto-generated per arity | NOT STARTED | — | — |
| 5.2 | Method as closure: env == self shim auto-generated per method | NOT STARTED | — | — |
| 5.3 | Closures escaping return: env heap-allocated and GC-rooted; stack-keep escape-analysis deferred to v2 | NOT STARTED | — | — |
Decisions made
Fill in along the way.
Deferred work
Escape analysis for stack-allocated env: v2.
Closeout notes
Fill in after gate green.