Remove the `WrenVM* vm` parameter from `wrenValueBufferInit`, `wrenByteBufferInit`,
`wrenIntBufferInit`, `wrenStringBufferInit`, `wrenSymbolTableInit`,
`wrenMethodBufferInit`, `wrenStringFind`, and `wrenDebugPrintStackTrace`
functions across the compiler, core, debug, utils, value, and VM modules.
Update all call sites and macro definitions to match the simplified signatures,
eliminating dead parameters that were never used within the function bodies.
The build configuration in script/wren.mk had three redundant warning flags
(-Wsign-compare, -Wtype-limits, -Wuninitialized) that were already covered
by -Wextra. Also updated the TODO comment to explain why -Wno-unused-parameter
remains necessary due to heavy callback usage in Wren's codebase.
Replace the hand-rolled capacity/count/elements fields in ObjList with a
ValueBuffer struct, and update Compiler to use a ValueBuffer for its
constant pool instead of an ObjList. This eliminates the separate
ensureListCapacity and wrenListAdd functions, centralizing buffer growth
logic in wrenValueBufferWrite. Adjust all list primitives (add, clear,
count, iterate, iteratorValue) and the GC marking path to operate on the
embedded ValueBuffer. Add wrenMarkBuffer helper for marking buffer
contents during sweep.
Add CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES to both Debug and Release Xcode build configurations. Fix the resulting warnings by adding explicit casts in wren_compiler.c (readUnicodeEscape, emit, emitShort, emitByteArg) and wren_vm.c (READ_SHORT macro, makeCallStub bytecode assignment) to prevent unintended truncation or sign extension during implicit integer conversions.
The original REPL loop had an if-else structure where the else branch (handling fgets failure) contained a return statement, making the code after the if-else block unreachable. This commit restructures the loop by inverting the condition: when fgets fails, the loop breaks instead of returning, allowing the subsequent wrenFreeVM call to execute. Additionally, enables CLANG_WARN_UNREACHABLE_CODE in both Debug and Release Xcode build configurations to catch similar issues in the future.
Consolidate temporary variable usage in list_add, list_count, and list_iterate by directly inlining AS_LIST/AS_NUM calls. Remove the entire block of num_abs, num_acos, num_asin, num_atan, num_atan2, num_ceil, num_cos, num_floor, and num_fraction primitive definitions to eliminate boilerplate.
Add acos, asin, atan, atan2, tan methods to Num class and expose Num.pi constant with value π. Include corresponding C primitives in wren_core.c and test files for each new method.
Convert `validateIndexValue` and `validateIndex` return types to `uint32_t` with `UINT32_MAX` sentinel, update `wrenNewList`, `wrenListInsert`, `wrenListRemoveAt` signatures, and remove the TODO comment about type unification with `ObjMap`.
Add early return check in wrenFreeVM that validates the VM pointer is not NULL
and that the methodNames count is non-zero, preventing a crash when the VM
has already been freed or was never properly initialized.
Add a generic `contains(element)` method to the `Sequence` class that iterates over elements using the existing `for` loop protocol, removing the duplicate implementation from `List`. Include comprehensive test files for both `List.contains` and `Range.contains` covering ordered, backwards, and exclusive ranges. Also fix the `generate_builtins.py` script to write to the correct `src/vm/` directory path and add a `float:left` CSS rule to the main content area in the documentation stylesheet.
The script/generate_builtins.py was reading from and writing to incorrect source file paths
under src/ instead of the correct src/vm/ directory, causing builtins generation to fail
when the source files were relocated to the vm subdirectory.
The contains method is promoted from List to the Sequence base class, making it available to all sequence types (including Range). Tests are added for both List.contains and Range.contains, covering ordered, backwards, and exclusive ranges.
The main content area lacked a float property causing links to be unreachable
in Internet Explorer 11 when running in edge mode. Adding float:left restores
proper link clickability for IE11 users.
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.
Update the Visual Studio 2013 project to reflect the source file reorganization where source files moved from `src/` to `src/cli/` and `src/vm/` subdirectories, and headers moved from `include/` to `src/include/`. Add explicit `IncludePath` entries for Debug and Release configurations to ensure the compiler can locate the new header locations. Also extend `.gitignore` with Visual Studio cache and user-specific file patterns to prevent build artifacts from being tracked.
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.
Update source file glob patterns from flat "src/*.[ch]" and "include/*.[ch]" to
nested "src/vm/*.[ch]" and "src/include/*.[ch]" to match new directory layout.
Remove the entire benchmark directory walk loop that counted benchmark files,
empty lines, non-empty lines, and TODO patterns, as benchmark data is no longer
collected in this script.
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.
The benchmark directory is relocated from the project root into the test directory, and all scripts, documentation links, and gitignore paths are updated accordingly. The test runner is also refactored to explicitly walk subdirectories (core, io, language, limit) instead of using a single test root, and a new test/README.md is added to document the test suite structure. Additionally, the constructor test for the Foo class is updated to add a zero-arity constructor and adjust expected output strings.
The gh-pages directory is now created inside build/ instead of at the project root.
The .gitignore entry for the old gh-pages location is removed, and the Makefile
cp target is updated from gh-pages to build/gh-pages.
The fails list was initialized after the try-except block that appends to it,
causing an UnboundLocalError when decoding fails. This commit moves the
initialization before the try block to ensure the list exists when accessed.
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.
Wrap stdout and stderr decode calls in try-except to catch UnicodeDecodeError when test output contains invalid UTF-8 byte sequences, appending a failure message instead of crashing the test runner.
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.
The `run_test` function in `script/test.py` now replaces backslash characters with forward slashes after computing the relative path, ensuring consistent path formatting for the wren interpreter across platforms.
- Update comment in `new_` function to accurately describe how angle brackets prevent direct user calls to `<instantiate>` method
- Fix spelling error in assertion message from "Uknown" to "Unknown" in `wrenCall` function
- Remove trailing whitespace in `wren_vm.c`
Add a new `table.precedence` CSS rule in style.scss to style the precedence table with full width, left padding, and consistent font sizing. Convert the existing Dart-formatted operator precedence list in doc/site/expressions.markdown into an HTML table with columns for precedence level, operator, description, and associativity, including all operators from call/subscript/selection down to assignment.
- 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.
- 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
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.
Replace C-style index loops (`for (i in 0...collection.count)`) with direct element iteration (`for (element in collection)`) across five methods in the `Planner` class: `removePropagateFrom`, `extractPlanFromConstraints`, `addConstraintsConsumingTo`, and two anonymous loops in the constraint propagation logic. This improves readability and aligns with Wren's idiomatic iteration patterns without changing behavior.
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 `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 shared number parsing logic into makeNumber helper with errno overflow checking, replace all direct wrenReallocate(ptr,0,0) calls with DEALLOCATE macro, and add test cases for too-large number literals in decimal and hex formats.
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.
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.
Rename the NATIVE macro to PRIMITIVE and DEF_NATIVE to DEF_PRIMITIVE, updating all
corresponding function prefixes from native_ to prim_ to maintain consistency with
the existing METHOD_PRIMITIVE type and terminology used throughout the codebase.
The OS detection now uses `gcc -dumpmachine` directly instead of `$(CC)` to avoid failures when CC is not defined by MSYS. Additionally, when the OS is detected as mingw32, CC is explicitly set to gcc to work around missing cc executable on some MinGW versions.
The AUTHORS file was missing a trailing newline after Marco Lizza's entry.
This commit adds the missing newline and appends Raymond Sohn as a new
contributor to the project.
Add a check in the interpreter's class creation path that rejects attempts to subclass any of the seven core built-in types (Class, Fiber, Fn, List, Map, Range, String). When such a subclass is declared, a runtime error is raised with a message like "Class 'SubName' may not subclass a built-in". Also add corresponding test files for each forbidden subclass scenario.
The `signatureSymbol` function previously built a method name string as a side effect before hashing it. This change separates the stringification logic into a new `signatureToString` function that writes the full signature name into a provided buffer and updates its length. All callers now use the new helper, making the code clearer and allowing the stringified signature to be reused independently of symbol lookup.
The finishParameterList function no longer needs to consume the closing delimiter
or produce error messages, as that responsibility has been moved to the callers.
The parameterList wrapper function has been inlined into its single call site,
simplifying the parameter parsing flow.
- Compile empty `()` as a valid method signature distinct from no parentheses
- Update `call()`, `clear()`, `run()`, `try()`, and `yield()` to use empty argument lists
- Revise documentation across multiple files to reflect new signature semantics
The method signature format has been changed from space-counted arity (e.g., "== ") to explicit parenthesized parameter lists (e.g., "==(_)"). This required updating the MAX_METHOD_SIGNATURE calculation to account for parentheses and parameter separators, replacing the old copyName helper with a new Signature struct and SignatureType enum, and rewriting the methodNotFound error message to display the full signature string instead of reconstructing arity from trailing spaces. All core method registrations in wren_core.c, wren_io.c, and corresponding test expectations have been updated to use the new signature format.
The wrenDefineMethod and wrenDefineStaticMethod functions now accept a single `signature` string parameter instead of separate `methodName` and `arity` arguments. This simplifies the API by letting callers specify the full method signature (including arity spaces) directly, removing the internal arity-to-spaces conversion logic in defineMethod. The change updates the header declaration, the internal defineMethod helper, and all call sites in wren_io.c to pass pre-formatted signatures.
Add new Precedence enum values (PREC_BITWISE_OR, PREC_BITWISE_XOR, PREC_BITWISE_AND, PREC_BITWISE_SHIFT) and a PREC_TERNARY level between assignment and logical operators. Update and_(), or_(), and conditional() to use the refined precedence constants. Include a test file verifying correct associativity and precedence ordering among bitwise operators (|, &, ^, <<) in expressions.
Previously, `Num.fromString` accepted strings like `"1.2prefix"` and returned the
leading numeric portion (`1.2`). This change makes parsing stricter by requiring
that the entire string be consumed after `strtod`, skipping only trailing
whitespace. If any non-whitespace characters remain after the number, the
function now returns `null` instead of a partial result.
The fix also adds an explicit empty-string check and updates the test suite to
reflect the new behavior, replacing the old `"1.2prefix"` success test with a
`"1.2suffix"` null-return test.
Implement a new `Num.fromString(value)` method that attempts to parse a string as a decimal literal and returns the corresponding `Num` instance, or `null` if parsing fails. The implementation uses `strtod` for conversion, validates the argument is a string at runtime, and includes tests for valid numbers, edge cases like leading/trailing whitespace and partial suffix parsing, non-number inputs returning null, and a runtime error when a non-string argument is passed. Also fixes a missing semicolon in the `toString` native registration and removes the hex literal TODO from the number literals test.
- Change `int` to `uint32_t` for iterator indices in `map_iterate` and `string_iterate` to match capacity/length types
- Update `String.length` field type from `int` to `uint32_t` in `wren_utils.h`
- Modify `wrenStringCodePointAt` parameter type from `int` to `uint32_t` and remove redundant negative index assertion
- Convert loop variable in `markMap` from `int` to `uint32_t` to match `map->capacity` type
- Add `-Wsign-compare`, `-Wtype-limits`, and `-Wuninitialized` compiler flags to catch future mismatches
The UINT32_MAX macro is defined in <stdint.h> but was not included, causing
compilation errors on platforms where it is not implicitly pulled in by other
headers. This commit adds the missing include to ensure the constant is
available for use in the source file.
Add before_install step to .travis.yml that updates apt packages and installs
gcc-multilib, enabling 32-bit C library headers and runtime for cross-compilation
in the CI environment.
The baseline file path was hardcoded as "benchmark/baseline.txt" in both read_baseline() and generate_baseline() functions, ignoring the BENCHMARK_DIR constant. This caused the baseline file to be created in the wrong directory when BENCHMARK_DIR differed from the default "benchmark" path. Changed both functions to construct the path using os.path.join(BENCHMARK_DIR, "baseline.txt") for consistency and correctness.