Skip to main content

Phase 5. Closures and higher-order functions

FieldValue
MEPMEP-45 §Phases · Phase 5
StatusNOT 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

#ScopeStatusCommitPR
5.0Closure-convert pass: transpiler3/c/lower/closure.go rewrites every closure into explicit (code, env_struct *) fat pointerNOT STARTED
5.1Free function as closure: env == NULL shim auto-generated per arityNOT STARTED
5.2Method as closure: env == self shim auto-generated per methodNOT STARTED
5.3Closures escaping return: env heap-allocated and GC-rooted; stack-keep escape-analysis deferred to v2NOT STARTED

Decisions made

Fill in along the way.

Deferred work

Escape analysis for stack-allocated env: v2.

Closeout notes

Fill in after gate green.