Commit Graph
100 Commits
Author SHA1 Message Date
Bob Nystrom 8b70246acd refactor: remove sourcePath parameter from wrenInterpret and related module functions
The sourcePath field on ObjModule was redundant since it always matched the module name except for the main script. This change removes the parameter from wrenInterpret, wrenInterpretInModule, and wrenNewModule, and replaces all references to module->sourcePath with module->name in error reporting and debug output.
2015-10-16 01:17:42 +00:00
Bob Nystrom c65fdb2f94 refactor: extract Meta class into separate module and add eval method with compile support 2015-10-16 01:08:56 +00:00
Bob Nystrom 419a5dfda0 refactor: move source path from FnDebug to ObjModule for centralized debug path storage
Remove the `sourcePath` field from `FnDebug` struct and the `Parser` struct, and instead store it directly in `ObjModule`. This eliminates duplication of the debug path across all functions in a module and simplifies the compiler interface by removing the `sourcePath` parameter from `wrenCompile()` and `wrenNewFunction()`. Update all call sites to reference `module->sourcePath` instead, including stack trace printing, code dumping, and the `meta_eval` primitive.
2015-10-14 14:37:13 +00:00
Bob Nystrom 21c5611bf0 fix: close only existing upvalues for locals in scope during stack unwinding
The previous implementation unconditionally closed the first open upvalue when
executing CLOSE_UPVALUE, which could crash when a local variable was never
actually captured by a closure. Changed closeUpvalue to closeUpvalues with a
stack threshold parameter, so only upvalues whose stack slot is at or above the
given pointer are closed. This prevents closing nonexistent upvalues for locals
that were never closed over, fixing segfaults in unused closure scenarios.

Added regression tests for unused closures and for nested scopes where only
some locals are captured.
2015-10-08 15:06:29 +00:00
Bob Nystrom ddc3ec855e fix: resolve local names in methods as self sends instead of upvalues
When a method references a name that exists as a local variable outside the method boundary, the compiler now correctly treats it as a self send rather than closing over the outer local. This fixes the closure resolution logic in `findUpvalue` to stop searching for upvalues when hitting a method boundary, unless the name starts with '_' indicating a static field access. The change removes two incorrect test cases that expected outer local closure behavior and adds a new test verifying that both instance and static methods resolve local names to their own methods.
2015-10-05 14:44:51 +00:00
Bob Nystrom 27d6176f40 fix: correct two typos in contributing documentation
- Fix "I am delighted" to "We'd be delighted" for inclusive tone
- Remove extra space before "[the mailing list" link reference
2015-10-04 04:45:59 +00:00
Bob Nystrom 640779a81c refactor: replace PrimitiveResult enum with boolean return type for primitive functions
The PrimitiveResult enum (PRIM_VALUE/PRIM_FIBER) is removed and replaced with a simple bool return value where `true` indicates a normal value return and `false` signals a fiber switch or runtime error. This simplifies the interpreter dispatch in `runInterpreter` by converting the switch on enum cases into a single if/else branch, and reduces branching in the common value-returning path. All primitive function signatures, the `RETURN_VAL`/`RETURN_ERROR` macros, and the `runFiber` helper are updated accordingly.
2015-10-04 03:43:12 +00:00
Bob Nystrom 4d1d6d03f4 feat: remove PRIM_CALL result type and add METHOD_FN_CALL for function call special-casing
Replace the special "call" primitive result type (PRIM_CALL) with a new METHOD_FN_CALL method type that marks function call methods. Add checkArity helper to validate argument count before invoking function closures, and update the interpreter dispatch to handle the new method type instead of relying on the removed PRIM_CALL result.
2015-10-04 02:04:11 +00:00
Bob Nystrom d463507b6e docs: reword embedding guide intro and add configuration details for Wren VM setup 2015-10-03 04:25:55 +00:00
Bob Nystrom 1ebb7f2507 refactor: remove explicit ObjFiber parameter from all primitive function signatures
Replace the `ObjFiber* fiber` parameter in `DEF_PRIMITIVE` macro and `Primitive` typedef with direct access to `vm->fiber` inside each primitive implementation. Update all call sites in `fiber_current`, `fiber_try`, `fiber_yield`, `fiber_yield1`, `meta_eval`, and the interpreter dispatch to use `vm->fiber` or a local `current` variable instead of the passed-in `fiber` argument.
2015-10-02 14:51:12 +00:00
Bob Nystrom 8fd9449196 feat: implement async file I/O with open/close/readBytes and scheduler error handling
Add foreign class File with static open, read, size methods and instance methods for close, size, readBytes. Implement async file operations using libuv callbacks that resume fibers on completion. Introduce schedulerResumeError and resumeError_ to propagate I/O errors as fiber errors. Add setExitCode to CLI vm for runtime error exit handling. Bump MAX_METHODS_PER_CLASS from 2 to 9 to accommodate new File methods.
2015-10-01 04:13:36 +00:00
Bob Nystrom af90291f6f feat: add isInfinity and isInteger methods to Num class
Implements two new methods on the Num class: isInfinity checks if a number is positive or negative infinity using isinf(), and isInteger checks if a number has no fractional component, returning false for NaN and infinity. Includes C primitives, documentation, and test files.
2015-09-30 15:41:43 +00:00
Bob Nystrom b3086333f0 refactor: unify PRIM_ERROR and PRIM_RUN_FIBER into single PRIM_FIBER enum value
Replace separate PRIM_ERROR and PRIM_RUN_FIBER return codes with a unified PRIM_FIBER in PrimitiveResult enum, updating all primitive implementations and the interpreter switch case to use the new combined value.
2015-09-30 14:32:39 +00:00
Bob Nystrom 2dcb3660b5 feat: add Fiber.transferError and allow non-string error objects in fiber abort
Refactor runtime error handling to store errors directly in the fiber's error field instead of on the stack, enabling any object (except null) as an error value. Add Fiber.transferError(_) primitive for transferring errors between fibers. Update validation helpers to accept Value arguments directly and modify RETURN_ERROR macro to set fiber error. Adjust GC marking to use wrenMarkValue for the error field. Add tests for aborting with non-string errors and null abort behavior.
2015-09-30 05:57:03 +00:00
Bob Nystrom f6c36ec85b feat: add va_list version of wrenCall and fix GC bug with return values
- Introduce wrenCallVarArgs as an explicit va_list variant, allowing variadic functions to forward their arguments directly without re-parsing.
- Fix a garbage collection issue in wrenCall where return values could be prematurely collected by ensuring proper root handling.
- Refactor the call API test to avoid re-entering the VM by moving test execution into an afterLoad callback instead of a foreign method.
2015-09-30 02:29:10 +00:00
Bob Nystrom b19d85f618 feat: add 'a' format specifier and null-value support to wrenCall, plus tests for strings with null bytes
Add a new 'a' format specifier to wrenCall that accepts an explicit byte array and length, enabling callers to pass strings containing null bytes without truncation. Also allow passing NULL for 'v' specifier arguments to produce a Wren NULL value. Rename setForeignCallbacks to setTestCallbacks for clarity. Extend the test suite with a new call.c test file that exercises all argument types including 'a' and 'v' with NULL, and add returnString/returnBytes foreign methods to verify wrenReturnString handles both null-terminated and explicit-length strings correctly.
2015-09-24 15:02:31 +00:00
Bob Nystrom 5e63e65752 docs: flesh out Range class docs, fix grammar, add smarty plugin, and improve CLI description 2015-09-23 04:19:38 +00:00
Bob Nystrom 6bda720b71 feat: replace all :::dart code fence markers with :::wren in documentation
Add a custom Pygments lexer plug-in for Wren syntax highlighting, update contributing docs with setup instructions for the lexer, and switch every `:::dart` annotation across all doc/site markdown files to `:::wren` so code examples render with the correct language grammar.
2015-09-22 14:59:54 +00:00
Bob Nystrom 2544aa74d8 refactor: rename script/ to util/ and remove project/ directory consolidating build tools
Migrate all Makefile references from script/wren.mk to util/wren.mk, update path for wren_to_c_string.py and libuv.py in build rules, and delete the entire project/msvc2013/ directory containing obsolete Visual Studio 2013 project files.
2015-09-22 14:45:58 +00:00
Bob Nystrom b111e7df1c fix: replace hardcoded python calls with python2_binary helper for gyp build scripts 2015-09-22 02:48:08 +00:00
Bob Nystrom dbddd15e29 refactor: replace per-module bind functions with centralized ModuleRegistry table in modules.c 2015-09-21 14:58:39 +00:00
Bob Nystrom 3a8582af89 feat: allow super calls in static methods by removing compiler error and fixing metaclass binding
Remove the compiler check that prevented 'super' from being used inside static methods, and fix the runtime binding logic in bindMethod to correctly resolve the superclass for static method dispatch. The key change moves the metaclass lookup (classObj->obj.classObj) to occur before wrenBindMethodCode so that bytecode patching uses the actual class rather than the metaclass, while preserving the original class name for foreign method resolution.
2015-09-19 22:19:41 +00:00
Bob Nystrom a4922635f2 refactor: replace ad-hoc isKeyword checks with static keyword lookup table in lexer
Introduce a Keyword struct and static keywords array mapping reserved word strings to their TokenType, replacing the previous isKeyword() function that performed repeated strncmp comparisons. The new table-driven approach simplifies lexing by enabling direct binary search or linear scan over known identifiers, reducing per-token branching and making the set of keywords explicit and easier to maintain.
2015-09-18 03:51:24 +00:00
Bob Nystrom e4cac681a5 feat: add io module with File.size async stat and scheduler resume helpers
Introduce a new built-in "io" module exposing a File class with a static size(path) method that performs asynchronous filesystem stat via libuv. The method uses a foreign function startSize_ to initiate the stat request and resumes the calling fiber through the scheduler upon completion. Extend the scheduler with schedulerResumeDouble and schedulerResumeString to support resuming fibers with numeric or string results. Include the generated io.wren.inc source, update the Xcode project to compile io.c and io.wren.inc, register the module in modules.c, and add a test file verifying synchronous-style async size calls and error handling.
2015-09-16 14:34:49 +00:00
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