feat: implement closures with upvalue support and statement/expression separation
Add closure objects that wrap functions with captured upvalues, enabling first-class closures that close over local variables from enclosing scopes. Introduce new bytecode instructions (CODE_CLOSURE, CODE_LOAD_UPVALUE, CODE_STORE_UPVALUE, CODE_CLOSE_UPVALUE, CODE_RETURN) and a CompilerUpvalue tracking system with a MAX_UPVALUES limit of 256. Refactor the grammar to strictly separate statements from expressions, fixing a bug where block expressions incorrectly popped locals while temporaries remained on the stack. Rename internal functions (wrenCallFunction, wrenDebugDumpInstruction, wrenDebugDumpStack) and add Upvalue allocation, closure creation, and debug dump support for the new instructions.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
var f = null
|
||||
|
||||
fn(param) {
|
||||
f = fn {
|
||||
io.write(param)
|
||||
}
|
||||
}.call("param")
|
||||
|
||||
f.call // expect: param
|
||||
Reference in New Issue
Block a user