The old hashBits function XORed the two 32-bit halves of a double and applied a weak mixing from Java's HashMap, which produced severe clustering for small integers (e.g., all values 1..N mapped to entry zero). This caused O(N²) insertion/lookup in maps with numeric keys. The new implementation uses Thomas Wang's integer hash (via V8's ComputeLongHash), which distributes bits uniformly across the 30-bit hash space. Also doubles the iteration count in map_numeric benchmarks (from 1M to 2M) to better stress the hash function, and updates the expected benchmark output accordingly.
The old hashBits function XORed the two 32-bit halves of a double and applied
Java HashMap-style mixing, but for small integers the low bits of the double
representation are mostly zero, causing nearly all keys to map to entry zero.
This replaces it with Thomas Wang's integer hash (as used by V8's
ComputeLongHash), which properly scatters bits across the 32-bit key space.
Also updates the map_numeric benchmark to iterate 2,000,000 entries (up from
1,000,000) and adjusts the expected output in util/benchmark.py accordingly.
Implement a new String.fromByte(byte) class method that creates a single-byte string from an integer 0-255. Includes C primitive in wren_core.c with bounds checking, the wrenStringFromByte helper in wren_value.c, header declaration, documentation in the core string markdown, and five test files covering valid values (65, 0, 255) and error cases (non-integer, non-number, too large, negative).
The fix changes `path->chars[2]` to `path[2]` in the drive letter absolute path detection logic, resolving a compilation error on Windows where `path` is a `const char*` pointer, not a struct with a `chars` member.
The include guard macro in src/vm/wren_compiler.h was incorrectly named
wren_parser_h, likely a copy-paste artifact from the parser header.
This change corrects it to wren_compiler_h to match the actual filename
and prevent potential ODR violations when both headers are included.
Replace fixed-size ERROR_MESSAGE_SIZE buffer with dynamically sized array based on MAX_VARIABLE_NAME to avoid stack overflow when formatting error messages for tokens exceeding the original buffer capacity.
Implement Ctrl+w keybinding to delete the word left of cursor by first removing trailing spaces then deleting non-space characters. Add EscapeBracket.delete handler that calls deleteRight() and consumes the extra 126 byte. Support EscapeBracket.end and EscapeBracket.home to jump cursor to line end and start respectively. Define corresponding constants ctrlW (0x17), delete (0x33), end (0x46), and home (0x48) in the Chars and EscapeBracket classes.
Add Ctrl+w keybinding to delete the word left of cursor by removing trailing spaces then characters until next space. Implement EscapeBracket.delete handling to delete character right of cursor and consume the trailing 126 byte. Support EscapeBracket.end and EscapeBracket.home to jump cursor to end or start of line. Register new ctrlW constant (0x17) and EscapeBracket constants for delete (0x33), end (0x46), home (0x48). Add Taylor Hoff to AUTHORS.
Introduce a static inline `wrenHasError` function in `wren_value.h` that encapsulates the `!IS_NULL(fiber->error)` pattern, improving code readability and maintainability. Replace all direct `IS_NULL(fiber->error)` checks across `wren_core.c`, `wren_vm.c`, and the interpreter loop with calls to this new helper. Additionally, clean up commented-out debug print statements and extraneous blank lines in the `trim` methods within the embedded core module source string, and add Michel Hermier to the AUTHORS file.
Introduce a limited form of re-entrant calls by enforcing that apiStack is NULL before entering a foreign call and resetting it to NULL after completion, replacing the previous save/restore pattern. Add a regression test (call_calls_foreign) that exercises re-entrant wrenCall invocations where a foreign method triggers another API call, verifying slot counts and correct parameter passing. Fix a typo in reset_stack_after_call_abort test (afterConstruct -> afterAbort) and update Makefile to build api_test target separately.
The core change in wren_vm.c replaces the save/restore pattern for vm->apiStack with a simple NULL assignment after foreign calls, enabling nested wrenCall invocations from within foreign method handlers. This is accompanied by new test files (call_calls_foreign.c/.h/.wren) that verify the re-entrant call path works correctly, along with Makefile and Xcode project updates to build and run the new tests. A minor typo fix in reset_stack_after_call_abort.c renames a handle variable from 'afterConstruct' to 'afterAbort' for consistency.
The assignment of a string literal to a non-const char* pointer triggers a C++
compiler warning about deprecated conversion. Adding the explicit cast silences
the warning while preserving the existing behavior, since the pointer is never
passed to free() or otherwise modified.
Add an empty.txt file under test/language/module/use_nearest_modules_dir/a/wren_modules/ to ensure Git creates and tracks the directory structure, which would otherwise be omitted due to containing no files.
Add explicit check in `runFiber()` to reject calls to the root fiber, preventing VM crashes when a completed fiber's caller tries to resume it. Replace the boolean `callerIsTrying` field with a `FiberState` enum (`FIBER_TRY`, `FIBER_ROOT`, `FIBER_OTHER`) to track fiber invocation mode, updating all relevant primitives and initialization. Include new test cases (`call_root.wren`, `call_wren_call_root.*`) and re-entrancy documentation notes.
Remove the dedicated METHOD_FN_CALL method type and its associated arity-checking dispatch logic in the VM. Instead, define a shared `call()` helper that validates argument count and invokes `wrenCallFunction`, then generate individual `fn_call0` through `fn_call16` primitives via a macro. This eliminates the special-case method type while preserving identical behavior for all 17 call overloads.
Also rename the `fn` union member to `as` in the `Method` struct, update all references accordingly, and add a `benchmark_baseline` Makefile target for generating performance baselines.
Add two new source files (path.c and resolution.c) to the PBXSourcesBuildPhase
of the api_test target in the wren XCode project file, ensuring they are
compiled as part of the test suite build.
Introduce a detailed RFC document outlining improvements to Wren's module import system, including relative import paths, package-based resolution, and ecosystem support. The proposal addresses current limitations where imports are always relative to the working directory, making code reuse across directories difficult. Key changes include supporting relative imports from the importing file's location and defining a package root mechanism for third-party dependencies.
The note clarifies that the proposal is now mostly implemented, though
the actual implementation diverges from the original design described
in the document.
Replace the `test` make target with `api_test` in all CI build configurations (32/64-bit, debug/release, C/C++). Introduce a new `Path` abstraction with normalization, directory detection, and realpath resolution to support relative module imports (e.g., `"./cthulu"`). Update `runFile` and `runRepl` to return `WrenInterpretResult` instead of void, enabling proper exit codes on compile/runtime errors. Add `stat.h` for cross-platform file mode macros and a `wrenModulesDirectory` path for future package imports.
- Add automatic docs deployment stage for master branch pushes in .travis.yml
- Include python3-markdown, python3-pygments, python3-setuptools, and ruby-sass as build dependencies
- Switch from container-based to sudo-required builds with trusty dist for custom Pygments lexer installation
- Ensure build directory exists before generating docs in Makefile
Introduce a path type classification system (absolute, relative, simple) to distinguish logical imports from relative ones. Implement automatic discovery of a "wren_modules" directory by walking up from the root directory. Refactor the CLI to return interpret results and exit codes instead of exiting directly. Extract cross-platform stat macros into a shared header. Update test API calls to use explicit relative paths.
Update all four PreBuildEvent configurations (Debug Win32, Debug x64, Release Win32, Release x64) in the vs2017 wren.vcxproj to call the new update_deps.py and build_libuv.py scripts instead of the removed libuv.py download and build commands. Also append "vs2017" argument to the vcbuild.bat call in build_libuv_windows function to ensure correct toolchain selection.
Implement six new trimming methods on String: trim(), trim(chars), trimEnd(), trimEnd(chars), trimStart(), trimStart(chars). The core logic uses a private trim_ helper that accepts a chars string, converts it to code points, and iterates from the start and/or end of the string to remove matching characters. Default whitespace set is tab, carriage return, newline, and space. Includes comprehensive test coverage for default and custom character trimming, edge cases (empty strings, all-trimmed strings, 8-bit clean data), and runtime error when chars argument is not a string.
The smartypants package name was incorrect for the Ubuntu distribution used in CI; switching to python-smartypants ensures the correct Debian/Ubuntu package is installed for text processing dependencies.
The previous package name python3-smartypants was incorrect for the Travis CI
build environment, causing package installation failures. This commit corrects
the package name to smartypants, which is the proper apt package for the
SmartyPants text processing library used in documentation generation.
Update all references from `python` to `python3` in contributing guide and Travis deployment script to ensure compatibility with systems where `python` is not linked to Python 3. Also add missing `Description-Content-Type` metadata field to the Wren Pygments lexer egg-info.
The previous commit mistakenly placed 'sudo' after 'python' in the
pygments lexer setup command, causing a permission error. This fix
reverses the order to 'sudo python setup.py develop', ensuring the
package installs with proper system privileges.
The container-based infrastructure does not support sudo, which is needed to install the custom Pygments lexer for documentation generation. This change replaces the `sudo: false` directive with `sudo: required` and explicitly sets the distribution to `trusty`. Additionally, the deploy script is corrected to invoke `sudo python` instead of plain `python` when installing the lexer, ensuring the system-wide installation succeeds.
- Rename util/deployGHP.sh to util/deploy_docs_from_travis.sh for consistency
- Change deploy condition from excluding pull requests to explicitly requiring push events on master branch
The documentation for the `close()` method on the File module incorrectly stated that reading or writing is still possible after closing the file. This commit corrects the description to accurately reflect that the file cannot be read from or written to after it has been closed.
Resolve merge conflict in AUTHORS by adding missing contributor entry.
Prevent macro leak by adding #undef FINALIZER after the module registry
definition in src/cli/modules.c, consistent with other macro cleanup.
When compiling a single expression, the parser now explicitly consumes the TOKEN_EOF token after parsing the expression. This ensures that any trailing garbage or unexpected tokens after the expression are caught and reported as errors, rather than being silently ignored. The comment for the non-expression path is also updated to clarify that it checks for end of file rather than end of block.
Replace strncpy with memcpy in readBuiltInModule to avoid potential string termination issues
when copying module source code, and increase ERROR_MESSAGE_SIZE from 60 to 80 to provide
more room for compiler error messages with long variable names.
Migrate the internal `String` struct to use the heap-allocated `ObjString*` throughout the compiler, debugger, VM, and value system. This unifies string representation, enables proper garbage collection of symbol table entries via new `wrenBlackenSymbolTable` function, and removes manual memory management for symbol names.
Add handling for UTF-8 byte order mark (BOM) at the start of source code
in wrenCompile function by checking for the three-byte sequence \xEF\xBB\xBF
and advancing the source pointer past it. Include a regression test file
(test/regression/520.wren) that contains a BOM to verify the fix works
correctly.
Add a MAX_PARAMETERS bound to the loop in signatureParameterList to prevent
buffer overflow when a method signature has an excessive number of parameters.
A compile error is already reported in such cases, but the unbounded loop could
still write past the end of the name buffer. Also add regression test 494.wren
to cover this scenario.
The compiler now always reserves slot zero for either the closure or method
receiver, eliminating a corner case where top-level REPL code lacked the
pre-allocated slot that function/method bodies expect. This ensures local
variables declared in REPL loops (e.g. `for (i in 1..2)`) get correct slot
indexes.
Additionally, inlines `wrenResetFiber` into `wrenNewFiber` and stores the
imported module's closure on the stack before invoking it, preventing a GC
from collecting the closure during import.
Fix two documentation errors: change `Foo.bar.printFromStatic()` to
`Foo.printFromStatic()` in classes.markdown, and replace `map` with `each`
in concurrency.markdown to match the actual Wren API.
The previous file used a non-standard preamble ("Wren uses the MIT License:")
and included an extra parenthetical clarification about binary distributions.
This commit rewrites the license body to exactly follow the standard MIT
License template published at https://choosealicense.com/licenses/mit/,
removes the custom header, and normalizes line wrapping so that GitHub and
other license detection tools correctly identify the project as MIT-licensed.
The example code in the embedding documentation for bindForeignMethod() incorrectly used `!isStatic` when checking for a static method `Math.add(_,_)`. Changed the condition to `isStatic` so the example correctly demonstrates how to dispatch static foreign methods.
The assertion for the `name` parameter in `wrenGetVariable` was incorrectly checking `module != NULL` instead of `name != NULL`. This fix ensures the variable name parameter is properly validated, preventing potential null pointer dereferences when retrieving variables.
Additionally, adds Marshall Bowers to the AUTHORS file.
The getNumArguments function had CODE_IMPORT_MODULE incorrectly returning 1 instead of 2, and CODE_IMPORT_VARIABLE returning 2 instead of 4. Additionally, wrenBindMethodCode had two bugs: it was incrementing ip before reading the instruction, causing incorrect opcode dispatch, and it was using ip++ instead of ip+1 for field offset adjustment, corrupting subsequent bytecode. The super instruction handling also incorrectly skipped over the symbol bytes before reading the constant index.
Replace the flat module name-to-path mapping with a proper relative import resolver that handles "./" and "../" prefixes relative to the importer's directory. This is a breaking change: existing imports in user code that assume paths are relative to the entrypoint file will now fail. Stack trace output and host API calls now use the resolved module string instead of the short import name. Update all test fixtures to use "./" relative imports and adjust C test files to pass the full resolved module path to wrenGetVariable.
Introduce a new `Path` struct and associated functions in `src/cli/path.c` and `src/cli/path.h` for resolving relative imports within the VM. The module provides operations such as normalization, directory extraction, extension removal, joining, and absolute path detection. Additionally, add a lightweight unit test framework under `test/unit/` with a `test.h`/`test.c` harness and `path_test.c` covering normalization cases. Update the build system (`Makefile`, `util/wren.mk`) to separate API tests from unit tests, rename the test executables to `api_wren` and `unit_wren`, and adjust CI targets and Python test scripts accordingly.
This breaking API change introduces a new `WrenResolveModuleFn` callback in the configuration that allows the host to canonicalize import module names, enabling relative imports. The `wrenInterpret()` function now requires a `module` parameter to specify the module name for the code being interpreted. The `wrenInterpretInModule()` function is removed in favor of the updated `wrenInterpret()`. The `metaCompile` function now dynamically looks up the caller's module name instead of hardcoding "main". New test files `resolution.c`, `resolution.h`, and `resolution.wren` are added to verify resolver behavior including null default, NULL return error, string rewriting, shared module deduplication, and importer propagation.
The error callback function signature in the embedding documentation was missing the required WrenVM* first parameter, which would cause compilation errors for users following the example. The fix adds the vm parameter to the error function declaration in the configuring-the-vm markdown file.
Add CODE_END_MODULE opcode to store the current ObjModule in vm->lastModule after module body execution. Modify IMPORT_VARIABLE to load variables from vm->lastModule instead of using a constant string operand for the module name. Update opcode definitions, debug dump, compiler import logic, and interpreter dispatch accordingly. Refactor variable lookup into getModuleVariable helper. Adjust formatting in wren_primitive.c and wren_opt_meta.c.
The compileInModule function now returns a closure directly instead of wrapping it in a fiber, simplifying the compilation pipeline and removing unnecessary fiber overhead for module imports. The wrenImportModule function is moved into wren_vm.c and rewritten to execute the imported module's closure immediately rather than returning a fiber for deferred execution. This change also adds a test for yielding from an imported module to verify correct behavior with the new execution model.
Remove redundant NULL-check branches for module parameter by merging the
wrenPopRoot call into a single conditional after compileInModule, eliminating
the early return path and simplifying control flow in the compilation entry point.
Replace the bundled GYP build system with a newer upstream version that adds z/OS platform support, improves MSVC SDK version detection with compatible SDK fallback, fixes host LDFLAGS handling in ninja generator, and includes various bug fixes and maintainer updates across multiple generator backends.
The switch statement in getNumArguments covers all opcode cases, but the compiler
cannot prove exhaustiveness. Adding UNREACHABLE() followed by return 0 eliminates
the "control reaches end of non-void function" warning on strict compiler settings.
The documentation examples for the `from`, `to`, and `max` properties of the Range class were incorrectly using `.min` in their code samples. Updated the examples in `doc/site/modules/core/range.markdown` to call the correct methods: `.from` for the `from` property, `.to` for the `to` property, and `.max` for the `max` property, ensuring the printed output values match the documented behavior.
Replace the previous approach of desugaring import statements into calls to System.importModule() and System.getModuleVariable() with two new bytecode instructions: CODE_IMPORT_MODULE and CODE_IMPORT_VARIABLE. This eliminates the need for the corresponding primitive methods in the core library, adds proper debug dump support for the new opcodes, and updates the compiler to emit these instructions directly. The getNumArguments function is also updated to handle the new opcodes and the unreachable default case is removed.
The link target for the embedded API reference was pointing to
`embedding-api.html` but the actual generated page uses the path
`embedding` without the `.html` extension. This change fixes the
link so it resolves correctly on the documentation site.
When a fiber is started for the first time via call() or transfer(), the value argument is now bound to the fiber's function parameter if it takes one. Previously, the first value was always ignored. Also adds runtime error for fibers created with functions taking more than one parameter, and updates documentation and tests accordingly.
- Replace string concatenation with interpolation in class method examples
- Remove backticks from Fiber class references in concurrency docs
- Add guidelines for choosing between getters and empty-parentheses methods
- Clarify block syntax for single-expression functions and chaining
- Delete the empty "Application Lifecycle" page (was just a TODO placeholder)
- Expand "Storing C Data" from stub to full documentation covering foreign classes, initialization, access, and finalization
- Add note that VM is not re-entrant; warn against calling wrenCall/wrenInterpret from foreign methods
- Fix broken cross-reference links (configuring-the-vm.html, wren.hpp include)
- Clarify slot API usage: remove confusing sentence about implicit return of receiver
- Fix grammar: "each VM them differently" → "each VM differently", "is only be called" → "is only called"
- Improve phrasing throughout for clarity and consistency
Replace `Meta.eval()` to compile source into a fiber instead of a function, fixing issue #456 where top-level variable declarations failed in the REPL. Add `Stdout` import and flush stdout before reading stdin since `System.print()` no longer auto-flushes. Refactor token detection to use `lexFirst()` instead of full `lex()`, and add new `Meta.compile()` method returning a fiber. Internally rename `wrenNewString` to `wrenNewStringLength` with explicit length parameter, updating all call sites across compiler, core, and meta modules.
Add a new `servedocs` Makefile target that runs `generate_docs.py --serve`, enabling continuous doc generation and local web serving. Extend the Python script with `RootedHTTPServer` and `RootedHTTPRequestHandler` classes to serve generated HTML files from the output directory, refreshing content on each request via `format_files(True)`. Also update the shebang to `python3` and change the conversion print message from "converted" to "Built".
The comment in the WrenForeignClassMethods struct incorrectly referenced
`wrenAllocateForeign` instead of the actual function `wrenSetSlotNewForeign()`.
This fixes the documentation to match the correct API function name that must
be called exactly once inside the allocate callback body.
Remove the automatic fflush(stdout) call from the write() function in vm.c, which was causing gratuitous performance overhead on every System.write() invocation. Introduce a new Stdout class with a foreign static flush() method that delegates to fflush(stdout), giving users explicit control over when output is flushed. Update the io module registration in modules.c to include the Stdout class and bump MAX_CLASSES_PER_MODULE from 5 to 6. Add documentation for Stdout in doc/site/modules/io/stdout.markdown, update the io index and template to list the new class, and add flush() usage notes to the Stdin readByte() and readLine() docs. Implement the stdoutFlush() foreign function in io.c.
Rename the internal `ClassCompiler` struct typedef to `ClassInfo` to better reflect its purpose as a descriptor for the enclosing class context during compilation. Update all variable declarations, function signatures, and references throughout `wren_compiler.c` to use the new type name, including in `getEnclosingClass`, `field`, `super_`, and `declareMethod` functions. This resolves issue #469 by eliminating the misleading "Compiler" suffix from a type that tracks class metadata rather than compilation state.
These test cases cover malformed class declarations, invalid string literals,
corrupted identifiers, and various edge cases that previously caused crashes
but now produce expected parse errors.
The compiler previously relied on `match(TOKEN_RIGHT_BRACE)` in the while loop condition, which consumed the brace and made it impossible to detect a missing one. Changed to peek-based loop termination and added explicit `consume` call for the closing brace, ensuring proper error reporting when '}' is absent. Added regression test for issue #429.
Add parentheses around the `count` parameter in both `ALLOCATE_FLEX` and
`ALLOCATE_ARRAY` macro definitions to prevent operator precedence bugs when
the argument is an expression. Without this fix, expressions like
`sizeof(type) * n + 1` would be evaluated incorrectly due to `*` having
higher precedence than `+`.
When the fiber's stack is reallocated, pointer subtraction between old and new stack
addresses is undefined behavior. Instead of computing an offset and adding it to each
pointer, recalculate each pointer relative to the new stack base using well-defined
arithmetic within the single array. This affects the apiStack, call frame stackStart
pointers, open upvalue values, and the stackTop pointer.
Implement the `round` method on the Num class in the Wren VM, which rounds a number to the nearest integer using standard rounding rules (away from zero for .5). The implementation adds a new `DEF_NUM_FN(round, round)` macro invocation in `wren_core.c`, registers the corresponding primitive `num_round`, and includes comprehensive documentation in the core module reference. A new test file `test/core/number/round.wren` validates behavior for positive, negative, zero, and fractional values. Also adds Kyle Charters to the AUTHORS file.
In runtimeError, walk the entire fiber call chain and set each fiber's error field to the same error value, unhooking callers as we go. Previously only the immediate caller was considered, leaving intermediate fibers in an inconsistent state. This ensures that when a fiber aborts, every fiber in the chain up to (but not including) the one that catches the error via try() is properly marked as errored.
Also remove the old nested fiber tests from try.wren and add a new comprehensive test (try_through_call.wren) that verifies the percolation behavior through multiple levels of fiber calls and confirms that intermediate fibers carry the error while the catching fiber and its callers remain clean.
Move the aborted fiber check in runFiber to execute before the "already called" check, ensuring a clear error message for aborted fibers. In runtimeError, replace the single caller unhook with a loop that walks the fiber chain, preserving the callerIsTrying flag and only unhooking fibers until a try-catch boundary is found, enabling proper error propagation through nested fiber calls. Add test cases for one and two levels of nested fiber try calls.
The off-by-one error caused the arch argument to be read from args[2] instead of args[1], which would either read an out-of-bounds index or pick the wrong argument when exactly two arguments were provided. This fix ensures the optional architecture parameter is correctly retrieved from the second command-line argument.
Remove dynamic dependency download during build by checking in libuv source and GYP build tooling. Update .gitignore to exclude intermediate build artifacts from the vendored deps directory, adjust Makefile to remove the now-unnecessary cleanall target and deps folder cleanup, and add the full libuv project tree including its own .gitignore, .mailmap, AUTHORS, CONTRIBUTING.md, ChangeLog, and LICENSE files.
The embedding API reference link was pointing to the old `embedding-api.html` path, which would result in a 404. Updated it to the correct `embedding/` path to ensure users can access the documentation.
The deleted test file `test/core/range/floating_point.wren` was a direct copy of the integer range test file, testing `.from` on integer ranges rather than actual floating-point ranges. This removal resolves issue #438 by eliminating the redundant test that provided no coverage for floating-point range behavior.
Delete the entire util/msvc2013 directory containing Visual Studio 2013 solution and project files. Add new util/vs2017 directory with updated solution targeting Visual Studio 2017 (v141 toolset) and supporting both Win32 and x64 platforms. Update .gitignore to ignore .vs/ and obj/ directories. Modify build_libuv_windows in util/libuv.py to accept an arch parameter and pass x86 or x64 to vcbuild.bat.