Commit Graph

2 Commits

Author SHA1 Message Date
Bob Nystrom
8c13258ef6 feat: promote Fiber from raw struct to heap-allocated ObjFiber with GC support
Refactor the VM's fiber representation from a stack-allocated `Fiber` struct embedded in `WrenVM` to a full `ObjFiber` object managed by the garbage collector. This includes adding the `OBJ_FIBER` object type enum, a `wrenNewFiber` allocation function, a `markFiber` traversal routine for GC marking, and updating all internal APIs (`DEF_FIBER_NATIVE`, `wrenDebugDumpStack`) to use `ObjFiber*` instead of `Fiber*`. The `Fiber` struct definition and its associated `CallFrame` type are moved from `wren_vm.h` into `wren_value.h`, and the `STACK_SIZE`/`MAX_CALL_FRAMES` constants are relocated accordingly. Additionally, the `vm->fiber` singleton pointer is removed, the `vm->unsupported` sentinel value is eliminated (replaced by returning `NULL_VAL` for invalid numeric operands), and the `wrenInterpret` function is temporarily removed. The `wrenNewClass` function's metaclass pinning order is also corrected to prevent premature GC collection.
2013-12-22 22:31:33 +00:00
Bob Nystrom
5b05c477c6 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.
2013-12-04 15:43:50 +00:00