Commit Graph
100 Commits
Author SHA1 Message Date
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
Bob Nystrom 17c6f277b2 refactor: merge patriciomacadden's refactoring branch into mainline
Consolidate the refactoring branch changes from patriciomacadden's fork into the main repository, incorporating the updated class definition logic in wren_core.c that replaces the separate defineSingleClass function with a unified defineClass function capable of handling both raw and subclassed class creation.
2015-04-03 14:19:17 +00:00
Bob Nystrom 7884d89165 docs: rename MapSequence and WhereSequence fields and parameters for clarity, expand map(_) and where(_) docs with lazy semantics and examples 2015-04-01 14:31:15 +00:00
Bob Nystrom 85a889e49f feat: replace eager map/where with lazy MapSequence and WhereSequence classes
Refactor Sequence.map and Sequence.where to return lazy MapSequence and WhereSequence wrappers instead of eagerly building a List. Add new MapSequence and WhereSequence classes that delegate iteration and apply the transformation or predicate on-the-fly. Update documentation to reflect lazy semantics and the need to call .list to materialize results. Adjust all existing tests to call .list on map/where results. Add new tests in test/core/sequence/ verifying lazy behavior with infinite Fibonacci iterators.
2015-04-01 14:22:02 +00:00
Bob Nystrom 7d7be7361e feat: add Sequence.each method to iterate over elements with a function
Add a new `each` method to the Sequence class in the Wren programming language,
allowing iteration over sequence elements by passing each element to a provided
function. This replaces the previous pattern of using `map` with `Fiber.yield`
in examples, providing a more direct and idiomatic way to perform side effects
per element. The implementation includes a core library method in `core.wren`,
a C source string in `wren_core.c`, documentation in the Sequence markdown file,
and three test cases covering normal iteration, empty sequences, and non-function
argument error handling.
2015-04-01 14:10:21 +00:00
Bob Nystrom 0cdbe8bc5a fix: prevent local variables from being in scope during their own initializer 2015-04-01 14:05:40 +00:00
Bob Nystrom 07de6fca9e fix: remove extraneous space inside isspace cast in num_fromString 2015-04-01 13:43:44 +00:00
Bob Nystrom 79db06c6a5 fix: cast char to unsigned char in isspace call to fix char-subscripts warning 2015-04-01 13:42:38 +00:00
Bob Nystrom a018470b47 fix: rename wrenDebugPrintCode to wrenDumpCode in endCompiler debug dump
The debug dump macro in endCompiler was calling the old function name
wrenDebugPrintCode, which has been renamed to wrenDumpCode. This change
updates the call site to match the new function name, fixing a potential
compilation error when WREN_DEBUG_DUMP_COMPILED_CODE is enabled.
2015-03-30 14:39:37 +00:00
Bob Nystrom 26a466b8a1 fix: flush stdout after each benchmark trial dot in run_benchmark_language 2015-03-30 14:39:21 +00:00
Bob Nystrom 133ed97dcf fix: correct debug function call from wrenDebugPrintCode to wrenDumpCode in endCompiler
The WREN_DEBUG_DUMP_COMPILED_CODE block in endCompiler() was calling the
nonexistent function wrenDebugPrintCode instead of the actual function
wrenDumpCode, causing a compilation error when debug dumping was enabled.
2015-03-29 01:08:51 +00:00
Bob Nystrom abe7a8d4b6 chore: remove outdated comment about instruction order matching Code enum in wren_vm.h 2015-03-28 17:19:38 +00:00
Bob Nystrom 540a4a166a feat: make Sequence.all() and Sequence.any() return actual predicate values instead of booleans
Rewrite all() and any() to store and return the predicate's result directly, matching && and || semantics. Update documentation to describe the new behavior. Move tests from test/core/list/ to test/core/sequence/ and add cases verifying that the first falsey/truthy value is returned.
2015-03-28 17:18:45 +00:00
Bob Nystrom adc64d65b9 refactor: extract opcode enum and dispatch table into shared X-macro header wren_opcodes.h 2015-03-28 16:56:07 +00:00
Bob Nystrom 84ad34b281 fix: invert boolean return semantics of finishBlock to match new doc comment
The return value of finishBlock() was inverted so that it now returns true
for expression bodies (value left on stack) and false for statement bodies
(no value left). All internal return points and the call site in finishBody()
were updated accordingly to maintain correct code generation behavior.
2015-03-28 16:15:19 +00:00
Bob Nystrom cc5bf9fcfe feat: add Sequence.list method to collect elements into a new List
Implements a new `list` method on the Sequence class that iterates over all elements and returns them as a freshly created List object. Includes documentation with usage example and a test case using a custom TestSequence class to verify correct behavior.
2015-03-28 16:06:49 +00:00
Bob Nystrom c4a7ad9d02 docs: clarify UTF-8 indexing explanation and fix punctuation in string and values documentation 2015-03-28 03:59:15 +00:00
Bob Nystrom c3d0b66630 feat: add raw byte access methods and \x escape to String class
Add `byteAt(index)`, `codePointAt(index)`, and `bytes` sequence to String,
enabling direct byte-level manipulation of UTF-8 encoded strings. Introduce
`\x` hex escape sequence in string literals for specifying raw byte values.
Refactor Unicode escape parsing into a generic `readHexEscape` function
supporting variable digit counts. Implement `wrenUtf8Decode` utility for
decoding UTF-8 sequences from byte buffers. Add comprehensive tests for
`byteAt` including boundary conditions and error cases.
2015-03-28 03:44:07 +00:00
Bob Nystrom b7904a89c9 feat: add String.fromCodePoint static method and refactor UTF-8 encoding into reusable utilities
Implement the `String.fromCodePoint(_)` primitive that creates a string from a Unicode code point, with validation for integer range 0–0x10ffff. Extract inline UTF-8 encoding logic from `readUnicodeEscape` in the compiler into new `wrenUtf8NumBytes` and `wrenUtf8Encode` utility functions in `wren_utils`, and add `wrenStringFromCodePoint` helper in `wren_value`. Update documentation for core classes to add "Methods" and "Static Methods" section headers, and include `String.fromCodePoint` docs with example. Add a test file `from_code_point.wren` covering various code points.
2015-03-27 14:43:36 +00:00
Bob Nystrom 6ff60a8c4a docs: correct encapsulation docs to state fields are private not protected in Wren
The documentation incorrectly described Wren fields as "protected" when they are actually "private". Updated the encapsulation section to accurately reflect that fields can only be accessed within the defining class, not by subclasses. This fixes issue #237.
2015-03-27 13:46:12 +00:00
Bob Nystrom 26ae448adf feat: generate runtime error when foreign method is not found
Change bindMethod return type from void to Value to propagate error string when a foreign method's C function pointer is NULL. The call site in runInterpreter now checks for a string error and triggers a runtime error, preventing silent failures on missing foreign bindings.

Add three test cases: foreign method after static declaration, foreign method with a body, and unknown foreign method that expects the new runtime error message.
2015-03-26 14:17:09 +00:00
Bob Nystrom 83e062cc71 feat: add foreign method binding for Meta class and restrict foreign lookup to core module
Add foreign static eval(source) method to Meta class in meta.wren and implement wrenBindMetaForeignMethod in wren_meta.c to handle its binding. Change the implicit module name from "main" to "core" in wren_vm.c and restrict foreign method lookup to only the "core" module, enabling Meta foreign methods to be resolved alongside IO methods. Relax the IO foreign method binder to return NULL instead of asserting for non-IO classes, allowing fallback to other library binders.
2015-03-26 03:20:26 +00:00
Bob Nystrom 2b3381e0b2 feat: add Meta class with eval method and integrate into VM and build system 2015-03-26 03:06:55 +00:00
Bob Nystrom b1360adf54 chore: add Thorbjørn Lindeijer to AUTHORS and fix Raymond Sohn email 2015-03-26 02:25:37 +00:00
Bob Nystrom c52fc1844f feat: add wren_meta source and header files to Xcode project build
Add wren_meta.c and wren_meta.h file references to the Xcode project.pbxproj, including the wren_meta.c source in the PBXBuildFile section and both files in the PBXFileReference section. Also reformat indentation in metaEval function body and add a TODO comment for argument type checking.
2015-03-26 02:25:18 +00:00
Bob Nystrom a737b542b9 feat: add Meta class with eval method and WREN_USE_LIB_META flag
Introduce a new Meta built-in class exposing a static eval(_) method for runtime code interpretation, guarded by the WREN_USE_LIB_META compile-time flag (default on). Include the meta.wren source, C implementation files, header, VM integration in wrenNewVM, test runner update to include the meta test directory, and an initial test for evaluating code that modifies an existing scoped variable.
2015-03-26 02:21:58 +00:00
Bob Nystrom e3e31f3d19 docs: add Thorbjørn Lindeijer to AUTHORS file with corrected email format 2015-03-26 02:15:58 +00:00
Bob Nystrom 90de831bd7 refactor: remove oldSize parameter from WrenReallocateFn and all call sites
Simplify the allocation API by dropping the unused `oldSize` argument from `WrenReallocateFn` typedef, its documentation, and all internal callers. Update `wrenReallocate` in `wren_vm.c` to pass only `newSize`, remove the `defaultReallocate` wrapper in favor of direct `realloc`, and adjust `generate_baseline` signature in benchmark script to match.
2015-03-25 14:45:29 +00:00
Bob Nystrom c32b586603 feat: add standard deviation calculation and color constant refactoring to benchmark script 2015-03-25 14:26:45 +00:00
Bob Nystrom a350d7c26a feat: add foreign method binding infrastructure with IO library integration
Implement the `WrenBindForeignMethodFn` callback type and `bindForeignMethodFn` configuration field to allow host applications to resolve foreign method declarations at class definition time. Refactor the IO library to use this new binding mechanism instead of the previous `wrenDefineStaticMethod` approach, adding `foreign` keyword support to the lexer and compiler. Introduce `freeCompiler` helper for cleanup, store module names in `ObjModule`, and update the VM to call the binder when processing `CODE_METHOD_INSTANCE` and `CODE_METHOD_STATIC` opcodes for foreign methods.
2015-03-24 14:58:15 +00:00
Bob Nystrom 80b24b50e8 refactor: split CFLAGS into C_WARNINGS and C_OPTIONS with pretty-printed build output
Split the monolithic CFLAGS variable into separate C_WARNINGS (warning flags) and C_OPTIONS (optimization, language, architecture flags) to improve maintainability. Added pretty-printed build commands using printf for cleaner terminal output during compilation and archiving.
2015-03-24 14:51:48 +00:00
Bob Nystrom e76e466d77 feat: add Sequence.count(predicate) method and update docs/tests
Implement a new `count(f)` method on the Sequence class that iterates over elements and returns the number of items for which the given predicate function evaluates to true. Update the core library source, sequence documentation, and add three new test files covering normal usage, non-boolean return values, and non-function argument error handling. Also fix minor terminology in list docs (items → elements).
2015-03-23 14:35:17 +00:00
Bob Nystrom 7ed5603ffc refactor: rename package module loading to module directory loading in readModule
Rename the internal concept from "package" to "module directory" when loading
module.wren files from subdirectories. Update variable names (packageModule
to moduleDir, packageModulePath to moduleDirPath) and adjust early return
logic to free modulePath before checking contents. Add test for loading
module from a directory and remove old package module test.
2015-03-23 13:48:08 +00:00
Bob Nystrom 1929f272fa refactor: extract wrenFilePath helper and add package module fallback in readModule
Extract the module-to-filepath construction logic from readModule into a reusable wrenFilePath function. Modify readModule to first attempt loading the module with a ".wren" extension; if that fails, treat the module name as a package directory and try loading "module.wren" from within it. Add test fixtures for the new package module resolution behavior.
2015-03-23 13:42:03 +00:00
Bob Nystrom a6ad88c9cd chore: remove duplicate build result patterns and reorder Xcode entries in .gitignore 2015-03-23 13:33:29 +00:00
Bob Nystrom 0937a8d3f8 feat: restructure MSVC solution to separate wren_lib static library from wren CLI project
Add new wren_lib static library project with all VM source files, update wren CLI project to depend on wren_lib and link against it, move VM sources out of CLI project filters, and add Debug/Release build output directories to .gitignore
2015-03-23 13:32:29 +00:00
Bob Nystrom 46b6763877 refactor: rename Upvalue to ObjUpvalue for consistency with Obj naming convention
Rename the `Upvalue` struct and all related type references to `ObjUpvalue` across
wren_value.c, wren_value.h, and wren_vm.c. This aligns with the existing pattern
where Obj-derived types (like ObjModule, ObjClosure) use the Obj prefix even when
the type is not first-class in the language. The change touches function signatures,
variable declarations, pointer arithmetic in memory tracking, and the struct
definition itself.
2015-03-23 05:31:03 +00:00
Bob Nystrom 15f9273aab refactor: remove unused WrenVM* parameter from buffer init, string find, and debug print functions
Remove the `WrenVM* vm` parameter from `wrenValueBufferInit`, `wrenByteBufferInit`,
`wrenIntBufferInit`, `wrenStringBufferInit`, `wrenSymbolTableInit`,
`wrenMethodBufferInit`, `wrenStringFind`, and `wrenDebugPrintStackTrace`
functions across the compiler, core, debug, utils, value, and VM modules.
Update all call sites and macro definitions to match the simplified signatures,
eliminating dead parameters that were never used within the function bodies.
2015-03-23 05:17:40 +00:00
Bob Nystrom 580f04be1a chore: remove redundant -Wsign-compare -Wtype-limits -Wuninitialized from CFLAGS in wren.mk
The build configuration in script/wren.mk had three redundant warning flags
(-Wsign-compare, -Wtype-limits, -Wuninitialized) that were already covered
by -Wextra. Also updated the TODO comment to explain why -Wno-unused-parameter
remains necessary due to heavy callback usage in Wren's codebase.
2015-03-23 05:17:29 +00:00
Bob Nystrom 7385ab2430 chore: enable -Wextra warnings and fix loadIntoCore declaration order 2015-03-23 04:49:31 +00:00
Bob Nystrom 96a829fc8f refactor: replace ObjList manual array management with ValueBuffer in Compiler and ObjList
Replace the hand-rolled capacity/count/elements fields in ObjList with a
ValueBuffer struct, and update Compiler to use a ValueBuffer for its
constant pool instead of an ObjList. This eliminates the separate
ensureListCapacity and wrenListAdd functions, centralizing buffer growth
logic in wrenValueBufferWrite. Adjust all list primitives (add, clear,
count, iterate, iteratorValue) and the GC marking path to operate on the
embedded ValueBuffer. Add wrenMarkBuffer helper for marking buffer
contents during sweep.
2015-03-22 19:22:47 +00:00
Bob Nystrom 899a4ec76e chore: enable clang suspicious implicit conversion warning and fix related type narrowing issues
Add CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES to both Debug and Release Xcode build configurations. Fix the resulting warnings by adding explicit casts in wren_compiler.c (readUnicodeEscape, emit, emitShort, emitByteArg) and wren_vm.c (READ_SHORT macro, makeCallStub bytecode assignment) to prevent unintended truncation or sign extension during implicit integer conversions.
2015-03-22 17:36:08 +00:00
Bob Nystrom 4343b95c04 fix: restructure REPL loop to eliminate unreachable code after fgets failure
The original REPL loop had an if-else structure where the else branch (handling fgets failure) contained a return statement, making the code after the if-else block unreachable. This commit restructures the loop by inverting the condition: when fgets fails, the loop breaks instead of returning, allowing the subsequent wrenFreeVM call to execute. Additionally, enables CLANG_WARN_UNREACHABLE_CODE in both Debug and Release Xcode build configurations to catch similar issues in the future.
2015-03-22 17:26:54 +00:00
Bob Nystrom 295a408858 refactor: extract instance-of check into separate isInstanceOf helper function 2015-03-21 23:50:27 +00:00
Bob Nystrom 65305fca09 refactor: remove inline local variable declarations in list primitives and delete redundant math primitives from wren_core.c
Consolidate temporary variable usage in list_add, list_count, and list_iterate by directly inlining AS_LIST/AS_NUM calls. Remove the entire block of num_abs, num_acos, num_asin, num_atan, num_atan2, num_ceil, num_cos, num_floor, and num_fraction primitive definitions to eliminate boilerplate.
2015-03-21 21:57:43 +00:00
Bob Nystrom d04057bf75 feat: add trigonometric methods and Num.pi constant to core library
Add acos, asin, atan, atan2, tan methods to Num class and expose Num.pi constant with value π. Include corresponding C primitives in wren_core.c and test files for each new method.
2015-03-21 19:54:08 +00:00
Bob Nystrom 52e0f4b1c0 fix: ensure step is always initialized before range validation in calculateRange 2015-03-21 19:32:31 +00:00
Bob Nystrom 07240ccb00 refactor: migrate list index and size types from int to uint32_t across core and value layers
Convert `validateIndexValue` and `validateIndex` return types to `uint32_t` with `UINT32_MAX` sentinel, update `wrenNewList`, `wrenListInsert`, `wrenListRemoveAt` signatures, and remove the TODO comment about type unification with `ObjMap`.
2015-03-21 19:22:04 +00:00
Bob Nystrom 69f135cc43 fix: change list capacity and count fields from int to uint32_t for consistency 2015-03-21 15:46:01 +00:00
Bob Nystrom 28fdc8372f fix: replace silent early return with assertion in wrenFreeVM for freed VM detection 2015-03-20 15:00:52 +00:00
Bob Nystrom 15e965c5eb fix: add null and already-freed guard to wrenFreeVM to prevent double-free crash
Add early return check in wrenFreeVM that validates the VM pointer is not NULL
and that the methodNames count is non-zero, preventing a crash when the VM
has already been freed or was never properly initialized.
2015-03-20 14:56:32 +00:00
Bob Nystrom 398a693d3c fix: replace constant-time string hash with full O(n) scan over all bytes 2015-03-19 14:38:05 +00:00
Bob Nystrom b33f16152a feat: move contains method from List to Sequence and add tests for list and range
Add a generic `contains(element)` method to the `Sequence` class that iterates over elements using the existing `for` loop protocol, removing the duplicate implementation from `List`. Include comprehensive test files for both `List.contains` and `Range.contains` covering ordered, backwards, and exclusive ranges. Also fix the `generate_builtins.py` script to write to the correct `src/vm/` directory path and add a `float:left` CSS rule to the main content area in the documentation stylesheet.
2015-03-19 14:29:07 +00:00
Bob Nystrom 550fd13565 chore: relocate AS_* and IS_* macros to top of wren_value.h for better organization 2015-03-19 14:28:53 +00:00
Bob Nystrom a91361fa2f fix: update source file paths in generate_builtins.py to include vm subdirectory
The script/generate_builtins.py was reading from and writing to incorrect source file paths
under src/ instead of the correct src/vm/ directory, causing builtins generation to fail
when the source files were relocated to the vm subdirectory.
2015-03-18 14:55:18 +00:00
Bob Nystrom a15bf3136e feat: move List.contains to Sequence.contains and add tests for List and Range
The contains method is promoted from List to the Sequence base class, making it available to all sequence types (including Range). Tests are added for both List.contains and Range.contains, covering ordered, backwards, and exclusive ranges.
2015-03-18 14:54:55 +00:00