Commit Graph
100 Commits
Author SHA1 Message Date
Bob Nystrom e5da0ecddf fix: correct two typos in classes documentation for field naming and superclass method invocation 2015-11-25 16:59:16 +00:00
Bob Nystrom bbe21c48db fix: replace empty array initializers with named sentinel macros for VC++ compatibility 2015-11-25 16:36:42 +00:00
Bob Nystrom 58d4dfc2db refactor: eagerly evaluate interpolated expressions in string compilation
Remove the deferred function compilation for interpolation parts and instead evaluate them directly during string parsing. This simplifies the compiler by eliminating the need for String.interpolate_() and the associated closure creation, replacing it with a direct list construction and join() call.
2015-11-23 15:08:14 +00:00
Bob Nystrom 253707db17 docs: expand method scope documentation with this keyword and object scope explanation 2015-11-21 22:00:21 +00:00
Bob Nystrom fa1c1f5cda docs: document string interpolation syntax and update code examples across docs and site
Add a new "Interpolation" section to the values documentation explaining the `%(expr)` syntax with examples of complex expressions and nested interpolation. Update all code samples in README.md, getting-started.markdown, and index.markdown to use the new interpolation syntax instead of string concatenation. Adjust syntax highlighting in style.scss by adding a new `.si` class for interpolation spans with distinct background color, and tweak existing color values for strings, numbers, and keywords to improve visual distinction. Add the `\%` escape sequence to the list of supported escape characters in values.markdown.
2015-11-21 17:20:50 +00:00
Bob Nystrom 920b3e2a32 feat: implement string interpolation with %(expr) syntax in compiler and core library
Add lexer support for `TOKEN_INTERPOLATION` to split string literals at interpolation points, introduce `MAX_INTERPOLATION_NESTING` limit of 8, and compile interpolated strings by emitting calls to `String.interpolate_()`. Optimize list and map literal construction with new `addCore_` primitives to reduce stack churn. Update `String`, `List`, and `Map` `toString` methods in core library to use interpolation syntax, and migrate all benchmark and test files from explicit concatenation to interpolated strings.
2015-11-11 15:55:48 +00:00
Bob Nystrom a8961f817e feat: switch release build optimization from -Os to -O3 for performance
Change the C compiler optimization flag in util/wren.mk from -Os (size-optimized) to -O3 (aggressive speed optimization) for release builds. Benchmarks show consistent speed improvements across 10 of 11 tests, with gains ranging from 2.5% to 12.6% relative to baseline, and only method_call showing a minor 5.4% regression.
2015-11-10 15:33:15 +00:00
Bob Nystrom cf5b011be5 fix: remove trailing commas in END_MODULE and END_CLASS macros 2015-11-10 15:13:19 +00:00
Bob Nystrom 7fd90152ae docs: lowercase module names in sidebar and table, reword built-in module description for clarity 2015-11-09 15:42:48 +00:00
Bob Nystrom 60dd61be05 docs: replace placeholder TODO with full Random module docs and rename parameters from min/max to start/end 2015-11-09 15:37:06 +00:00
Bob Nystrom 909c242a03 chore: reorganize doc site structure by moving core docs under modules/ and removing category metadata
Restructure the documentation hierarchy to prepare for documenting additional built-in modules. Move all core library documentation from `doc/site/core/` to `doc/site/modules/core/`, rename `modules.markdown` to `modularity.markdown`, remove `^category` metadata lines from all affected pages, update cross-reference links to use relative paths under the new structure, and add a TODO placeholder to the Class class page.
2015-11-08 21:31:22 +00:00
Bob Nystrom 4562b2e497 docs: move precedence table from grammar page to syntax page with updated operator list and links 2015-11-08 18:59:23 +00:00
Bob Nystrom 1b2f11eec3 docs: remove outdated commented-out is operator documentation from method-calls page 2015-11-07 21:00:49 +00:00
Bob Nystrom f27fff9dd0 docs: document is operator as overridable infix method and add type-test examples 2015-11-07 21:00:24 +00:00
Bob Nystrom efcc4d07c7 docs: reorganize language guide into linear narrative with renamed sections and navigation links 2015-11-07 19:09:04 +00:00
Bob Nystrom 7fcd513b23 fix: add explicit casts to C++ compile errors in wren_value.c and wren_vm.c
Add explicit casts from void* to Obj** for reallocateFn calls in wrenNewVM and wrenFreeVM, and remove trailing whitespace on blank lines throughout wren_value.c to resolve C++ compilation errors.
2015-11-04 15:07:33 +00:00
Bob Nystrom 8afa5c3d68 fix: refactor GC gray set to use count/capacity and handle empty set edge cases
- Rename grayDepth to grayCount and maxGray to grayCapacity for clarity
- Fix gray stack growth condition to check capacity instead of depth
- Use config.reallocateFn directly instead of wrenReallocate wrapper
- Change blacken loop from do-while to while to handle empty gray set
- Remove separate initializeGC function and inline allocation in wrenNewVM
- Add explicit System.gc() calls in deeply_nested_gc and many_reallocations tests
- Normalize test output strings to lowercase "done"
2015-10-29 14:38:09 +00:00
Bob Nystrom 9fe0b2475e refactor: rename GC marking functions to tri-color terminology and add wrenGrayObj helper
Rename `wrenMarkValue` to `wrenGrayValue`, `wrenMarkBuffer` to `wrenGrayBuffer`, and `wrenDarkenObjs` to `wrenBlackenObjects` to make the tri-color garbage collection abstraction explicit. Introduce `wrenGrayObj` as a new helper that handles adding objects to the gray stack with cycle detection via the `isDark` flag. Update all call sites in the compiler, value, and VM modules to use the new names. Fix a typo in the VM header comment ("garbace" → "garbage").
2015-10-28 14:55:04 +00:00
Bob Nystrom ee2789dea7 perf: replace single gc calls with 1000-iteration loops in binary_trees_gc benchmark
In the binary_trees_gc.wren benchmark, change each of the three single System.gc() calls to a for loop that invokes System.gc() 1000 times, increasing garbage collection pressure during tree construction and traversal phases.
2015-10-28 14:46:06 +00:00
Bob Nystrom 2e71b0c07d fix: increase GC stress in binary_trees_gc benchmark by calling gc 1000 times per cycle 2015-10-28 14:45:52 +00:00
Bob Nystrom 6a56bd2ee9 feat: add binary_trees_gc benchmark that explicitly invokes System.gc
Add a new benchmark variant of the binary_trees test that calls System.gc() after
each tree construction phase to measure garbage collection overhead. The benchmark
creates a stretch tree, a long-lived tree, and iterates through depths 4 to 12
with explicit GC calls between iterations. Register the new benchmark in
util/benchmark.py with expected output values matching the original binary_trees
benchmark.
2015-10-24 18:00:17 +00:00
Bob Nystrom 4e712dbf6b feat: add 2-second timeout to test runner to prevent hanging during GC stress tests
Implement a threading.Timer-based timeout mechanism in the Test class that kills the subprocess if it exceeds two seconds. This prevents pathological tests from hanging indefinitely, particularly when running tests concurrently with GC stress testing. The timeout is enforced by a kill callback that sets a flag and terminates the process, with proper cleanup via a try/finally block to cancel the timer.
2015-10-24 17:58:21 +00:00
Bob Nystrom 498d1af8d0 feat: add System.gc() method and replace test's Api.gc() with it
Add a new `System.gc()` primitive that calls `wrenCollectGarbage` to allow
scripts to trigger garbage collection. Document the method in the core
System page. Remove the test-only `Api.gc()` foreign method and update
the foreign_class test to use `System.gc()` instead.
2015-10-24 17:56:27 +00:00
Bob Nystrom c9a7dba0c1 chore: rename auxiliary modules to optional and update all references
Rename the `src/aux/` directory to `src/optional/`, update all include guards, preprocessor defines, and file references from `WREN_AUX_*` to `WREN_OPT_*`, and adjust build system, Xcode project, and code generation scripts accordingly.
2015-10-24 16:23:25 +00:00
Bob Nystrom 2f013b3538 style: standardize example output markers across core docs and classes page 2015-10-18 22:56:52 +00:00
Bob Nystrom f8c5517969 feat: add Will Speak to AUTHORS file with email contact
Append a new entry for Will Speak with email address will@willspeak.me to the AUTHORS file, following the existing contributor listing format and fixing the missing newline at end of file for the previous entry.
2015-10-18 17:35:14 +00:00
Bob Nystrom c03d86c28b chore: move core.wren source from builtin/ to src/vm/ and update build paths
- Remove builtin/README.md explaining the .wren to .wren.inc conversion process
- Update src/README.md to document new aux/ directory for optional modules
- Fix generated file headers in wren_core.wren.inc and wren_aux_random.wren.inc to point to new source locations
- Update Makefile pattern rule to look for .wren sources in src/vm/ instead of builtin/
- Adjust wren_to_c_string.py to strip both "aux_" and "wren_" prefixes when deriving module names
2015-10-18 05:17:10 +00:00
Bob Nystrom 88a4e0a4e9 refactor: move meta and random modules from vm and cli into new aux library category
Restructure module hierarchy by extracting meta and random from the core VM and CLI-specific modules into a new "aux" (auxiliary) directory. This introduces WREN_AUX_META and WREN_AUX_RANDOM configuration flags, updates include paths and build system to compile aux sources separately, removes random module registration from CLI modules.c, and adjusts the VM's module loading to implicitly import core into all modules regardless of name.
2015-10-18 05:09:48 +00:00
Bob Nystrom 455c1dc7c1 feat: add 8-digit Unicode escape support with \U prefix in string literals
Extend the string parser to handle `\U` escape sequences for 8-hex-digit Unicode code points (e.g., `\U0001F603`), enabling encoding of characters beyond the Basic Multilingual Plane. Refactor `readUnicodeEscape` to accept a configurable digit length, allowing both `\u` (4 digits) and `\U` (8 digits) to share the same parsing logic. Add test cases for valid long escapes, equality with byte-encoded surrogates, and an error test for incomplete long escapes.
2015-10-18 03:07:52 +00:00
Bob Nystrom 5e7f7b3096 fix: skip guess_number example in test runner due to user input requirement
The run_example function in util/test.py now checks if the example path
contains "guess_number" and returns early to avoid hanging on interactive
input during automated test execution.
2015-10-17 20:29:50 +00:00
Bob Nystrom 1db2c3deae feat: add guess-a-number game example with random number and user input loop
Add a new Wren example implementing a classic number guessing game where the program picks a random integer between 1 and 100, then repeatedly prompts the user for guesses, providing "too low", "too high", or "you win" feedback until the correct number is found. The implementation uses the `random` module for number generation and `io` module for stdin reading with input validation.
2015-10-17 18:19:25 +00:00
Bob Nystrom cda76e087a fix: replace bit-shift constant with explicit double literal for 2^53 in randomFloat
The division operand in randomFloat() was previously computed using a 1UL left-shift by 53 bits, which on some platforms could produce unexpected integer overflow behavior or precision loss when implicitly converted to double. Replaced with the exact double literal 9007199254740992.0 (2^53) to guarantee consistent floating-point division across all architectures and compiler configurations.
2015-10-17 18:07:13 +00:00
Bob Nystrom 166a5d0d59 feat: add WELL512-based Random module with seed, float, and int methods
Implement a new `random` module for the Wren language runtime, providing a `Random` class backed by the WELL512a PRNG algorithm. The module supports three seeding strategies (time-based, single numeric seed, and 16-element sequence), generates uniform floats in [0,1) and integers in the full uint32 range, and includes convenience methods for bounded ranges. The implementation adds the C foreign functions `randomAllocate`, `randomSeed0`, `randomSeed1`, `randomSeed16`, `randomFloat`, and `randomInt0`, registers them in the module registry, and includes the Wren wrapper class with constructors accepting no arguments, a number, or a sequence. The commit also adds 12 test scripts covering float/int generation, seeding reproducibility, and error handling for invalid seed types.
2015-10-17 18:03:15 +00:00
Bob Nystrom 0f932e1f3a fix: make UNREACHABLE() macro safe on compilers lacking __builtin_unreachable
Add fallback empty UNREACHABLE() definition for GCC < 4.5 and non-MSVC compilers, and insert return/break statements after all UNREACHABLE() calls to prevent -Wreturn-type warnings when the macro expands to nothing. Also cast malloc result to char* in io.c to suppress C++ compilation warning.
2015-10-17 04:51:30 +00:00
Bob Nystrom 98f328c09f chore: improve Python 2.6 compatibility in libuv.py build helper
- Update docstring formatting in python2_binary() for consistency
- Refactor version check in run() to use explicit tuple comparison instead of sys.version_info[1] < 7
- Add missing cwd parameter to subprocess.Popen call in fallback path for Python < 2.7
2015-10-17 04:33:22 +00:00
Bob Nystrom 173e5e557c fix: replace deprecated sys.version_info.major with tuple index for Python 2.6 compatibility
Add fallback for subprocess.check_output on Python versions earlier than 2.7 by checking sys.version_info tuple and using Popen.communicate when check_output is unavailable
2015-10-17 04:24:22 +00:00
Bob Nystrom 9e6f778147 feat: add Stdin class with readLine and async stdin read support in io module 2015-10-17 04:05:24 +00:00
Bob Nystrom 6f67fda56a chore: rename "core library" to "core module" in comments across wren_core.c and wren_core.h
Update three inline comments in wren_core.c (defineClass docstring and wrenInitializeCore bootstrap note) and one in wren_core.h (module-level description) to consistently refer to the "core module" instead of "core library", aligning terminology with the actual module-based architecture.
2015-10-16 02:38:25 +00:00
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