Commit Graph

3 Commits

Author SHA1 Message Date
Bob Nystrom
c107d26c93 feat: generate default constructors at compile time and reorder interpret loop for branch alignment
Add a `defaultConstructor` function in the compiler that emits bytecode for a constructor returning the receiver, invoked during class compilation. Reorder `CODE_CLASS`, `CODE_SUBCLASS`, and method opcodes to the end of the interpret loop's jump table and switch cases, moving `CODE_CALL_0` through `CODE_CALL_16` earlier to compensate for branch alignment issues caused by removing code from `CODE_CLASS` and `CODE_CALL` handlers.
2013-12-12 15:34:16 +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
Bob Nystrom
88f7444f0c feat: extract bytecode dumpInstruction into new wren_debug module
Move the dumpInstruction function and its associated opcode printing logic from wren_vm.c into a dedicated wren_debug.c source file with a corresponding wren_debug.h header. Add the new source file to the Xcode project build configuration.
2013-11-30 00:17:33 +00:00