Commit Graph

6 Commits

Author SHA1 Message Date
Bob Nystrom
78f6e3b96d perf: inline wrenObjectToValue and switch Xcode project to C99 for speed bump 2013-12-14 19:34:49 +00:00
Bob Nystrom
fc3ebb924c refactor: replace raw #ifdef NAN_TAGGING with WREN_NAN_TAGGING flag and add WREN_COMPUTED_GOTO, WREN_DEBUG_GC_STRESS, WREN_TRACE_MEMORY configurable defines
Convert all conditional compilation guards from bare `#ifdef NAN_TAGGING` to `#if WREN_NAN_TAGGING` across wren_common.h, wren_value.c, wren_value.h, and wren_vm.c. Introduce new `#ifndef`-based defaults for WREN_NAN_TAGGING, WREN_COMPUTED_GOTO, WREN_DEBUG_GC_STRESS, and WREN_TRACE_MEMORY in wren_common.h, replacing the old TODO comments and commented-out debug flags. Update preprocessor indentation style for consistency.
2013-12-14 19:06:54 +00:00
Bob Nystrom
d8c31a4391 feat: add wrenBindMethod to patch field indices and superclass dispatch in inherited methods
When a class is defined, its superclass is not known until runtime since class definitions are imperative statements. This adds a new wrenBindMethod function that walks the bytecode of a method after it is bound to a class, adjusting LOAD_FIELD/STORE_FIELD indices to account for inherited fields and patching superclass dispatch targets. The newClass function now correctly accumulates numFields from the superclass chain, and the VM calls wrenBindMethod when binding methods to a class. Includes new test files for inherited field access and the is operator.
2013-12-11 00:13:25 +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
fe7e9041d1 refactor: replace hardcoded pinned array with linked list in WrenVM GC root tracking
Replace the fixed-size `MAX_PINNED` array of `Obj*` pointers with a dynamically allocated linked list of `PinnedObj` nodes, removing the 16-object limit and eliminating the `numPinned` counter. Update `pinObj` to accept a caller-provided `PinnedObj` stack variable and link it at the head of the list, and simplify `unpinObj` to pop the head without requiring the object argument. Adjust `wrenNewVM` to initialize the new `pinned` pointer to NULL, and modify `collectGarbage` to iterate the linked list instead of the array.
2013-11-29 17:14:19 +00:00
Bob Nystrom
f9c534aef9 chore: rename source files to wren_ prefix and add module-level documentation headers 2013-11-28 16:11:50 +00:00