Cache the FNV-1a hash code in the ObjString struct at creation time, replacing the
on-the-fly sampling hash in hashObject() and enabling constant-time string equality
checks. Refactor string allocation into allocateString() and hashString() helpers,
remove the old wrenNewUninitializedString() declaration, and add a CONST_STRING
macro. Disable the unimplemented subscript range operator with a runtime error and
skip the related UTF-8 tests. Add a string_equals benchmark to measure the speedup.
Swap the parameter order of `List.insert()` from `(item, index)` to `(index, item)`,
matching the convention used by most standard libraries. Update the C implementation
in `wren_core.c`, all documentation examples, and every test file to reflect the new
signature. Also restructure MSVC project files to match the new `src/cli/` and
`src/vm/` directory layout, add Visual Studio cache files to `.gitignore`, and fix
a trailing whitespace issue in `class_supertype`.
The `List.insert` method signature is changed from `insert(item, index)` to `insert(index, item)`, aligning with standard practice in most languages. All documentation, core implementation, and test files are updated to reflect the new parameter order. The `validateIndex` call now reads the index from slot 1 instead of slot 2, and the value is read from slot 2.
Move runFile() and VM configuration logic from main.c into new vm.c module,
exposing createVM() and runFile() functions. This decouples CLI script
execution from the REPL and main entry point, enabling reuse of the same
VM setup and file-running code for API tests.
Extract the static `readFile`, `readModule`, and `setRootDirectory` functions from main.c into a new io module, replacing the fixed-size `rootDirectory` array with a heap-allocated pointer and adding the corresponding header with public declarations.
The dumpObject function in wren_debug.c was incorrectly printing "[fn %p]" for
OBJ_RANGE objects instead of the correct "[range %p]" label. This fix ensures
that range objects are properly identified during debug output.
The two validation functions in wren_core.c were calling wrenStringFormat with a format
string containing a "$" placeholder but were not passing the argName argument, causing
the placeholder to remain unsubstituted in error messages. This commit adds the missing
argName parameter to both calls.
Additionally, the CONST_STRING macro in wren_value.h was changed from using strlen(text)
to sizeof(text) - 1, which allows the compiler to compute the string length at compile
time rather than at runtime, improving performance for string literal creation.
The previous implementation used `sizeof(text) - 1` to determine string length at compile time, which required the argument to be a bare string literal. The new approach uses `strlen(text)` instead, which allows most compilers to evaluate the string length at compile time when a string literal is passed, while also supporting non-literal string arguments. This change trades compile-time guarantee for broader compatibility and compiler optimization potential.
Replace ad-hoc string construction using wrenNewString, wrenStringConcat, and sprintf with the new wrenStringFormat helper. This centralizes string formatting logic, reduces code duplication, and eliminates manual length calculations in wren_compiler.c, wren_core.c, wren_value.c, and wren_vm.c. Also introduces CONST_STRING macro for compile-time string literals and changes wrenNewUninitializedString return type from Value to ObjString* for consistency.
The previous signature `insert(element, index)` was counter-intuitive and inconsistent with every major language's list API. This commit swaps the parameters to `insert(index, element)`, matching the convention used by Ruby, JavaScript, C++, Lua, C#, Java, and Python. All documentation, C implementation, and test files are updated to reflect the new order.
Separate Wren VM library sources from CLI tool sources by moving them into
src/vm/ and src/cli/ subdirectories respectively. Update the Makefile to use
separate wildcard patterns for each directory, generate distinct object file
paths under build/vm/ and build/cli/, and adjust include paths to src/include.
Also update the Xcode project file to reference the new file locations.
Implement a new `supertype` property on Class objects that returns the superclass of a given class. The primitive `class_supertype` checks if the class has a superclass (returning null for Object) and returns the superclass object. Includes documentation in the class reference and a test file verifying behavior for explicit superclasses, implicit Object inheritance, and Object's null supertype.
Remove explicit NULL and zero assignments for vm fields (methodHandles, foreignCallSlot, foreignCallNumArgs, bytesAllocated, compiler, fiber, first, numTempRoots, modules) and consolidate them into a single memset(vm, 0, sizeof(WrenVM)) call, simplifying the initialization logic.
Moves the debug trace instruction printing logic from inline DISPATCH() macro into a dedicated DEBUG_TRACE_INSTRUCTIONS macro with proper WREN_DEBUG_TRACE_INSTRUCTIONS guard, and adjusts RUNTIME_ERROR macro to use Allman brace style for consistency with surrounding code.
Update the num_toString primitive in wren_core.c to return "infinity" and "-infinity"
instead of the platform-dependent "inf" and "-inf" for positive and negative infinity
values. This ensures consistent string output across different C compilers and
platforms that may format infinity differently. Update the corresponding test
expectations in test/number/divide.wren to match the new output format.
Remove the Xcode-generated file header comment with copyright notice
and author attribution from wren_debug.h. Also correct the include guard
macro from `wren_wren_debug_h` to `wren_debug_h` to match the actual
file path and naming convention used by other headers in the project.
- Fix misleading comment in `new_` function in `wren_compiler.c` to accurately describe angle brackets instead of leading space
- Fix typo "Uknown" to "Unknown" in assertion message in `wrenCall` function in `wren_vm.c`
- Remove trailing whitespace in `wren_vm.c`
In the variable undefined check within wrenCompile, the error() call was
receiving an ObjString struct instead of its underlying char* buffer,
causing a type mismatch. Changed the argument to access the .buffer field
of the variable name string.
The comment previously stated that a leading space prevents direct calls,
but the actual mechanism uses angle brackets in the method name "<instantiate>"
to make it inaccessible from user code.
- Delete TODO about nullary constructor handling in constructorSignature
- Remove TODO and commented-out code for making fibers iterable in wrenInitializeCore
- Eliminate TODO questioning elimination of OBJ_CLASS enum in favor of classObj pointers
- Drop TODO about moving WrenVM struct definition and using array for class fields
Previously, IO.read would return an empty string when stdin reached EOF because it always called wrenReturnString with the buffer, even when fgets returned NULL. Now it returns null by only calling wrenReturnString when fgets succeeds, and adds a test case verifying that IO.read returns null on EOF.
Refactor the internal Map API to replace the low-level `wrenMapFind` function
(which returned a raw entry index or UINT32_MAX) with a higher-level
`wrenMapGet` that directly returns the stored Value or UNDEFINED_VAL.
This change simplifies all call sites by eliminating manual index-based entry
lookups and direct access to the internal `entries` array. The old
`wrenMapFind` is made static and renamed to `findEntry`, returning a pointer
to the MapEntry struct instead of an index, which is used internally by
`wrenMapGet` and `wrenMapRemoveKey`.
Additionally, fix a bug in `loadModule` where a new module was always created
before checking if the module already existed; now the early return for
already-loaded modules correctly skips module creation and variable copying.
- Change Fiber.yield() to exit interpreter when no parent fiber exists instead of raising runtime error
- Add Fiber.current primitive to return the currently executing fiber object
- Update interpreter loop to stop execution when PRIM_RUN_FIBER receives null value
- Modify test expectations to reflect new yielding behavior from main fiber
Previously, IO.read would return an empty string when reading from stdin reached EOF. This changes the behavior to return null when fgets returns NULL, indicating end-of-file. The fix removes the unconditional wrenReturnString call and only returns the buffer when data was actually read. A new test case verifies that IO.read returns null on EOF.
Add five new numeric methods to the Wren core library: deg (convert radians to degrees), rad (convert degrees to radians), fraction (extract fractional part), sign (return -1, 0, or 1), and truncate (discard fractional part). Register all new primitives in wrenInitializeCore and include corresponding test files for fraction, sign, and truncate operations.
Implement a `count` method on the `Sequence` class that iterates over all elements and returns the total number. The method uses a simple for-loop to increment a counter for each element, providing a generic way to determine sequence length without requiring a separate length property. Includes a test sequence that yields values 1 through 10 to verify the count returns 10.
The `num_div` primitive performed integer division on two int32 values, but this
functionality is already covered by the existing `num_divide` primitive which
handles floating-point division. Removing this duplicate method eliminates
confusion and reduces code maintenance burden.
The previous implementation cast the number to int32_t, which incorrectly
truncated values outside the int32_t range and produced wrong results for
large doubles. The new implementation uses the standard C `modf` function
to correctly truncate the fractional part while preserving the full
double precision of the integer portion.
Replace the num_decimal primitive with num_fraction, changing the implementation from a simple subtraction of integer part to using the standard C modf function for more robust fractional part extraction. Update the method registration in wrenInitializeCore to bind the new name and function.
Implement DEF_PRIMITIVE(num_div) that casts both operands to int32_t
and performs integer division, returning the truncated quotient.
Register the new primitive as "div(_)" on the num class in
wrenInitializeCore, placed alphabetically between "deg" and "floor".
Remove the dedicated `setMarkedFlag`, `markString`, `markFn`, and `markClass` helper functions, replacing their calls with the new generic `wrenMarkObj` entry point. This eliminates duplicated marking logic and ensures all object types go through a single marking path that handles cycle detection and memory tracking consistently.
Implement the num_sign primitive that checks if the numeric argument is >= 0.0
and returns 1.0 for non-negative values or -1.0 for negative values. Register
the new primitive on the Number class in wrenInitializeCore.
The num_decimal primitive was incorrectly returning the integer part of a number
instead of the fractional part, while num_truncate was returning the fractional
part instead of truncating to the integer portion. This commit corrects both
functions by exchanging their logic bodies.
Implement two new primitive methods for the Number class: `decimal` returns the integer part by casting to uint32_t, and `truncate` returns the fractional part by subtracting the integer portion from the original value. Register both primitives in the core initialization.
Implement two new primitive methods on the Num class: `deg` converts radians to degrees by multiplying by 180/π (57.29578) and flooring, while `rad` converts degrees to radians by dividing by the same factor and flooring. Both are registered in `wrenInitializeCore` alongside existing trigonometric primitives.
Implement the `any` method on the Sequence class that returns true if any element passes the given predicate function. Update the core.wren library source, the C embedded source string in wren_core.c, and add comprehensive test files for normal usage, non-bool return values, and non-function argument error handling. Also fix a typo in the QA documentation and correct the initial account balance in the example.
Extract the duplicated number parsing logic from readHexNumber and readNumber into a single makeNumber function that accepts an isHex flag. Also fix a missing OBJ_VAL wrapper in the num_fromString primitive's ERANGE error path and normalize trailing newlines in three test files.
Replace TODO stubs with actual errno checks in readHexNumber, readNumber, and num_fromString to emit a "Number literal is too large." error when strtol/strtod overflow. Add three test files (literal_too_large.wren, hex_too_large.wren, from_string_too_large.wren) verifying compile-time and runtime error behavior for out-of-range numeric inputs.
The comment for the DEALLOCATE macro in wren_common.h previously read "Use the VM's allocate to free"
which was grammatically incorrect and misleading. Changed "allocate" to "allocator" to accurately
describe that the macro uses the VM's memory allocator function to free memory at the given pointer.
Introduce a DEALLOCATE macro that wraps wrenReallocate(vm, pointer, 0, 0) to provide a consistent, readable interface for freeing allocated memory. Replace all existing direct wrenReallocate calls used for deallocation across wren_core.c, wren_utils.c, wren_value.c, and wren_vm.c with the new macro. Also remove two stale TODO comments in wren_core.c related to testing and unimplemented map methods.