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.
Remove conditional getcwd logic for MSVC and POSIX, replacing it with a simple
empty root directory string. This simplifies the import path resolution by
always using relative paths from the current working directory instead of
attempting to resolve an absolute root path at startup.
- Add platform-specific getcwd header includes for MSVC and POSIX
- Replace malloc-based rootDirectory assignment with a static 2048-byte buffer
- Initialize rootDirectory to point to the static buffer instead of an empty string
- Update runFile to use const char* for lastSlash and copy path directly into buffer
- Implement TODO in runRepl by calling getcwd to set rootDirectory to current working directory
Initialize vm->modules to NULL in wrenNewVM and create a module registry map to track loaded modules. In loadModule, check if a module has already been loaded via wrenMapFind; if found, reuse the existing module object instead of creating a new one, enabling successive wrenInterpret calls to execute in the same module context and preserve variable bindings across REPL invocations.
Extract `callMethodInstruction` and `callMethod` helper functions from the
existing `methodCall` function to reduce code duplication and improve
readability. Also fix comment formatting for argument arity overloading
and block argument inclusion.
Extract the duplicated argument list parsing logic from methodCall and
subscript into a shared finishArgumentList function. This unifies the
comma-separated expression parsing, arity tracking, and newline handling
into a single location. Also add a new test case verifying that newlines
after commas and before closing delimiters are correctly handled in both
method calls and subscript expressions.
When a script path contains no '/' character, strrchr returns NULL, causing a crash in the subsequent malloc and memcpy calls. This change adds a NULL check before attempting to extract the root directory, leaving rootDirectory as an empty string when no separator is present.
The monolithic Makefile is replaced with a thin wrapper that invokes
script/wren.mk for each configuration. Build artifacts are now placed
in bin/ (executables) and lib/ (static/shared libraries) instead of
the project root. The .gitignore is updated accordingly, and the
getting-started documentation reflects the new output layout.
Add three new bitwise operators (^, <<, >>) to the Wren compiler and runtime,
including tokenization, parsing with correct precedence, and native method
implementations operating on 32-bit unsigned integers. New test files verify
correct behavior for edge cases including max u32 values and operand type errors.
Create new modules.markdown guide explaining Wren's module system, import syntax, and top-level scoping. Update error-handling.markdown to use "Top-level variable" instead of "Global variable" in error messages. Revise variables.markdown to clarify top-level variable visibility and link to the new modules page. Add "Modules" link to the site navigation template.
Add token definitions for `<<`, `>>`, and `^` in the lexer with proper two-character parsing for shift operators. Register new infix operators at the BITWISE precedence level in the parser grammar. Implement native C functions for bitwise XOR, left shift, and right shift on 32-bit unsigned integers in the core runtime, and bind them as methods on the Num class. Include test files covering edge cases like max u32, overflow, and non-numeric operand errors.
Make the `for` clause in import statements optional, and support comma-separated lists of imported names when present. This removes the previous restriction of exactly one imported variable per import statement.
- Refactor `import()` in compiler to handle optional `for` clause with loop over comma-separated names
- Update existing tests to use comma-separated imports and omit `for` clause where appropriate
- Add new tests: `inside_block`, `name_collision`, `no_variable`
Add map_numeric and map_string benchmark scripts in Lua, Python, Ruby, and Wren to compare hash map insertion/lookup/deletion performance across languages. Register both new benchmarks in the benchmark runner script and fix its language executable paths to use WREN_DIR. Expose a new `IO.time` static method in the C IO module returning `time(NULL)` as a double. In the Makefile, split the monolithic `clean` target into separate removals for build artifacts, wren executables, and library variants to avoid accidental deletion of unrelated files. Remove hardcoded hash singleton constants from wren_value.c as they are no longer used.