Commit Graph
100 Commits
Author SHA1 Message Date
Bob Nystrom a3bbc03afb chore: reorder OBJ_STRING case in wrenFreeObj switch to alphabetical order 2015-12-27 04:13:39 +00:00
Bob Nystrom a20ef8458b fix: correct spelling of 'upvalue' in comment for addUpvalue function 2015-12-27 04:12:35 +00:00
Bob Nystrom bdc2709234 chore: add build log output for wren_to_c_string invocations in makefile
Remove the print statement from wren_to_c_string.py that logged the input file path, and instead add printf commands to the three makefile rules that invoke the script, ensuring consistent logging format during builds.
2015-12-27 04:11:48 +00:00
Bob Nystrom 5e32d02778 fix: initialize match variable before loop in test.py stack trace parsing 2015-12-27 04:08:20 +00:00
Bob Nystrom 9b2a03c48a feat: add Directory.list() method to io module for reading directory entries
Implement a new `Directory` class with a static `list(path)` method that returns an array of filenames from the specified directory. The implementation uses a foreign function `list_(path, fiber)` that performs the actual filesystem read via libuv, collects all directory entries into a zero-byte-terminated buffer, and then splits that buffer into individual strings on the Wren side. Includes test cases for normal directory listing, listing a file path (runtime error), listing a nonexistent path (runtime error), and passing a wrong argument type (runtime error). Also bumps `MAX_CLASSES_PER_MODULE` from 3 to 4 to accommodate the new class.
2015-12-24 18:12:12 +00:00
Bob Nystrom dbd75f8905 feat: allow call and unary expressions as map keys in compiler
Change the map key parsing precedence from PREC_PRIMARY to PREC_UNARY in
wren_compiler.c, enabling method calls (e.g., name.count), subscript
access (name[0]), and unary operators (-1, ~3) as valid map keys.

Add two test files: precedence.wren verifying the new key types work
correctly, and bad_key_precedence.wren confirming that binary operators
like addition still produce a parse error.
2015-12-23 00:00:50 +00:00
Bob Nystrom e929c7c997 refactor: remove foreignCallNumArgs and rename foreignCallSlot to foreignStackStart
The number of arguments can be derived from the stack pointer difference, eliminating the need to store it separately. Rename the slot pointer to better reflect its purpose as the start of the foreign call's stack region.
2015-12-16 01:10:02 +00:00
Bob Nystrom 5d8ecad5a6 feat: add benchmark for Wren C API foreign method calls and refactor test class names
Add a new benchmark that measures the performance of calling foreign methods through the Wren C embedding API, specifically testing argument passing and return values with a tight loop of 10 million calls. Refactor test API classes from generic "Api" to specific names like "Call", "Returns", "Value", and "ForeignClass" to avoid naming conflicts with the new benchmark module. Update the benchmark runner to use the test_api executable for API-specific benchmarks and remove the special API test argument handling from the test runner.
2015-12-16 00:02:13 +00:00
Bob Nystrom ba0d308fba fix: remove fiber support as map keys and revert to value-only key validation
The previous implementation allowed fibers as map keys by assigning each fiber a unique numeric ID for hashing and equality. This was originally added to support a misguided attempt at thread-local storage that was never used. This commit removes the fiber ID field from ObjFiber, the nextFiberId counter from WrenVM, the fiber hashing case in hashObject(), and the IS_FIBER check in validateKey(). The error message for invalid keys is updated from "Key must be a value type or fiber." to "Key must be a value type." and all affected test expectations are updated accordingly.
2015-12-15 18:42:21 +00:00
Bob Nystrom 315e140a43 fix: correct fiber count in benchmark comment from 10000 to 100000 2015-12-15 18:37:53 +00:00
Bob Nystrom 6de3d6aa30 fix: correct debug instruction output and remove ClassCompiler parameter from method
- Fix debug dump to print human-readable instruction names instead of internal enum names (e.g., "RETURN" instead of "CODE_RETURN")
- Remove `ClassCompiler*` parameter from `method()` function, accessing class state through `compiler->enclosingClass` instead
- Change `ClassCompiler.fields` from pointer to embedded struct, updating field lookup to use address-of operator
2015-12-15 01:10:10 +00:00
Bob Nystrom 9aee7ee94e feat: grow fiber stack dynamically and replace fixed-size stack with heap-allocated array 2015-12-14 16:00:22 +00:00
Bob Nystrom 83254bbde3 feat: track max stack slots per function for dynamic stack growth
Add `numSlots` and `maxSlots` fields to `Compiler` struct to track current and maximum stack usage during compilation. Introduce `stackEffects` array mapping each opcode to its net stack delta, defined via updated `OPCODE` macro in `wren_opcodes.h` now taking a second argument. Modify `initCompiler` to initialize slot tracking from `numLocals`, update `emitByte` and related emit functions to adjust `numSlots` and update `maxSlots` when a new peak is reached. Extend `ObjFn` with `maxSlots` field, pass it through `wrenNewFunction` calls (including `makeCallStub`), and fix a null-check in `wrenDumpCode` for core module name.
2015-12-14 06:57:40 +00:00
Bob Nystrom 0f0d3f0c2d fix: propagate compile errors from imported modules and update test runner to skip them 2015-12-08 15:49:37 +00:00
Bob Nystrom 9dcba9f8b6 feat: ignore newlines in import statements and add test for multiline imports
Add calls to ignoreNewlines in the import compiler function to allow
newlines between the import keyword and the module string, and between
the module string and the for clause. Create a new test case
test/language/module/newlines/ that verifies multiline import syntax
works correctly with both bare imports and imports with variable
bindings.
2015-12-08 03:41:10 +00:00
Bob Nystrom 9d2b4af508 fix: allow empty ranges at the end of a sequence for lists and strings
Previously, empty ranges were only permitted at index zero on an empty sequence.
This change extends the `calculateRange` function to allow empty ranges at the
end of a non-empty sequence, enabling `list[3...3]` and `list[3..-1]` to return
an empty slice. Updated the range validation logic to check `range->from == *length`
instead of requiring a zero-length sequence, and added test cases for both lists
and strings to verify the new behavior.
2015-12-06 18:37:58 +00:00
Bob Nystrom 320c804ecf feat: add Dart benchmarks for binary_trees, delta_blue, fib, for, and method_call
Add five new Dart benchmark implementations (binary_trees, delta_blue, fib, for, method_call) under test/benchmark/ and register the Dart runner using the fletch runtime in util/benchmark.py. The benchmarks are ported from existing Wren and JavaScript versions, covering tree traversal, constraint solving, recursive Fibonacci, loop performance, and method call overhead.
2015-12-05 19:09:30 +00:00
Bob Nystrom a5d08effea fix: escape percent sign in string interpolation error message
The error message for a missing '(' after '%' in string interpolation
contained an unescaped '%' character, which could be misinterpreted
by format string functions. Changed the literal '%' to '%%' to ensure
proper display of the percent sign in the error output.
2015-12-05 18:15:18 +00:00
Bob Nystrom 93839b588a fix: add parentheses to method calls in delta_blue benchmark for idiomatic Wren syntax 2015-12-01 04:58:08 +00:00
Bob Nystrom 6a05397557 feat: add animals guessing game example with binary tree knowledge base 2015-11-29 17:43:47 +00:00
Bob Nystrom ce2028302a fix: correct .gitignore patterns to use leading slash and add missing pygments lexer file 2015-11-27 19:22:09 +00:00
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