giles
1bb40415a8
VM upvalue support: closures capture variables from enclosing scopes
Compiler (compiler.sx):
- Function scopes marked is-function=true; let scopes share parent frame
- scope-resolve only creates upvalue captures at function boundaries
- Let scope locals use parent's slot numbering (same frame)
- OP_CLOSURE emits upvalue descriptors: (is_local, index) per capture
VM (sx_vm.ml):
- upvalue_cell type: shared mutable reference to captured value
- OP_UPVALUE_GET/SET: read/write from closure's upvalue array
- OP_CLOSURE: reads upvalue descriptors, creates cells from
enclosing frame's locals (is_local=1) or upvalues (is_local=0)
- vm_closure carries live env_ref (not snapshot)
- vm_call falls back to CEK for Lambda/Component/Island values
Verified: (let ((x 10)) (let ((add-x (fn (y) (+ x y)))) (add-x 5)))
Compiles to: CONST 10, LOC_SET #0, CLOSURE [UV_GET#0 LOC_GET#0 CPRIM+ RET]
with upvalue descriptor: is_local=1 index=0
VM executes → 15 ✓
Auto-compile: 6/117 functions compile (up from 3). Disabled until
compiler handles all features — fallback can't reconstruct closure
scope for variables like nav-state bound in caller's let*.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 20:13:17 +00:00
..
2026-03-15 02:29:37 +00:00
2026-03-19 12:06:24 +00:00
2026-03-19 16:53:01 +00:00
2026-03-11 11:15:48 +00:00
2026-03-11 11:15:48 +00:00
2026-03-14 10:11:48 +00:00
2026-03-12 23:54:38 +00:00
2026-03-08 00:00:23 +00:00
2026-03-12 22:27:52 +00:00
2026-03-11 09:42:04 +00:00
2026-03-18 17:22:51 +00:00
2026-03-19 14:56:55 +00:00
2026-03-02 19:57:27 +00:00
2026-03-11 16:38:47 +00:00
2026-03-19 16:53:01 +00:00
2026-03-07 19:02:29 +00:00
2026-03-19 20:13:17 +00:00
2026-03-12 22:00:12 +00:00
2026-03-15 18:05:00 +00:00
2026-03-13 12:03:58 +00:00
2026-03-02 00:50:57 +00:00
2026-03-06 01:45:29 +00:00
2026-03-18 17:22:51 +00:00
2026-03-08 00:00:23 +00:00
2026-03-15 18:05:00 +00:00
2026-03-05 22:17:26 +00:00
2026-03-11 11:15:48 +00:00
2026-03-11 04:53:34 +00:00
2026-03-11 11:15:48 +00:00
2026-03-14 10:11:48 +00:00