Commit Graph

7 Commits

Author SHA1 Message Date
Bob Nystrom
07c3dff92f fix: track live memory via bytesAllocated instead of subtracting freed sizes
The old code subtracted oldSize from totalAllocated during deallocation,
which required knowing the object size at free time. This was unsafe
because it could read a freed object to determine its size. The new
approach tracks bytesAllocated by only adding new allocations and
relying on GC marking to account for freed memory, making it both
correct and faster with less code.
2013-12-14 22:17:16 +00:00
Bob Nystrom
e910186f51 fix: remove stack pop for loop body in LOOP opcode since bodies are now statements 2013-12-08 02:47:40 +00:00
Bob Nystrom
071239aa35 feat: add bitwise NOT operator (~) with token, parser, and native implementation
Add TOKEN_TILDE token type and lexer support for the '~' character in the compiler. Implement the bitwise NOT operation as a native method on the Num class, operating on 32-bit unsigned integers. Include a new OPERATOR macro for prefix/infix operator grammar rules and add comprehensive test cases covering positive, negative, floating-point, and boundary values.
2013-12-05 06:09:31 +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
230017a616 feat: raise max method parameters from 10 to 16 with proper error handling
Add MAX_PARAMETERS constant set to 16 and extend VM bytecode instructions CODE_CALL_11 through CODE_CALL_16 to support the new limit. Introduce compile-time error messages when parameter or argument count exceeds 16 in function definitions, method declarations, subscript calls, and regular method calls. Add new native fiber call stubs fn_call9 through fn_call16 and register them in the core initialization. Include comprehensive test coverage for 9-16 parameter functions and methods, plus error tests for exceeding the limit in all contexts.
2013-11-29 23:08:27 +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
Bob Nystrom
4091fe4911 refactor: rename primitives module to wren_core and update all references
Rename the `primitives.h` and `primitives.c` files to `wren_core.h` and `wren_core.c` respectively, reflecting the module's purpose of defining built-in classes and native methods. Update all includes, macro names (PRIMITIVE -> NATIVE, DEF_PRIMITIVE -> DEF_NATIVE, etc.), and function calls (wrenLoadCore -> wrenInitializeCore) across the codebase and Xcode project file to match the new naming convention.
2013-11-28 16:00:55 +00:00