Commit Graph
100 Commits
Author SHA1 Message Date
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 85487d9d8c feat: enable pthread flag for gcc builds on non-macOS platforms
Add -pthread to CFLAGS in the Linux/Unix shared library build path
to ensure proper thread support when compiling with gcc, which does
not enable it by default unlike some other compilers.
2015-08-08 16:14:52 +00:00
Bob Nystrom 283c64d713 fix: bump _XOPEN_SOURCE to 600 for libuv compatibility on Linux
The previous value of 500 was insufficient for libuv's POSIX requirements,
causing compilation failures on Linux systems. Upgrading to 600 ensures
the necessary POSIX 2004 extensions are available, allowing libuv to
function correctly with the build system.
2015-08-08 16:06:40 +00:00
Bob Nystrom fc745b43ed feat: add CLI_FLAGS variable with _XOPEN_SOURCE=500 and consolidate include paths for cli, module, and test targets 2015-08-08 15:57:57 +00:00
Bob Nystrom 0f4d3025b8 fix: adjust libuv build paths for Linux output directory and parameterize in Makefile 2015-08-08 14:40:27 +00:00
Bob Nystrom 408ded555d fix: change libuv Linux build directory from 'out' to 'build' in build_libuv_linux
The build_libuv_linux function previously used the 'out' directory for the make
command, but now correctly targets the 'build' directory to match the output
generated by gyp_uv.py on Linux.
2015-08-08 14:20:07 +00:00
Bob Nystrom 664a166d6c feat: add input validation and stack trace filtering for Timer.sleep
Add type and range checks to Timer.sleep() in both C source and Wren
implementation, aborting with descriptive errors for non-numeric or
negative arguments. Introduce six new test files covering sleep with
fibers, float durations, main fiber, zero milliseconds, negative
values, and non-numeric input. Fix stack trace parsing in test runner
to skip builtin library frames by iterating through error lines until
a main-line match is found.
2015-08-08 14:17:30 +00:00
Bob Nystrom 810da1f0fc feat: add libuv event loop integration with timer module and CLI restructuring
Add a vertical slice of real libuv integration by introducing a "timer" CLI module with a Timer class and static sleep() method. This required significant infrastructure changes: setting up libuv event loop in the CLI, creating a new src/module directory for CLI modules, updating all build scripts (Makefile, wren.mk, Xcode project) to handle the new module compilation, and reorganizing CLI code by moving REPL logic from main.c to vm.c. The generate_builtins.py script was also updated to support copying Wren sources into the module directory.
2015-08-07 15:10:55 +00:00
Bob Nystrom e7bdca2cfa feat: add 'v' type specifier to wrenCall for passing WrenValue arguments
- Extend wrenCall's variadic argument handling to accept 'v' type specifier,
  which passes a previously acquired WrenValue* without releasing it.
- Update documentation comment in wren.h to describe the new 'v' argument type.
- Fix parameter counting in makeCallStub to correctly parse parenthesized
  signatures by scanning backwards from the closing parenthesis.
2015-08-07 14:57:32 +00:00
Bob Nystrom f9f8b55b29 feat: add support for passing WrenValue pointers as 'v' type argument to wrenCall
Extend the wrenCall variadic argument handling to accept a new 'v' type specifier,
which allows callers to pass a previously acquired WrenValue* directly without
implicitly releasing it. This enables reusing existing Wren values across multiple
calls without unnecessary string or number conversions.

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

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

Key changes:
- In `callSignature()`, when compiling a `CODE_SUPER_0` instruction, a constant slot is created and filled with NULL, to be populated with the superclass reference when the method is bound.
- In `getNumArguments()`, the `CODE_SUPER_0` through `CODE_SUPER_16` cases are moved after the newly added 2-argument opcodes (`CODE_JUMP`, `CODE_LOOP`, etc.) to maintain correct ordering.
- In `dumpInstruction()`, the debug output now prints the superclass constant index alongside the method symbol.
- In `runInterpreter()`, the super call execution reads the superclass directly from the function's constant table instead of deriving it from the receiver's class at runtime.
2015-06-02 14:33:39 +00:00
Bob Nystrom 1b4d7d404d fix: correct NaN tagging diagrams in wren_value.h comment formatting
The ASCII diagrams in the NaN tagging documentation had misaligned
brackets and inconsistent dash counts that made the bit layout
confusing. Updated the exponent/mantissa separator from parentheses
to brackets, fixed the NaN bits indicator alignment, and corrected
the highest mantissa bit marker position to match the actual bit
positions in the IEEE 754 double representation.
2015-06-02 14:14:19 +00:00
Bob Nystrom 067199657e feat: add test build target and refactor CLI VM creation to accept foreign method bindings
- Add test executable build target in Makefile and wren.mk with new TEST_SOURCES variable
- Refactor createVM() and runFile() to accept WrenBindForeignMethodFn parameter
- Remove deprecated safeToString_ method from String class and simplify toString implementations
- Delete example/set.wren and add example/syntax.wren with syntax highlighting examples
- Refactor test runner script with color helper functions and add TEST_APP path
- Remove .DELETE_ON_ERROR from Makefile and add test dependency in test target
2015-05-27 13:57:20 +00:00
Bob Nystrom 3297642b65 feat: add api tests for returning double and null values from foreign functions
Introduce two new test suites under test/api/: return_double exercises wrenReturnDouble with integer and floating-point values, and return_null verifies that a foreign function returning nothing yields null. Refactor bindForeign dispatch in main.c to use a REGISTER_TEST macro, rename returnBoolBindForeign to return_boolBindForeign for consistency, and add an exit(1) on unknown foreign methods to prevent silent NULL returns.
2015-05-24 17:04:24 +00:00
Bob Nystrom 2961318302 feat: show number of expectations in test output
Add a global `expectations` counter and increment it each time an `EXPECT_PATTERN` match is found in test scripts. Display the total count alongside existing Passed/Failed/Skipped stats in the test runner output.
2015-05-24 16:45:52 +00:00
Bob Nystrom a8cb321063 feat: add C test harness and build infrastructure for embedding API tests
Add a new test runner under `test/api/` that compiles C test cases against the Wren VM, along with Makefile and Python test script changes to build and execute them. The first test (`return_bool`) exercises `wrenReturnBool` via foreign methods. The CLI's `createVM` and `runFile` now accept an optional `WrenBindForeignMethodFn` callback to support custom bindings in tests.
2015-05-24 16:29:25 +00:00
Bob Nystrom 3901ab57e7 feat: add C API test infrastructure with foreign method binding support
Add a new test framework for exercising the Wren C embedding API directly from C code, including a Makefile target, test runner modifications, and the first API test case for boolean return values. The build system now compiles test sources from `test/api/` into a separate test executable, and the CLI's `createVM` and `runFile` functions accept an optional `WrenBindForeignMethodFn` callback to enable foreign method binding in tests. The test runner (`script/test.py`) is refactored to support both script and API test types, passing the test name instead of the full path for API tests. The initial `return_bool` test verifies that `wrenReturnBool` correctly returns `true` and `false` from foreign methods.
2015-05-24 16:23:30 +00:00
Bob Nystrom 6d2bafc211 feat: add example directory test runner and ignore support to walk function
Add a `run_example` function that invokes `run_test` with `example=True`, which suppresses output comparison for example files. Extend the `walk` function with an `ignored` parameter to skip directories like `benchmark`. Update the test script to walk both `test` and `example` directories, enabling example files to be executed as tests to catch regressions like #266.
2015-05-23 15:32:33 +00:00
Bob Nystrom 38125a9cfe fix: remove outdated Set example from example/set.wren to resolve issue #266 2015-05-20 14:07:47 +00:00
Bob Nystrom df146953cd feat: add syntax highlighting example file for wren language constructs
Add a comprehensive example file `example/syntax.wren` that demonstrates all major syntactic constructs of the wren programming language, including class definitions, constructors, methods, control flow, literals, and reserved words. This file is primarily intended for testing syntax highlighters and covers nested comments, field declarations, static methods, setters, inheritance with `is`, and various control structures like `while`, `for`, `if`/`else`, and `break`.
2015-05-19 14:00:57 +00:00
Bob Nystrom 520b60c33f chore: remove unused .DELETE_ON_ERROR target for wren.c from Makefile 2015-05-19 14:00:44 +00:00
Bob Nystrom 057a59e1d3 feat: add syntax example file for Wren language highlighting
Add a comprehensive example file `example/syntax.wren` demonstrating syntactic constructs of the Wren programming language, including class definitions, constructors, methods, reserved words, literals, and control flow structures. This file is primarily intended for testing syntax highlighters and covers nested comments, field declarations, static methods, setters, inheritance with `is`, and various keyword usage patterns.
2015-05-19 13:58:12 +00:00
Bob Nystrom 701cffbe69 revert: remove safeToString_ and recursive toString handling due to memory leak on runtime errors
The safeToString_ mechanism introduced in 40897f33 used per-fiber maps and lists to detect recursive toString calls, but leaked memory when runtime errors occurred before cleanup. This reverts to direct toString implementations for List and Map, removing the recursive detection logic and updating tests to mark self-referencing containers as TODO.
2015-05-19 13:50:17 +00:00
Bob Nystrom 50de0dc5a8 feat: add failing tests for super calls in closures and inherited methods
Add two new test files covering super behavior in Wren's class inheritance:
- super_in_closure_in_inherited_method.wren tests super.toString inside a closure
  within an inherited method, expecting "instance of B" output.
- super_in_inherited_method.wren tests direct super.toString call in an inherited
  method, also expecting "instance of B". Both tests are currently expected to fail.
2015-05-19 13:47:42 +00:00
Bob Nystrom 13f63e0d04 feat: add wrenByteBufferFill and wrenMethodBufferFill for bulk buffer growth
Replace the loop-based single-element writes in readUnicodeEscape and wrenBindMethod with a new BufferFill macro that grows the buffer by a specified count in one allocation. The macro doubles capacity until it fits the requested count, then fills the new slots with the given data. The existing BufferWrite is reimplemented as a call to BufferFill with count=1.
2015-05-05 13:54:13 +00:00
Bob Nystrom 898ac53f4f fix: prevent stack overflow on recursive toString for List and Map
Add `String.safeToString_` static method that tracks objects currently being
converted to string per fiber, returning "..." when recursion is detected.
Wrap List.toString and Map.toString with this guard to handle self-referential
and mutually recursive structures without crashing.
2015-05-03 18:13:05 +00:00
Bob Nystrom cd1cc07c6f feat: allow fibers as map keys by adding unique fiber IDs and hash support
Add a unique numeric ID to each fiber allocation, enabling fibers to be used as map keys. This includes updating the hash function for OBJ_FIBER to return the fiber's ID, modifying key validation to accept fibers, updating documentation to describe the new capability, and adjusting all relevant test expectations and error messages.
2015-05-03 18:10:31 +00:00
Bob Nystrom 332f570a1a feat: add Object.same static method for reliable built-in equality
Introduce a new static method `Object.same(obj1, obj2)` that exposes the VM's
built-in equality semantics (`wrenValuesEqual`) directly, bypassing any
user-defined `==` overrides. This required creating a dedicated metaclass for
Object (subclass of Class) to host the static method without polluting every
class with a `same` method. The implementation wires up a new `Object metaclass`
in the core initialization sequence, adjusts the class hierarchy setup order,
and adds comprehensive tests covering value types, identity comparison, and
verification that `Object.same` ignores custom `==` operators.
2015-05-01 14:55:28 +00:00
Bob Nystrom cbfbb3a4cd test: add test for lowercase class name reference inside class body
Add a new test file `lowercase_name_inside_body.wren` that verifies a class can correctly reference its own lowercase name from both static and instance methods. The test ensures that `foo` resolves to the class itself in static context and to the instance method `foo` in instance context, addressing issue #251.
2015-04-25 17:47:55 +00:00
Bob Nystrom b496f02746 feat: add Evan Hahn to AUTHORS file with email contact
Append Evan Hahn's name and email address to the project's AUTHORS file, recognizing their contribution to the repository.
2015-04-25 16:34:57 +00:00
Bob Nystrom 24fabf1301 docs: copy-edit community page for clarity and consistency
- Shorten "wren bird" to "bird" to avoid redundancy
- Change "User groups" to "User group" for singular accuracy
- Rephrase "embedding APIs for Wren" to "Wren bindings for other languages"
- Add call-to-action for pull requests at the end of the page
2015-04-25 15:48:06 +00:00
Bob Nystrom 6a62c9aacc feat: add community page with user groups, third-party libraries, and editor integrations
Add a new community.markdown page to the documentation site that provides
information about Wren's user groups, third-party libraries written in Wren,
embedding API bindings for Rust, and editor integrations for Vim and Emacs.
Also update the site navigation template to include a link to the new
community page.
2015-04-25 15:39:43 +00:00
Bob Nystrom 39cb27c3f8 chore: update reserved words list in syntax documentation to include 'import'
The diff shows the reserved words list in the syntax markdown documentation was updated to include 'import' and reorder the words, moving 'new' to the second line.
2015-04-25 15:39:04 +00:00
Bob Nystrom 21ea9c788c chore: redirect amalgamation output to build/wren.c and add dedicated make target
The Makefile now defines an explicit `amalgamation` target that writes the combined source into `build/wren.c` instead of the default `wren.c` in the project root. The `generate_amalgamation.py` script is updated with whitespace formatting improvements for readability. The `.PHONY` list is extended to include the new `amalgamation` target.
2015-04-25 15:38:45 +00:00
Bob Nystrom 82bf33c6f4 feat: add amalgamation build target and rename libSource variables for consistency
Add a Makefile target to generate a single-file amalgamation of all Wren library sources using a new Python script. Rename the static `libSource` variables in core, io, and meta modules to `coreLibSource`, `ioLibSource`, and `metaLibSource` respectively to avoid name collisions in the amalgamated output. Update the `callFunction` helper to `callFn` and fix the regex pattern in `generate_builtins.py` to match the renamed constant.
2015-04-23 14:27:32 +00:00
Bob Nystrom 2a2b74a2e3 fix: add missing "import" keyword to reserved words list in syntax docs
The "import" keyword was omitted from the reserved words list in the syntax documentation. This commit adds it between "if" and "in" in the alphabetically ordered list, ensuring the documentation accurately reflects all language keywords.
2015-04-22 14:46:13 +00:00
Bob Nystrom 0bab23280a docs: rename sequence list method to toList and fix typo in wren.h comment 2015-04-22 14:45:39 +00:00
Bob Nystrom 2d2f083072 docs: clarify fiber call/resume semantics, fn arity error, and list insert negative index behavior 2015-04-22 14:45:20 +00:00
Bob Nystrom 6c66ce0e04 docs: add documentation for Fiber.call, Fn.call, and List.insert methods 2015-04-22 14:22:42 +00:00
Bob Nystrom daea0a8394 fix: correct typo in wren.h comment from "orde" to "order" 2015-04-22 14:21:13 +00:00
Bob Nystrom 6eefc06865 docs: replace deprecated .list with .toList in sequence documentation and move method definition 2015-04-22 14:19:00 +00:00
Bob Nystrom 706fa35049 chore: add Patricio Mac Adden to AUTHORS file for project contributions 2015-04-06 13:53:59 +00:00
Bob Nystrom 4b3b967674 chore: remove double space in finishParameterList and rephrase static method comment 2015-04-06 13:53:53 +00:00
Bob Nystrom abc7a9f692 docs: add Patricio Mac Adden to AUTHORS file
Add Patricio Mac Adden <patriciomacadden@gmail.com> to the list of project
contributors in the AUTHORS file, placed after Thorbjørn Lindeijer entry.
2015-04-06 13:45:11 +00:00
Bob Nystrom 10a6a1d23f fix: restore parent compiler before freeing on compile error
When a compile error occurs, the compiler's code is freed but the parent compiler
was not restored as the active compiler. This could cause the garbage collector
to operate on a dangling compiler pointer if a collection happens after the error.
The fix calls wrenSetCompiler to restore the parent compiler before freeing,
ensuring the GC always sees a valid compiler state.
2015-04-04 06:12:14 +00:00
Bob Nystrom d92a8f1c93 fix: replace foreign Meta.eval with primitive and suppress compile errors in wrenCompile 2015-04-04 04:22:58 +00:00
Bob Nystrom 103b9a133b fix: correct broken link to wren.h in embedding-api documentation
The link previously pointed to the old path `include/wren.h` which no longer exists. Updated the URL to the correct location at `src/include/wren.h` in the repository.
2015-04-04 01:51:21 +00:00
Bob Nystrom 734a415999 fix: cast subtraction result to int before abs to suppress clang -Wabsolute-value warning 2015-04-04 01:38:10 +00:00
Bob Nystrom 446e8b2ca9 feat: rename Sequence.list method to toList and update all call sites
The `.list` method on Sequence was renamed to `.toList` to better reflect its
purpose of converting a sequence into a List object. This change updates the
method definition in `builtin/core.wren` and `src/vm/wren_core.c`, along with
all test files that called `.list` on sequences, maps, ranges, and custom
sequence implementations. The test file `test/core/sequence/list.wren` was also
renamed to `test/core/sequence/to_list.wren` to match the new method name.
2015-04-03 18:22:34 +00:00
Bob Nystrom b6e2229b58 feat: move primitive class definitions from C into core.wren library source
Move the definitions of Bool, Fiber, Fn, Null, and Num classes from hardcoded C code in wren_core.c into the core.wren library source, allowing them to be parsed and created during library initialization. Simplify defineClass to always use wrenNewSingleClass, remove redundant root pushing in wrenNewClass, and adjust the class creation in the interpreter to use a Value instead of ObjClass*.
2015-04-03 15:00:55 +00:00