Commit Graph
100 Commits
Author SHA1 Message Date
Bob Nystrom e0984a5012 fix: require parentheses for zero-argument join() method on Sequence
The zero-argument overload of `join` on `Sequence` was previously defined as a
getter-style method without parentheses. This change makes it a regular method
that requires explicit parentheses, consistent with the one-argument `join(sep)`
variant and standard Wren method syntax. The implementation now reads
`join() { join("") }` instead of `join { join("") }`.

All call sites in tests and documentation are updated accordingly.
2015-09-16 14:15:48 +00:00
Bob Nystrom ffe87c271d feat: add configurable write callback for System.print output delegation
Add a `WrenWriteFn` callback to `WrenConfiguration` that allows host applications to control how text from `System.print()` and related functions is displayed. When set, the VM invokes this callback instead of directly calling `printf`. If the callback is NULL, printed text is silently discarded. The CLI's `initVM()` now registers a simple `write` function that prints to stdout, while the core `system_writeString` primitive checks for the callback before outputting. This change also refactors `wrenInitConfiguration` to set `defaultReallocate` as the default reallocation function and consolidates configuration fields into a single `WrenConfiguration` struct stored directly in `WrenVM`, removing separate member fields for reallocate, bindForeignMethod, bindForeignClass, loadModule, minNextGC, and heapScalePercent.
2015-09-16 06:01:43 +00:00
Bob Nystrom aa72900a9e feat: replace IO class with System class and remove separate IO module
- Delete wren_io.c, wren_io.h, and io.wren source files
- Remove multi-arity print overloads and IO.read/IO.time methods
- Add System class with print, printAll, write, writeAll methods to core.wren
- Update all documentation examples and README to use System.print instead of IO.print
2015-09-15 14:46:09 +00:00
Bob Nystrom f12581a674 refactor: merge io.c file I/O and module resolution functions into vm.c
Remove the separate io.c and io.h source files, inlining their static helper functions (readFile, wrenFilePath, readModule, setRootDirectory) directly into vm.c. This frees io.c as a dedicated built-in module slot and eliminates the cross-file dependency on io.h from main.c, test/api/main.c, and the Xcode/make build systems.
2015-09-14 05:29:47 +00:00
Bob Nystrom 34bcc6bd2d feat: add scheduler module and refactor built-in module loading into shared modules.c
Introduce a new scheduler module with fiber-based cooperative multitasking, including native bindings for resume operations and a Wren class for scheduling callables. Refactor the existing timer module and CLI code to use a centralized built-in module registry in modules.c, replacing direct includes of timer.h and timer.wren.inc. Update Xcode project and Makefile to compile the new scheduler.c, modules.c, and their generated .wren.inc sources.
2015-09-13 18:32:39 +00:00
Bob Nystrom 95626bb136 feat: replace inline C string literals with auto-generated .wren.inc includes
Replace the manually embedded C string constants for builtin Wren modules with
a new build system that automatically generates `.wren.inc` header files from
`.wren` source files. The old `script/generate_builtins.py` is removed and
replaced by `script/wren_to_c_string.py`, which produces standalone include
files with a `PREAMBLE` containing the module name and source path. The Makefile
gains pattern rules to rebuild these `.wren.inc` files whenever the
corresponding `.wren` source changes, and the `builtin` phony target is removed
since the generation is now automatic. The `wren.mk` wildcard lists are updated
to include the new `.wren.inc` files as dependencies. The `timer.c` and
`wren_core.c` source files now `#include` their respective `.wren.inc` headers
instead of defining the string literals inline, and the `timer.wren` trailing
newline is removed.
2015-09-13 17:03:02 +00:00
Bob Nystrom 95ec9c63bd fix: correct platform.system() call by removing incorrect arch argument in Windows branch 2015-09-12 17:45:18 +00:00
Bob Nystrom eba4911485 fix: error when class inherits from null instead of defaulting to Object
Previously, inheriting from null would silently fall back to Object superclass. Now validates superclass and raises runtime error if null is provided. Refactored defineClass to remove implicit null-to-Object fallback, added loadCoreVariable helper for module-level core imports, and updated CLASS/FOREIGN_CLASS opcode comments to reflect that null is no longer a valid superclass. Added test case for inherit_from_null.
2015-09-12 17:14:04 +00:00
Bob Nystrom 9b002c6d67 fix: replace string length calls with counter in map_string benchmarks across all languages 2015-09-12 16:59:30 +00:00
Bob Nystrom e0fda5e315 docs: clarify string encoding and indexing terminology in core string docs 2015-09-12 16:42:31 +00:00
Bob Nystrom c5cea469e3 docs: clarify string is byte array, move .count to codePoints.count, remove O(n) primitive
The string class is now documented as an immutable byte array rather than a
sequence of Unicode code points. The .count getter is removed from the string
primitive and replaced by .codePoints.count on the code point sequence
interface, making the O(n) cost explicit. Updated the doc site and test files
accordingly.
2015-09-12 04:33:26 +00:00
Bob Nystrom 85750ca338 feat: add StringCodePointSequence class and expose codePoints property on String
Extract codePointAt() logic into a dedicated StringCodePointSequence class that wraps a string and implements the Sequence interface, enabling iteration over code points. Add a `codePoints` getter to String that returns a new instance of this sequence. Refactor the underlying C implementation of `codePointAt_` to decode UTF-8 into actual code point integers (returning raw bytes for invalid sequences) and rename the primitive to use trailing underscore convention. Update all related tests to reflect the new behavior where mid-sequence byte indices return the raw byte string instead of an empty string, and add new test files for the code point sequence iteration.
2015-09-11 14:56:01 +00:00
Bob Nystrom 731e1f4b1d feat: replace public byteAt with private byteAt_ and add O(1) bytes.count
Remove the public `byteAt(_)` method from String and its ByteSequence wrapper, renaming it to the private `byteAt_(_)` to eliminate redundancy with `.bytes[_]`. Add a native `byteCount_` primitive on String and expose it as `count` on StringByteSequence, enabling O(1) byte length queries. Update all test files to use the new `.bytes` subscript API and add a dedicated `count.wren` test for the new functionality.
2015-09-11 06:52:18 +00:00
Bob Nystrom 0397da2451 refactor: pass value directly to emitConstant instead of relying on parser state
Refactor emitConstant to accept a Value parameter, removing the implicit dependency on compiler->parser->value. Update all call sites to pass the value explicitly, improving encapsulation and making the function's data flow clearer.
2015-09-09 13:44:26 +00:00
Bob Nystrom 21765218c4 fix: correct wrenUtf8DecodeNumBytes signature to accept single byte and fix range subscript bug
The function was previously taking a string and index, then indexing into the string internally. Changed to accept the byte directly, which fixes incorrect behavior when wrenNewStringFromRange and wrenStringCodePointAt passed a raw byte value instead of a string pointer. Also fixed a typo in wrenNewStringFromRange where wrenUtf8EncodeNumBytes was called instead of wrenUtf8DecodeNumBytes.
2015-09-09 03:59:47 +00:00
Bob Nystrom a619851cf2 feat: implement UTF-8 aware string subscript ranges with new wrenNewStringFromRange helper
Add wrenNewStringFromRange function to wren_value.c that decodes UTF-8 code points from source string and re-encodes them into result, enabling correct range subscripts on multi-byte characters. Rename wrenUtf8NumBytes to wrenUtf8EncodeNumBytes and make wrenUtf8Encode return written byte count for use in range construction. Add wrenUtf8DecodeNumBytes utility to skip continuation bytes when iterating by byte index. Remove all skip directives from test files and add UTF-8 specific test cases verifying correct slicing across code point boundaries.
2015-09-02 05:14:55 +00:00
Bob Nystrom ef93496fd4 fix: remove default constructors and require explicit construct new() for all user classes
The compiler no longer auto-generates a default `new()` constructor for classes. All classes must now explicitly define `construct new() {}` to be instantiable. This change removes the `createDefaultConstructor` function from the compiler, eliminates the `return_this` primitive used by Object's default initializer, and adds explicit constructors to all test and example classes. Core metaclasses (Bool, Class, Null, Num, Object, Range, Sequence) now correctly reject `new()` calls with runtime errors.
2015-09-01 15:16:04 +00:00
Bob Nystrom 4665ec1913 feat: implement foreign object finalization and expose wrenCollectGarbage API
Add finalizer invocation for foreign objects during garbage collection by calling wrenFinalizeForeign in wrenFreeObj. Expose wrenCollectGarbage as a public API function and update internal calls accordingly. Ensure the "<finalize>" symbol is always registered in the symbol table even when no finalizer is provided. Add test fixtures for Resource class with finalizer and Api.gc/Api.finalized methods to verify finalization behavior across multiple GC cycles.
2015-09-01 04:56:21 +00:00
Bob Nystrom 2a8847fa57 feat: replace WrenMethod with WrenValue for method handles and update wrenCall signature to return WrenInterpretResult 2015-08-31 14:57:48 +00:00
Bob Nystrom c0d90460f0 fix: remove redundant ignoreNewlines call after list instantiation in wren_compiler.c
The ignoreNewlines() call following list instantiation via callMethod(compiler, 0, "new()", 5) was redundant because the subsequent do-while loop for compiling list elements already handles newline skipping internally. Removing this duplicate call eliminates unnecessary parser state manipulation without affecting list compilation behavior.
2015-08-31 14:46:17 +00:00
Bob Nystrom 075f487b6e refactor: restructure list/map compilation loops and extract syntax error tests
- Convert list() and map() compiler functions from if/do-while to do-while loops
- Remove redundant empty literal handling by breaking on right bracket/brace
- Add new test files for duplicate comma, duplicate trailing comma, and empty list/map with comma
- Expand newlines test to cover trailing comma and empty list/map cases
- Simplify trailing_comma tests by removing inline syntax error checks
- Update Test.fail() to handle variable arguments without kwargs
2015-08-31 14:23:36 +00:00
Bob Nystrom 6b40c5b3f5 docs: update README and site docs to clarify VM vs CLI separation and mention libuv dependency 2015-08-31 05:38:40 +00:00
Bob Nystrom 7e111d19da feat: replace fiber run() with transfer() and suspend() for scheduler-friendly semantics
Remove the run() method from fibers and introduce transfer() for non-stack-based fiber switching, along with suspend() to pause the interpreter and return control to the host application. Update Timer.sleep() to use runNextScheduled_() instead of Fiber.yield(), and add Timer.schedule() for creating independently scheduled fibers. Refactor the core fiber runtime to support transfer semantics, including proper error handling for aborted fibers and self-transfer edge cases. Fix a missing quote in test.py's runtime error validation string.
2015-08-31 05:15:37 +00:00
Bob Nystrom ca8e97521a feat: add Alexander Roper to AUTHORS and expand embedding API documentation
- Add Alexander Roper to AUTHORS file with newline fix for Starbeamrainbowlabs entry
- Replace placeholder embedding API docs with full guide covering static/dynamic linking and source inclusion
- Update codebase line count from 5,000 to 7,000 lines in README and index
- Fix relative documentation links to absolute URLs in README
- Add CSS styling for preprocessor directive syntax highlighting
- Update Xcode project file references and CopyFiles build phase UUID
- Adjust delta_blue benchmark expected value from 7032700 to 14065400
- Improve markdown header detection regex in generate_docs.py to avoid matching #include
- Refactor metrics.py to exclude curly brace lines from code line counting
- Add TEST_HEADERS dependency to test object compilation in wren.mk
- Remove NULL parameter from runFile call in main.c
- Refactor vm.c to support WrenBindForeignClassFn callback and rename externalBindForeign to bindMethodFn
- Update vm.h to remove bindForeign parameter documentation and adjust runFile signature
2015-08-29 06:13:56 +00:00
Bob Nystrom 4de5d75fc6 fix: install g++-multilib package for 32-bit C++ standard library support on Travis CI 2015-08-29 03:25:26 +00:00
Bob Nystrom 3253c54eda fix: print captured stdout/stderr output when libuv build command fails 2015-08-29 03:14:55 +00:00
Bob Nystrom f0cd0e854e feat: add architecture-specific target flags to libuv Linux build script
Add conditional -Dtarget_arch flag to gyp_uv.py invocation in
build_libuv_linux() to support ia32 for 32-bit and x64 for 64-bit
architectures, enabling cross-compilation for all Linux targets.
2015-08-29 02:49:19 +00:00
Bob Nystrom f95436f640 refactor: move libuv download to deps/ and build per-arch static libs
Move libuv download location from build/ to deps/ so that make clean does not
remove the downloaded source. Introduce per-architecture libuv static library
naming (build/libuv-32.a, build/libuv-64.a) and pass arch parameter through
build_libuv_linux and build_libuv functions. Add cleanall target to remove
deps/ separately from build artifacts.
2015-08-29 02:31:03 +00:00
Bob Nystrom eb1bcb35d1 fix: align libuv output directory path across Mac and Linux builds
Set BUILD_DIR=out in xcodebuild invocation for Mac and remove conditional LIBUV_BUILD variable, so both platforms consistently use build/libuv/out/Release/libuv.a instead of Mac using build/libuv/build/Release/libuv.a.
2015-08-27 14:55:12 +00:00
Bob Nystrom bd0957dc48 fix: double delta_blue benchmark iterations and update expected result
The delta_blue benchmark was updated to run 40 iterations instead of 20 in both the Python and Wren implementations, and the expected benchmark result was adjusted from 7032700 to 14065400 to match the doubled workload. Additionally, the Wren source was cleaned up by removing forward declaration placeholders for global variables and converting them to proper `var` declarations with immediate initialization.
2015-08-27 13:25:24 +00:00
Bob Nystrom 674f682ce1 style: reorder single-char token cases in nextToken and fix wren_utils.h comment 2015-08-22 14:56:38 +00:00
Bob Nystrom 69c328c575 fix: exclude brace-only lines from empty line count in metrics script 2015-08-22 14:27:32 +00:00
Bob Nystrom 4f053e7a3c feat: add matchChar helper and refactor twoCharToken, skipBlockComment, readNumber, and nextToken to use it 2015-08-22 06:08:11 +00:00
Bob Nystrom e4adcd5c5b feat: store number and string literals directly as Value in parser struct
Replace the separate `string` ByteBuffer and `number` double fields in the Parser struct with a single `value` field of type Value. This unifies literal storage, simplifies the parser's state, and eliminates the need for separate buffers and conversion logic for different literal types.

The change modifies `makeNumber` to store parsed numbers as `NUM_VAL` directly into `parser->value`, and adds a guard in `addConstant` to return -1 early if the parser has encountered an error.
2015-08-22 05:54:30 +00:00
Bob Nystrom b289ef4195 fix: update Wren codebase size estimate from 5k to 7k lines in README
The README.md previously stated the Wren codebase was approximately 5,000 lines,
but the actual codebase has grown to around 7,000 lines. This commit corrects
the line count in the introductory bullet point to reflect the current size.
2015-08-21 05:34:42 +00:00
Bob Nystrom 6fa0e8cc0a docs: update Wren codebase line count from 5,000 to 7,000 in index.markdown
The line count reference in the documentation was outdated; updated the
stated codebase size from 5,000 to 7,000 lines to reflect current
repository growth.
2015-08-21 05:34:33 +00:00
Bob Nystrom 3b49ded36e docs: update Wren codebase line count from 5000 to 7000 in README 2015-08-21 05:34:08 +00:00
Bob Nystrom 16613c678b fix: rename constructor initializer keyword from "this" to "init" across compiler, core, and documentation
Rename the constructor initializer signature prefix from "this " to "init " in
wren_common.h's MAX_METHOD_SIGNATURE calculation, wren_compiler.c's
signatureToString and createDefaultConstructor functions, and wren_core.c's
default Object constructor primitive registration. This changes the syntactic
keyword used to define initializer methods in the Wren language.
2015-08-21 05:30:44 +00:00
Bob Nystrom 869ecb9f07 fix: correct error message and comment to use 'construct' instead of 'this' in constructor methods 2015-08-21 05:23:53 +00:00
Bob Nystrom 087649abc5 fix: replace free with uv_close in timer callback and fix strncpy off-by-one
The timerCallback function previously freed the uv_timer_t handle directly after completion, which could cause undefined behavior if libuv still needed the handle. Now it properly calls uv_close with a new timerCloseCallback that frees the handle after the close operation finishes. Additionally, the strncpy call in timerGetSource was copying only length bytes without the null terminator; it now copies length + 1 bytes to ensure proper null termination of the returned source string.
2015-08-21 05:09:52 +00:00
Bob Nystrom aa3c1308b8 style: reformat subprocess.check_call args in remove_dir for readability 2015-08-21 05:08:39 +00:00
Bob Nystrom 149da8fc9a feat: add libuv dependency and Windows build support to MSVC project
Add libuv library path to both Debug and Win32 configurations in the MSVC project file, include timer module source and header files in the project filters, and implement the Windows libuv build script by calling vcbuild.bat instead of exiting with an unimplemented error. Also add a cross-platform remove_dir helper to handle directory cleanup on Windows where shutil.rmtree fails on readonly files.
2015-08-21 05:07:34 +00:00
Bob Nystrom 80f60f385d fix: correct test name from 'should_process_empty_input' to 'should_handle_empty_input' 2015-08-21 05:04:42 +00:00
Bob Nystrom f2ba534704 feat: add scientific notation parsing for number literals in wren compiler
Implement support for scientific notation (e.g., 2.55e2, 1.2e-3) in the Wren compiler's number lexer. The readNumber function now handles 'e'/'E' exponent markers with optional negative sign, emitting a lex error for unterminated exponents. Added comprehensive test cases covering valid scientific literals, missing exponents, fractional parts, and multiple exponent markers. Also added Alexander Roper to AUTHORS and removed related TODO comments.
2015-08-21 05:03:19 +00:00
Bob Nystrom e24aba2644 docs: replace placeholder embedding API page with full configuration and hosting guide 2015-08-21 05:02:13 +00:00
Bob Nystrom 83fbc7b27f fix: enable 32-bit Mac libuv build and add explicit Linux pthread/rt linking 2015-08-16 17:28:55 +00:00
Bob Nystrom ef721ee355 build: link rtlib to wren binary and test executable for timer support 2015-08-16 16:59:53 +00:00
Bob Nystrom 66c6987270 fix: move library flags after object files in linker commands for wren.mk 2015-08-16 16:57:47 +00:00
Bob Nystrom 33df26d181 chore: switch C standard from c99 to gnu99 and reorder linker flags in wren.mk
- Changed C_OPTIONS from -std=c99 to -std=gnu99 to enable GNU C99 extensions
- Reordered linker flags in bin/$(WREN) and test targets: moved -lm before -lpthread and object files before libraries to fix potential linking order issues
2015-08-16 16:55:50 +00:00
Bob Nystrom b1d94e945b refactor: replace libuv dynamic link with object inclusion in wren.mk build rules
Remove the LIB_UV_LINK variable that used -luv and -lpthread flags for linking, and instead pass the libuv static object directly via $^ in the bin/wren and test/wren link commands. This changes the linking strategy from dynamic library to object inclusion, simplifying the build and avoiding external library dependencies at link time.
2015-08-16 16:40:02 +00:00
Bob Nystrom aa5a4ee755 fix: replace automatic $^ expansion with explicit object lists in wren.mk link rules
The linker rules for both the main wren binary and the test binary were using
the automatic variable $^ which included libuv.a as a prerequisite. This
caused libuv.a to be passed as an object file to the linker, leading to
unnecessary static library inclusion. The fix explicitly lists only the
required object file groups (CLI_OBJECTS, MODULE_OBJECTS, VM_OBJECTS) and
the test-specific cli/io.o and cli/vm.o, removing libuv.a from the link
invocation while keeping it as a build dependency via LIBUV.
2015-08-16 16:36:17 +00:00
Bob Nystrom 0aaf3eca7b fix: reorder libuv link flags and remove silent @ prefix from link commands
Reorder -luv before -lpthread in LIB_UV_LINK to fix potential linker ordering issues on some systems, and remove the @ prefix from the bin/ and test/ link commands to allow verbose output during linking.
2015-08-16 16:16:26 +00:00
Bob Nystrom 4d175783d7 fix: move pthread flag from global CFLAGS to libuv link step for Linux builds
The -pthread compiler flag was removed from the global CFLAGS and instead
incorporated into a new LIB_UV_LINK variable that includes -lpthread alongside
the libuv library path. This change applies the pthread linking only to
executables that depend on libuv (the CLI binary and test binary), rather than
to all compilation units, preventing potential issues with modules or static
library builds that do not require threading support.
2015-08-16 16:07:41 +00:00
Bob Nystrom 8d315517e5 fix: update relative links to absolute URLs for getting-started and contributing pages in README 2015-08-16 02:58:42 +00:00
Bob Nystrom 2dc209e585 feat: add foreign class support with allocation, construct opcodes, and CLI callback wiring
Implement the initial infrastructure for foreign classes in the Wren VM, including new opcodes (FOREIGN_CONSTRUCT, FOREIGN_CLASS), a WrenBindForeignClassFn callback type in the public API, and updated CLI vm.c to store and forward foreign binding callbacks via setForeignCallbacks(). The compiler now tracks whether a class is foreign via a new isForeign flag in ClassCompiler, emits CODE_FOREIGN_CONSTRUCT instead of CODE_CONSTRUCT for foreign class constructors, and errors on field definitions inside foreign classes. The debug dump and opcode header gain entries for the new opcodes, and wrenBindSuperclass handles the -1 numFields sentinel for foreign classes to prevent field inheritance from superclasses.
2015-08-15 19:07:53 +00:00
Bob Nystrom 7551fa8c9b refactor: consolidate per-test subdirectories into flat test/api structure with merged returns and value files 2015-08-13 16:09:27 +00:00
Bob Nystrom 85487d9d8c feat: enable pthread flag for gcc builds on non-macOS platforms
Add -pthread to CFLAGS in the Linux/Unix shared library build path
to ensure proper thread support when compiling with gcc, which does
not enable it by default unlike some other compilers.
2015-08-08 16:14:52 +00:00
Bob Nystrom 283c64d713 fix: bump _XOPEN_SOURCE to 600 for libuv compatibility on Linux
The previous value of 500 was insufficient for libuv's POSIX requirements,
causing compilation failures on Linux systems. Upgrading to 600 ensures
the necessary POSIX 2004 extensions are available, allowing libuv to
function correctly with the build system.
2015-08-08 16:06:40 +00:00
Bob Nystrom fc745b43ed feat: add CLI_FLAGS variable with _XOPEN_SOURCE=500 and consolidate include paths for cli, module, and test targets 2015-08-08 15:57:57 +00:00
Bob Nystrom 0f4d3025b8 fix: adjust libuv build paths for Linux output directory and parameterize in Makefile 2015-08-08 14:40:27 +00:00
Bob Nystrom 408ded555d fix: change libuv Linux build directory from 'out' to 'build' in build_libuv_linux
The build_libuv_linux function previously used the 'out' directory for the make
command, but now correctly targets the 'build' directory to match the output
generated by gyp_uv.py on Linux.
2015-08-08 14:20:07 +00:00
Bob Nystrom 664a166d6c feat: add input validation and stack trace filtering for Timer.sleep
Add type and range checks to Timer.sleep() in both C source and Wren
implementation, aborting with descriptive errors for non-numeric or
negative arguments. Introduce six new test files covering sleep with
fibers, float durations, main fiber, zero milliseconds, negative
values, and non-numeric input. Fix stack trace parsing in test runner
to skip builtin library frames by iterating through error lines until
a main-line match is found.
2015-08-08 14:17:30 +00:00
Bob Nystrom 810da1f0fc feat: add libuv event loop integration with timer module and CLI restructuring
Add a vertical slice of real libuv integration by introducing a "timer" CLI module with a Timer class and static sleep() method. This required significant infrastructure changes: setting up libuv event loop in the CLI, creating a new src/module directory for CLI modules, updating all build scripts (Makefile, wren.mk, Xcode project) to handle the new module compilation, and reorganizing CLI code by moving REPL logic from main.c to vm.c. The generate_builtins.py script was also updated to support copying Wren sources into the module directory.
2015-08-07 15:10:55 +00:00
Bob Nystrom e7bdca2cfa feat: add 'v' type specifier to wrenCall for passing WrenValue arguments
- Extend wrenCall's variadic argument handling to accept 'v' type specifier,
  which passes a previously acquired WrenValue* without releasing it.
- Update documentation comment in wren.h to describe the new 'v' argument type.
- Fix parameter counting in makeCallStub to correctly parse parenthesized
  signatures by scanning backwards from the closing parenthesis.
2015-08-07 14:57:32 +00:00
Bob Nystrom f9f8b55b29 feat: add support for passing WrenValue pointers as 'v' type argument to wrenCall
Extend the wrenCall variadic argument handling to accept a new 'v' type specifier,
which allows callers to pass a previously acquired WrenValue* directly without
implicitly releasing it. This enables reusing existing Wren values across multiple
calls without unnecessary string or number conversions.

The implementation reads a WrenValue* from the variadic arguments and extracts
its internal Value for the call. Additionally, fix the parameter counting logic
in makeCallStub to correctly count underscore parameters only within the
parenthesized signature portion, preventing off-by-one errors for methods with
trailing parentheses in their signature strings.
2015-08-07 14:57:23 +00:00
Bob Nystrom 81ffd6e001 feat: add WrenValue handle API for persistent GC-rooted object references
Introduce a new `WrenValue` handle type that allows C code to hold a persistent reference to a Wren object, preventing garbage collection until explicitly released. The implementation adds a doubly-linked list of value handles to the VM, integrates them into the garbage collector's marking phase, and provides `wrenGetArgumentValue`, `wrenReleaseValue`, and `wrenReturnValue` functions. The commit also includes a new `get_value` API test that exercises storing and retrieving a value across GC cycles, and refactors the test registration macro to use camelCase naming for consistency across all existing API tests.
2015-08-07 06:15:55 +00:00
Bob Nystrom 592772a97d feat: add WrenValue handle API for persistent object references outside VM
Introduce WrenValue type and wrenGetArgumentValue/wrenReleaseValue functions to allow C code to hold GC-safe references to Wren objects across foreign calls. Implement doubly-linked list management in VM struct, mark value handles during garbage collection, and add assertion in wrenFreeVM to detect unreleased values. Update test infrastructure with new get_value test case and rename existing test binding functions to camelCase convention.
2015-08-07 05:24:15 +00:00
Bob Nystrom 7eb6ea6b4f feat: expose core module pointer and fix map tombstone reuse in Wren VM
Refactor `signatureFromToken` to return a `Signature` struct instead of mutating a pointer parameter, enabling cleaner method call signature construction in the compiler. Expose `wrenGetCoreModule` as a public API function and update `defineClass`, `wrenFindVariable`, and `wrenLoadMetaLibrary` to accept an explicit `ObjModule*` parameter, removing the implicit core module assumption. Fix a critical bug in `addEntry` where tombstone entries were not immediately reused for new key-value pairs, causing potential infinite loops during map insertion. Add a regression test `test/core/map/churn.wren` that verifies correct map behavior under heavy insert/remove churn.
2015-08-07 04:37:13 +00:00
Bob Nystrom 8468ca7642 fix: fully initialize Signature struct fields in signatureFromToken and methodCall 2015-08-06 14:34:19 +00:00
Bob Nystrom 45c717b11b feat: add module parameter to wrenFindVariable and expose wrenGetCoreModule
Refactor wrenFindVariable to accept an explicit ObjModule* parameter instead of
implicitly using the main module. Promote the internal getCoreModule helper to
a public wrenGetCoreModule function declared in wren_vm.h. Update all call sites
in wren_core.c and wren_meta.c to pass the core module when looking up core
variables, and replace inline getCoreModule calls in wren_vm.c with the new
public function. Remove the NULL-module fallback documentation from
wrenDeclareVariable and wrenDefineVariable.
2015-08-06 14:13:11 +00:00
Bob Nystrom 5e7ea2f135 fix: correct tombstone handling in map insertion to prevent deadlock
The addEntry function was incorrectly skipping tombstone entries when inserting new keys, causing the map to fill up with tombstones and eventually deadlock on insert. The fix removes the tombstone check that prevented overwriting tombstone slots with new entries, allowing proper reuse of removed entries.

A regression test (test/core/map/churn.wren) was added to verify that inserting and removing entries in a loop correctly maintains the map count without deadlocking.
2015-08-06 13:55:30 +00:00
Bob Nystrom 0b1098f56a fix: set working directory to LIB_UV_DIR for Linux libuv make invocation
The build_libuv_linux function previously ran the make command without
specifying a working directory, causing it to execute relative to the
current process directory. This change adds the cwd parameter to the
run call, ensuring make operates inside the correct LIB_UV_DIR path
where the out directory exists.
2015-08-02 17:58:27 +00:00
Bob Nystrom a96f756d24 feat: implement Linux build for libuv by running gyp and make
Replace the stub that printed "not implemented" and exited with actual build
steps: invoke gyp_uv.py to generate Makefiles, then run make in the out/
directory. This enables libuv compilation on Linux targets.
2015-08-02 17:56:44 +00:00
Bob Nystrom e24d9ef0c3 feat: integrate libuv as external dependency for CLI and add separate vm build target
Add a Python script to download and compile libuv v1.6.1, hook it into the Makefile so release and debug targets depend on the static library, and link libuv when building the CLI interpreter. Introduce a new "vm" target that builds only the VM library without requiring libuv. Update the Xcode project to link libuv.a into the executable.
2015-08-02 17:43:38 +00:00
Bob Nystrom 7d9e45e906 feat: replace 'this' keyword with 'construct' for constructor definitions across core lib, compiler, docs, and tests
Add TOKEN_CONSTRUCT as a new reserved word in the Wren compiler lexer and parser, and update the grammar rule table so that 'construct' triggers a constructor signature instead of 'this'. Modify all built-in class definitions in core.wren, wren_core.c, benchmark files, and test fixtures to use 'construct new(...)' and 'construct named(...)' syntax. Update documentation in classes.markdown and syntax.markdown to reflect the new keyword, and remove the deprecated test files for 'new' and infix class expressions.
2015-07-21 14:24:53 +00:00
Bob Nystrom 847edd8e1e fix: correct Fiber instantiation syntax in README code example
The example previously used `new Fiber { ... }` which is incorrect Wren syntax; changed to `Fiber.new { ... }` to match the language's constructor pattern.
2015-07-20 14:34:30 +00:00
Bob Nystrom 67f1480bf0 chore: migrate Travis CI to container-based builds and update README links
- Switch Travis CI from sudo-based apt-get to addons.apt.packages for gcc-multilib
- Enable container-based builds with `sudo: false`
- Update README.md call-to-action links to point to getting-started and browser playground
- Replace `printList_` with `printAll` in IO class and remove redundant `IO.` prefixes
- Add IO.read() method documentation and update IO.print docs for up to 16 arguments
- Reorganize community page with Libraries, Language bindings, and Tools sections
- Add wrenjs JavaScript binding and Sublime Text syntax highlighting
- Fix typo "no where" to "nowhere" in fibers documentation
- Add indentation to preprocessor defines in wren_common.h for consistency
- Remove unreachable `return 0` after UNREACHABLE() in wren_compiler.c
- Fix Windows color output by wrapping text in str() in test script
2015-07-19 19:49:23 +00:00
Bob Nystrom 33560c3824 fix: correct attribute reference and type coercion in test runner error handling
- Fix `validate_runtime_error` to reference `self.runtime_error_message` instead of undefined `runtime_error_message`
- Ensure `color_text` returns `str(text)` on Windows to avoid type mismatch when non-string input is passed
2015-07-19 17:31:55 +00:00
Bob Nystrom bb7ce3b10a refactor: extract inline helper for retrieving ObjFn from CallFrame
Replace three duplicated switch-on-type patterns (in wrenDebugPrintStackTrace, wrenAppendCallFrame, and runInterpreter) with a single static inline wrenGetFrameFunction that handles OBJ_FN and OBJ_CLOSURE cases with an UNREACHABLE default.
2015-07-19 17:16:54 +00:00
Bob Nystrom 177d53fe68 fix: align preprocessor indentation and remove dead code after UNREACHABLE in non-nan-tagged and non-computed-goto modes 2015-07-19 17:16:27 +00:00
Bob Nystrom 4c79185a3d fix: correct argument in test runner fail call to show expected error message
The diff shows that in `script/test.py`, the `self.fail()` call on line 158 was passing `runtime_error_message` (the actual error) instead of `self.runtime_error_message` (the expected error) when formatting the failure message. This fix swaps the argument to display the correct expected error string in the test output.
2015-07-19 16:33:00 +00:00
Bob Nystrom ef4b2f90f7 fix: correct typo "no where" to "nowhere" in fibers documentation
The diff fixes a single-word typo in the fibers documentation markdown file,
changing the incorrect two-word phrase "no where" to the correct compound word
"nowhere" in the sentence explaining why the first value sent to a fiber is ignored.
2015-07-19 16:10:42 +00:00
Bob Nystrom 0c336449e3 fix: correct punctuation in TODO comment and fix brace placement in ioRead function 2015-07-18 21:17:39 +00:00
Bob Nystrom bcd4df7e25 feat: make IO.printAll public and require parentheses on IO.read
Rename private `printList_` to public `printAll` across all overloaded `IO.print` methods in both Wren source and embedded C string. Update `IO.read` to require explicit `()` call syntax in test and documentation. Revise IO documentation to clarify `print`, `printAll`, `write`, and `read` semantics with updated examples.
2015-07-18 21:09:00 +00:00
Bob Nystrom 35305797b2 feat: add string_equals.py benchmark for equality comparison performance
Add a new benchmark file that measures performance of string equality comparisons
across various lengths and match/mismatch scenarios, including type mismatch
between string and integer.
2015-07-18 18:21:49 +00:00
Bob Nystrom 83d01fdf5b docs: restructure community page with library, binding, and editor sections and update README call-to-action links 2015-07-18 18:19:52 +00:00
Bob Nystrom 864210978b chore: switch travis to container-based infra and move apt deps to addons block
Replace manual apt-get install steps with declarative addons.apt.packages for gcc-multilib, and set sudo: false to enable container-based builds for faster CI execution.
2015-07-10 17:35:25 +00:00
Bob Nystrom 3ea9e0f2a9 fix: initialize signature type to SIG_GETTER in unarySignature function 2015-07-10 17:27:32 +00:00
Bob Nystrom 852f726c5a fix: cast enum sum to Code type in createConstructor emitShortArg call 2015-07-10 16:22:04 +00:00
Bob Nystrom e19ff59cce feat: replace new keyword with this constructor syntax and ClassName.new() calls across core library and docs
Replace all uses of the `new` reserved word with explicit `this new()` constructor definitions and `ClassName.new()` instantiation calls in builtin/core.wren. Update all documentation files (classes.markdown, fiber.markdown, fn.markdown, sequence.markdown, error-handling.markdown, expressions.markdown, fibers.markdown, functions.markdown) to reflect the new constructor syntax, removing `new` keyword examples and replacing them with `ClassName.new()` patterns and `this new()` definitions.
2015-07-10 16:18:22 +00:00
Bob Nystrom 121d39cb42 fix: update expect error regex to not match expect error line patterns 2015-07-09 15:09:19 +00:00
Bob Nystrom 357e24efcb fix: correct test runner to fail on all unmet expected errors and refactor into Test class
The test runner previously short-circuited when a test expected an error and found at least one, causing it to miss other expected errors that didn't occur. This commit fixes the error pattern regex to exclude line-specific error expectations, removes specific error message strings from test files (since the runner doesn't validate them yet), and refactors the monolithic test function into a dedicated Test class with parse and run methods for better maintainability.
2015-07-09 15:06:33 +00:00
Bob Nystrom 5401742163 fix: correct typo in AUTHORS file and add Starbeamrainbowlabs to contributor list
Fix the misspelling of "incomplete" in the AUTHORS file header and append
Starbeamrainbowlabs with their email address to the end of the contributor list.
2015-07-01 23:07:51 +00:00
Bob Nystrom b1c9231b5a docs: fix code block language annotations, method formatting, and footer credits in documentation site 2015-07-01 15:11:10 +00:00
Bob Nystrom 272273e539 docs: add IO class documentation with print, write, and read static methods
Add a new doc page for the IO class covering its three static methods:
IO.print() for printing multiple values with a trailing newline, IO.write()
for printing a single value without a newline, and IO.read() for reading a
line of text from the console with a prompt. Also update the core index page
and template sidebar to include a link to the new IO documentation.
2015-07-01 13:44:27 +00:00
Bob Nystrom 29ca6f4ffc feat: dynamically grow fiber call frame array instead of fixed MAX_CALL_FRAMES
Replace the statically-sized CallFrame array in ObjFiber with a dynamically
allocated array that starts at INITIAL_CALL_FRAMES (4) and doubles when
capacity is exceeded. This reduces memory for new fibers and improves
fiber creation benchmark performance by ~45%.
2015-07-01 07:00:25 +00:00
Bob Nystrom 8ae42156d8 feat: add return_this primitive to replace duplicated identity-returning implementations
Extract the common pattern of returning the receiver argument into a single
DEF_PRIMITIVE(return_this) function, and refactor fiber_instantiate,
fn_instantiate, and the default Object constructor to use it instead of
inline RETURN_VAL(args[0]) calls. Also fix trailing whitespace on isEmpty
and class_toString lines in the core library source string.
2015-06-30 14:39:43 +00:00
Bob Nystrom 1dc1c4e2bf feat: add isEmpty method to Sequence class with efficient early-termination check 2015-06-30 13:52:29 +00:00
Bob Nystrom d04e6a61a6 feat: add dedicated toString primitive for Class and simplify object_toString
Extract class name retrieval from object_toString into a new class_toString primitive, registered on the Class metaclass. This removes the IS_CLASS branch from object_toString, which now only handles instances and falls back to "<object>". The change ensures Class objects return their own name directly via toString rather than relying on the generic object handler.
2015-06-28 22:33:37 +00:00
Bob Nystrom 43af98f1a5 refactor: merge duplicate call-handling logic between CODE_CALL and CODE_SUPER into shared code block
Eliminate the performance penalty of an if-test inside the call instruction loop by using explicit goto to share the common tail-end call-handling code between normal and superclass calls. This improves interpreter throughput across multiple benchmarks, with gains of up to 23% on the 'for' benchmark and 14% on 'fib'.
2015-06-28 17:58:48 +00:00