Commit Graph
100 Commits
Author SHA1 Message Date
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
Bob Nystrom b7d0b4b73e fix: add float left to main element to fix unreachable links in IE11 edge mode
The main content area lacked a float property causing links to be unreachable
in Internet Explorer 11 when running in edge mode. Adding float:left restores
proper link clickability for IE11 users.
2015-03-18 14:52:31 +00:00
Bob Nystrom 1e842bbb2e feat: store precomputed hash in ObjString and use it for equality and hashing
Cache the FNV-1a hash code in the ObjString struct at creation time, replacing the
on-the-fly sampling hash in hashObject() and enabling constant-time string equality
checks. Refactor string allocation into allocateString() and hashString() helpers,
remove the old wrenNewUninitializedString() declaration, and add a CONST_STRING
macro. Disable the unimplemented subscript range operator with a runtime error and
skip the related UTF-8 tests. Add a string_equals benchmark to measure the speedup.
2015-03-18 14:09:03 +00:00
Bob Nystrom a3418dc06a feat: swap list insert arguments to index-first order and update all call sites
Swap the parameter order of `List.insert()` from `(item, index)` to `(index, item)`,
matching the convention used by most standard libraries. Update the C implementation
in `wren_core.c`, all documentation examples, and every test file to reflect the new
signature. Also restructure MSVC project files to match the new `src/cli/` and
`src/vm/` directory layout, add Visual Studio cache files to `.gitignore`, and fix
a trailing whitespace issue in `class_supertype`.
2015-03-17 14:01:09 +00:00
Bob Nystrom f6da4700f4 fix: guard string hash loop against zero-length strings causing division by zero 2015-03-17 14:00:54 +00:00
Bob Nystrom 0d42d87689 feat: reverse List.insert argument order to index-first, value-second
The `List.insert` method signature is changed from `insert(item, index)` to `insert(index, item)`, aligning with standard practice in most languages. All documentation, core implementation, and test files are updated to reflect the new parameter order. The `validateIndex` call now reads the index from slot 1 instead of slot 2, and the value is read from slot 2.
2015-03-16 16:18:59 +00:00
Bob Nystrom bf7295d01b fix: update MSVC project file paths and add include directories for build fix
Update the Visual Studio 2013 project to reflect the source file reorganization where source files moved from `src/` to `src/cli/` and `src/vm/` subdirectories, and headers moved from `include/` to `src/include/`. Add explicit `IncludePath` entries for Debug and Release configurations to ensure the compiler can locate the new header locations. Also extend `.gitignore` with Visual Studio cache and user-specific file patterns to prevent build artifacts from being tracked.
2015-03-16 16:16:54 +00:00
Bob Nystrom 76baf731db refactor: extract CLI VM creation and file execution into separate vm.c/vm.h
Move runFile() and VM configuration logic from main.c into new vm.c module,
exposing createVM() and runFile() functions. This decouples CLI script
execution from the REPL and main entry point, enabling reuse of the same
VM setup and file-running code for API tests.
2015-03-16 14:42:45 +00:00
Bob Nystrom 11a61b47ab feat: extract CLI file loading functions into separate io.c and io.h
Extract the static `readFile`, `readModule`, and `setRootDirectory` functions from main.c into a new io module, replacing the fixed-size `rootDirectory` array with a heap-allocated pointer and adding the corresponding header with public declarations.
2015-03-16 14:22:52 +00:00
Bob Nystrom db365ae9fa fix: correct object type label in dumpObject for OBJ_RANGE case
The dumpObject function in wren_debug.c was incorrectly printing "[fn %p]" for
OBJ_RANGE objects instead of the correct "[range %p]" label. This fix ensures
that range objects are properly identified during debug output.
2015-03-16 14:05:40 +00:00
Bob Nystrom a73ee9a8e7 fix: pass missing argName to wrenStringFormat in validateIntValue and validateIndexValue
The two validation functions in wren_core.c were calling wrenStringFormat with a format
string containing a "$" placeholder but were not passing the argName argument, causing
the placeholder to remain unsubstituted in error messages. This commit adds the missing
argName parameter to both calls.

Additionally, the CONST_STRING macro in wren_value.h was changed from using strlen(text)
to sizeof(text) - 1, which allows the compiler to compute the string length at compile
time rather than at runtime, improving performance for string literal creation.
2015-03-16 06:17:08 +00:00
Bob Nystrom e95b32188f refactor: replace sizeof-based string length with strlen in CONST_STRING macro
The previous implementation used `sizeof(text) - 1` to determine string length at compile time, which required the argument to be a bare string literal. The new approach uses `strlen(text)` instead, which allows most compilers to evaluate the string length at compile time when a string literal is passed, while also supporting non-literal string arguments. This change trades compile-time guarantee for broader compatibility and compiler optimization potential.
2015-03-16 06:07:20 +00:00
Bob Nystrom 9314cbfd72 refactor: replace manual string concatenation with wrenStringFormat across VM core
Replace ad-hoc string construction using wrenNewString, wrenStringConcat, and sprintf with the new wrenStringFormat helper. This centralizes string formatting logic, reduces code duplication, and eliminates manual length calculations in wren_compiler.c, wren_core.c, wren_value.c, and wren_vm.c. Also introduces CONST_STRING macro for compile-time string literals and changes wrenNewUninitializedString return type from Value to ObjString* for consistency.
2015-03-16 05:32:20 +00:00
Bob Nystrom d01173048b fix: update metrics script glob paths and remove benchmark walk
Update source file glob patterns from flat "src/*.[ch]" and "include/*.[ch]" to
nested "src/vm/*.[ch]" and "src/include/*.[ch]" to match new directory layout.
Remove the entire benchmark directory walk loop that counted benchmark files,
empty lines, non-empty lines, and TODO patterns, as benchmark data is no longer
collected in this script.
2015-03-16 05:07:06 +00:00
Bob Nystrom d731e554e6 refactor: rename debug print functions to dump and move value printing to wren_debug.c 2015-03-15 17:09:43 +00:00
Bob Nystrom cf3db93a06 refactor: remove failIf helper and return NULL on missing file in readFile 2015-03-15 17:09:22 +00:00
Bob Nystrom 18cf57d5f5 refactor: split source tree into vm/ and cli/ directories with updated build system
Separate Wren VM library sources from CLI tool sources by moving them into
src/vm/ and src/cli/ subdirectories respectively. Update the Makefile to use
separate wildcard patterns for each directory, generate distinct object file
paths under build/vm/ and build/cli/, and adjust include paths to src/include.
Also update the Xcode project file to reference the new file locations.
2015-03-14 22:00:50 +00:00
Bob Nystrom c4ef964f92 refactor: move benchmark directory under test and update all references
The benchmark directory is relocated from the project root into the test directory, and all scripts, documentation links, and gitignore paths are updated accordingly. The test runner is also refactored to explicitly walk subdirectories (core, io, language, limit) instead of using a single test root, and a new test/README.md is added to document the test suite structure. Additionally, the constructor test for the Foo class is updated to add a zero-arity constructor and adjust expected output strings.
2015-03-14 19:45:56 +00:00
Bob Nystrom af58528e88 chore: move gh-pages output directory under build/ and update .gitignore
The gh-pages directory is now created inside build/ instead of at the project root.
The .gitignore entry for the old gh-pages location is removed, and the Makefile
cp target is updated from gh-pages to build/gh-pages.
2015-03-14 19:19:03 +00:00