Commit Graph
100 Commits
Author SHA1 Message Date
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
Bob Nystrom 3f3955b1c3 fix: move fails list initialization before try block in run_test
The fails list was initialized after the try-except block that appends to it,
causing an UnboundLocalError when decoding fails. This commit moves the
initialization before the try block to ensure the list exists when accessed.
2015-03-14 16:49:55 +00:00
Bob Nystrom 8436ead62e feat: add Class.supertype primitive and documentation for retrieving superclass
Implement a new `supertype` property on Class objects that returns the superclass of a given class. The primitive `class_supertype` checks if the class has a superclass (returning null for Object) and returns the superclass object. Includes documentation in the class reference and a test file verifying behavior for explicit superclasses, implicit Object inheritance, and Object's null supertype.
2015-03-14 16:48:45 +00:00
Bob Nystrom 3c44a3a001 refactor: replace manual zero-initialization with memset in wrenNewVM
Remove explicit NULL and zero assignments for vm fields (methodHandles, foreignCallSlot, foreignCallNumArgs, bytesAllocated, compiler, fiber, first, numTempRoots, modules) and consolidate them into a single memset(vm, 0, sizeof(WrenVM)) call, simplifying the initialization logic.
2015-03-14 16:36:27 +00:00
Bob Nystrom f2693f57ad refactor: extract DEBUG_TRACE_INSTRUCTIONS macro and fix RUNTIME_ERROR brace style in runInterpreter
Moves the debug trace instruction printing logic from inline DISPATCH() macro into a dedicated DEBUG_TRACE_INSTRUCTIONS macro with proper WREN_DEBUG_TRACE_INSTRUCTIONS guard, and adjusts RUNTIME_ERROR macro to use Allman brace style for consistency with surrounding code.
2015-03-14 16:29:17 +00:00
Bob Nystrom 32a3688e60 fix: handle malformed UTF-8 output in test runner decode calls
Wrap stdout and stderr decode calls in try-except to catch UnicodeDecodeError when test output contains invalid UTF-8 byte sequences, appending a failure message instead of crashing the test runner.
2015-03-14 15:47:31 +00:00
Bob Nystrom 7bef4e0001 docs: condense operator precedence table by merging rows and abbreviating headers 2015-03-13 14:56:47 +00:00
Bob Nystrom e52573c3f6 fix: change infinity string representation from "inf" to "infinity" in num_toString
Update the num_toString primitive in wren_core.c to return "infinity" and "-infinity"
instead of the platform-dependent "inf" and "-inf" for positive and negative infinity
values. This ensures consistent string output across different C compilers and
platforms that may format infinity differently. Update the corresponding test
expectations in test/number/divide.wren to match the new output format.
2015-03-13 14:35:10 +00:00
Bob Nystrom 9c56d90e1c fix: cast size_t arguments to unsigned long for consistent printf format across architectures 2015-03-13 14:27:11 +00:00
Bob Nystrom e2555a0b96 chore: remove boilerplate comment block and fix include guard in wren_debug.h
Remove the Xcode-generated file header comment with copyright notice
and author attribution from wren_debug.h. Also correct the include guard
macro from `wren_wren_debug_h` to `wren_debug_h` to match the actual
file path and naming convention used by other headers in the project.
2015-03-13 14:26:42 +00:00
Bob Nystrom a308c16a25 fix: normalize Windows backslashes to forward slashes in test path
The `run_test` function in `script/test.py` now replaces backslash characters with forward slashes after computing the relative path, ensuring consistent path formatting for the wren interpreter across platforms.
2015-03-13 14:26:23 +00:00
Bob Nystrom 6797c2ef77 fix: correct comment and fix typo in wren compiler and vm
- Update comment in `new_` function to accurately describe how angle brackets prevent direct user calls to `<instantiate>` method
- Fix spelling error in assertion message from "Uknown" to "Unknown" in `wrenCall` function
- Remove trailing whitespace in `wren_vm.c`
2015-03-13 14:25:12 +00:00
Bob Nystrom 005a616cd6 style: refactor precedence table styles and add associativity mention in expressions doc 2015-03-13 14:24:45 +00:00
Bob Nystrom 99ae2946be docs: replace operator precedence dart code block with styled HTML table in expressions doc
Add a new `table.precedence` CSS rule in style.scss to style the precedence table with full width, left padding, and consistent font sizing. Convert the existing Dart-formatted operator precedence list in doc/site/expressions.markdown into an HTML table with columns for precedence level, operator, description, and associativity, including all operators from call/subscript/selection down to assignment.
2015-03-12 14:27:31 +00:00
Bob Nystrom eea7803aae fix: correct comment and fix typo in wren compiler and vm files
- Fix misleading comment in `new_` function in `wren_compiler.c` to accurately describe angle brackets instead of leading space
- Fix typo "Uknown" to "Unknown" in assertion message in `wrenCall` function in `wren_vm.c`
- Remove trailing whitespace in `wren_vm.c`
2015-03-12 14:26:29 +00:00
Bob Nystrom 101c94802b fix: pass char* buffer instead of ObjString to error() in wrenCompile
In the variable undefined check within wrenCompile, the error() call was
receiving an ObjString struct instead of its underlying char* buffer,
causing a type mismatch. Changed the argument to access the .buffer field
of the variable name string.
2015-03-11 14:31:18 +00:00
Bob Nystrom 146995d54d chore: remove outdated TODO comments across compiler, core, value, and vm headers
- Delete TODO about nullary constructor handling in constructorSignature
- Remove TODO and commented-out code for making fibers iterable in wrenInitializeCore
- Eliminate TODO questioning elimination of OBJ_CLASS enum in favor of classObj pointers
- Drop TODO about moving WrenVM struct definition and using array for class fields
2015-03-07 22:10:34 +00:00
Bob Nystrom 250a855d82 fix: return null from IO.read on EOF instead of empty string
Previously, IO.read would return an empty string when stdin reached EOF because it always called wrenReturnString with the buffer, even when fgets returned NULL. Now it returns null by only calling wrenReturnString when fgets succeeds, and adds a test case verifying that IO.read returns null on EOF.
2015-03-07 21:47:07 +00:00
Bob Nystrom 3979a7dfff refactor: replace wrenMapFind with wrenMapGet returning Value instead of index
Refactor the internal Map API to replace the low-level `wrenMapFind` function
(which returned a raw entry index or UINT32_MAX) with a higher-level
`wrenMapGet` that directly returns the stored Value or UNDEFINED_VAL.

This change simplifies all call sites by eliminating manual index-based entry
lookups and direct access to the internal `entries` array. The old
`wrenMapFind` is made static and renamed to `findEntry`, returning a pointer
to the MapEntry struct instead of an index, which is used internally by
`wrenMapGet` and `wrenMapRemoveKey`.

Additionally, fix a bug in `loadModule` where a new module was always created
before checking if the module already existed; now the early return for
already-loaded modules correctly skips module creation and variable copying.
2015-03-07 20:41:18 +00:00
Bob Nystrom f1fd125385 feat: allow yielding main fiber and expose current fiber reference
- Change Fiber.yield() to exit interpreter when no parent fiber exists instead of raising runtime error
- Add Fiber.current primitive to return the currently executing fiber object
- Update interpreter loop to stop execution when PRIM_RUN_FIBER receives null value
- Modify test expectations to reflect new yielding behavior from main fiber
2015-03-07 20:32:11 +00:00
Bob Nystrom 7dcd39f512 fix: remove deprecated num_deg and num_rad primitives, simplify num_fraction implementation 2015-03-07 06:52:42 +00:00
Bob Nystrom 92d72be158 feat: add deg, rad, fraction, sign, truncate primitives to num class
Add five new numeric methods to the Wren core library: deg (convert radians to degrees), rad (convert degrees to radians), fraction (extract fractional part), sign (return -1, 0, or 1), and truncate (discard fractional part). Register all new primitives in wrenInitializeCore and include corresponding test files for fraction, sign, and truncate operations.
2015-03-07 06:43:02 +00:00
Bob Nystrom b712bb1929 feat: add count method to Sequence class with iteration-based element tally
Implement a `count` method on the `Sequence` class that iterates over all elements and returns the total number. The method uses a simple for-loop to increment a counter for each element, providing a generic way to determine sequence length without requiring a separate length property. Includes a test sequence that yields values 1 through 10 to verify the count returns 10.
2015-03-06 15:01:02 +00:00
Bob Nystrom 69f6f2e71c refactor: replace index-based for loops with idiomatic iteration in delta_blue planner
Replace C-style index loops (`for (i in 0...collection.count)`) with direct element iteration (`for (element in collection)`) across five methods in the `Planner` class: `removePropagateFrom`, `extractPlanFromConstraints`, `addConstraintsConsumingTo`, and two anonymous loops in the constraint propagation logic. This improves readability and aligns with Wren's idiomatic iteration patterns without changing behavior.
2015-03-04 15:16:56 +00:00
Bob Nystrom 6519dbf70e refactor: replace per-type mark helpers with unified wrenMarkObj in GC marking
Remove the dedicated `setMarkedFlag`, `markString`, `markFn`, and `markClass` helper functions, replacing their calls with the new generic `wrenMarkObj` entry point. This eliminates duplicated marking logic and ensures all object types go through a single marking path that handles cycle detection and memory tracking consistently.
2015-03-04 15:08:48 +00:00
Bob Nystrom 4781e77809 feat: add Sequence.any method and update docs, tests, and core source
Implement the `any` method on the Sequence class that returns true if any element passes the given predicate function. Update the core.wren library source, the C embedded source string in wren_core.c, and add comprehensive test files for normal usage, non-bool return values, and non-function argument error handling. Also fix a typo in the QA documentation and correct the initial account balance in the example.
2015-03-03 15:23:47 +00:00
Bob Nystrom a8fa458ab7 refactor: rename NATIVE/DEF_NATIVE macros to PRIMITIVE/DEF_PRIMITIVE and add DEALLOCATE macro
Extract shared number parsing logic into makeNumber helper with errno overflow checking, replace all direct wrenReallocate(ptr,0,0) calls with DEALLOCATE macro, and add test cases for too-large number literals in decimal and hex formats.
2015-03-03 15:20:43 +00:00
Bob Nystrom f809e4a1f1 refactor: extract shared makeNumber helper and fix OBJ_VAL wrapping in num_fromString
Extract the duplicated number parsing logic from readHexNumber and readNumber into a single makeNumber function that accepts an isHex flag. Also fix a missing OBJ_VAL wrapper in the num_fromString primitive's ERANGE error path and normalize trailing newlines in three test files.
2015-03-03 15:17:56 +00:00
Bob Nystrom 2eff9633ae fix: correct comment in DEALLOCATE macro to use "allocator" instead of "allocate"
The comment for the DEALLOCATE macro in wren_common.h previously read "Use the VM's allocate to free"
which was grammatically incorrect and misleading. Changed "allocate" to "allocator" to accurately
describe that the macro uses the VM's memory allocator function to free memory at the given pointer.
2015-03-02 15:32:09 +00:00
Bob Nystrom 09a7a126b0 feat: add DEALLOCATE macro and replace direct wrenReallocate calls for freeing memory
Introduce a DEALLOCATE macro that wraps wrenReallocate(vm, pointer, 0, 0) to provide a consistent, readable interface for freeing allocated memory. Replace all existing direct wrenReallocate calls used for deallocation across wren_core.c, wren_utils.c, wren_value.c, and wren_vm.c with the new macro. Also remove two stale TODO comments in wren_core.c related to testing and unimplemented map methods.
2015-03-02 15:31:46 +00:00
Bob Nystrom 8897c6a0a5 refactor: rename NATIVE/DEF_NATIVE macros to PRIMITIVE/DEF_PRIMITIVE across wren_core
Rename the NATIVE macro to PRIMITIVE and DEF_NATIVE to DEF_PRIMITIVE, updating all
corresponding function prefixes from native_ to prim_ to maintain consistency with
the existing METHOD_PRIMITIVE type and terminology used throughout the codebase.
2015-03-02 15:24:04 +00:00
Bob Nystrom 3e37778acb fix: fallback to gcc when cc is missing on MinGW in wren.mk
The OS detection now uses `gcc -dumpmachine` directly instead of `$(CC)` to avoid failures when CC is not defined by MSYS. Additionally, when the OS is detected as mingw32, CC is explicitly set to gcc to work around missing cc executable on some MinGW versions.
2015-03-01 17:25:48 +00:00
Bob Nystrom cb10020de5 chore: add Raymond Sohn to AUTHORS file and fix missing newline at EOF
The AUTHORS file was missing a trailing newline after Marco Lizza's entry.
This commit adds the missing newline and appends Raymond Sohn as a new
contributor to the project.
2015-03-01 16:40:17 +00:00
Bob Nystrom d6570cccce docs: expand static field documentation with instance access examples and null initialization note 2015-03-01 16:39:53 +00:00
Bob Nystrom 0b569194ef docs: add static field usage example to classes documentation 2015-03-01 16:34:11 +00:00
Bob Nystrom e00ea68927 chore: add Raymond Sohn to AUTHORS file with email address
The diff appends a new entry for Raymond Sohn with email raymondsohn@gmail.com
to the AUTHORS file, following the existing contributor list format.
2015-03-01 16:33:06 +00:00
Bob Nystrom f46b93976b fix: refactor fibonacci benchmark from closure to static class method 2015-03-01 16:20:55 +00:00
Bob Nystrom c11bb88105 perf: replace recursive closure with static method in fib benchmark for faster execution 2015-03-01 00:51:41 +00:00
Bob Nystrom aa5113ba77 fix: remove dead commented code and add null check for sourcePath in stack trace 2015-02-28 21:51:19 +00:00
Bob Nystrom ff420c816b feat: add wrenGetMethod, wrenCall, and wrenReleaseMethod for invoking Wren methods from C code 2015-02-28 21:31:15 +00:00
Bob Nystrom 091860b89d fix: add dedicated markRange function to correctly count ObjRange memory in GC 2015-02-28 17:09:57 +00:00
Bob Nystrom cf9d568469 fix: guard GC trigger to only fire on allocation, not deallocation 2015-02-28 05:41:59 +00:00
Bob Nystrom f77944a56c docs: add detailed documentation for benchmark runner script explaining trial methodology and baseline comparison 2015-02-28 05:34:07 +00:00
Bob Nystrom 3a8bc85674 refactor: extract validateSuperclass helper and move subclassing tests to inheritance directory 2015-02-27 16:08:27 +00:00
Bob Nystrom d7d067b960 feat: prevent subclassing of built-in types with runtime error
Add a check in the interpreter's class creation path that rejects attempts to subclass any of the seven core built-in types (Class, Fiber, Fn, List, Map, Range, String). When such a subclass is declared, a runtime error is raised with a message like "Class 'SubName' may not subclass a built-in". Also add corresponding test files for each forbidden subclass scenario.
2015-02-27 15:41:25 +00:00
Bob Nystrom fdcd1fdf03 docs: update ceil/floor examples with negative numbers and range docs to use non-integer values 2015-02-27 15:37:58 +00:00
Bob Nystrom ec9188ba96 docs: add ceil, floor, and range operator documentation to Num class doc page 2015-02-27 15:30:58 +00:00
Bob Nystrom 1dfdcb05a7 chore: encode stdin input as utf-8 bytes and remove extra newlines in test output 2015-02-27 15:22:27 +00:00
Bob Nystrom 08f40299f0 refactor: extract signature stringification into dedicated helper and update callers
The `signatureSymbol` function previously built a method name string as a side effect before hashing it. This change separates the stringification logic into a new `signatureToString` function that writes the full signature name into a provided buffer and updates its length. All callers now use the new helper, making the code clearer and allowing the stringified signature to be reused independently of symbol lookup.
2015-02-27 15:10:44 +00:00
Bob Nystrom 469f64fa9a refactor: remove endToken parameter and error handling from finishParameterList
The finishParameterList function no longer needs to consume the closing delimiter
or produce error messages, as that responsibility has been moved to the callers.
The parameterList wrapper function has been inlined into its single call site,
simplifying the parameter parsing flow.
2015-02-27 14:51:37 +00:00
Bob Nystrom 5382fa05d7 feat: allow empty argument list methods in calls, definitions, and docs
- Compile empty `()` as a valid method signature distinct from no parentheses
- Update `call()`, `clear()`, `run()`, `try()`, and `yield()` to use empty argument lists
- Revise documentation across multiple files to reflect new signature semantics
2015-02-27 07:08:36 +00:00
Bob Nystrom 94f34367f9 feat: switch method signatures to parenthesized parameter notation and update error messages
The method signature format has been changed from space-counted arity (e.g., "== ") to explicit parenthesized parameter lists (e.g., "==(_)"). This required updating the MAX_METHOD_SIGNATURE calculation to account for parentheses and parameter separators, replacing the old copyName helper with a new Signature struct and SignatureType enum, and rewriting the methodNotFound error message to display the full signature string instead of reconstructing arity from trailing spaces. All core method registrations in wren_core.c, wren_io.c, and corresponding test expectations have been updated to use the new signature format.
2015-02-27 05:56:15 +00:00
Bob Nystrom a24f51d4af feat: replace separate methodName/arity params with unified signature string in foreign method API
The wrenDefineMethod and wrenDefineStaticMethod functions now accept a single `signature` string parameter instead of separate `methodName` and `arity` arguments. This simplifies the API by letting callers specify the full method signature (including arity spaces) directly, removing the internal arity-to-spaces conversion logic in defineMethod. The change updates the header declaration, the internal defineMethod helper, and all call sites in wren_io.c to pass pre-formatted signatures.
2015-02-26 15:44:45 +00:00
Bob Nystrom a12b1695a7 docs: document NULL return behavior for wrenCompile on syntax errors 2015-02-26 15:37:10 +00:00
Bob Nystrom 8fb17b57f1 feat: split monolithic PREC_BITWISE into separate precedence levels for |, ^, &, and << >> in wren_compiler.c
Add new Precedence enum values (PREC_BITWISE_OR, PREC_BITWISE_XOR, PREC_BITWISE_AND, PREC_BITWISE_SHIFT) and a PREC_TERNARY level between assignment and logical operators. Update and_(), or_(), and conditional() to use the refined precedence constants. Include a test file verifying correct associativity and precedence ordering among bitwise operators (|, &, ^, <<) in expressions.
2015-02-25 15:14:31 +00:00
Bob Nystrom 3aa82e7960 fix: reject trailing non-number characters in Num.fromString parsing
Previously, `Num.fromString` accepted strings like `"1.2prefix"` and returned the
leading numeric portion (`1.2`). This change makes parsing stricter by requiring
that the entire string be consumed after `strtod`, skipping only trailing
whitespace. If any non-whitespace characters remain after the number, the
function now returns `null` instead of a partial result.

The fix also adds an explicit empty-string check and updates the test suite to
reflect the new behavior, replacing the old `"1.2prefix"` success test with a
`"1.2suffix"` null-return test.
2015-02-25 15:07:54 +00:00
Bob Nystrom f0a73b6ce2 feat: add Num.fromString static method to parse decimal strings into numbers
Implement a new `Num.fromString(value)` method that attempts to parse a string as a decimal literal and returns the corresponding `Num` instance, or `null` if parsing fails. The implementation uses `strtod` for conversion, validates the argument is a string at runtime, and includes tests for valid numbers, edge cases like leading/trailing whitespace and partial suffix parsing, non-number inputs returning null, and a runtime error when a non-string argument is passed. Also fixes a missing semicolon in the `toString` native registration and removes the hex literal TODO from the number literals test.
2015-02-25 14:53:12 +00:00
Bob Nystrom 766d9792a4 fix: correct missing closing parenthesis in removeAt example code 2015-02-25 14:49:42 +00:00
Bob Nystrom d57319e80a fix: use BENCHMARK_DIR constant for baseline file path in benchmark script 2015-02-25 06:08:57 +00:00
Bob Nystrom c9f0dcde66 fix: convert signed integer types to unsigned in core and value modules to eliminate -Wsign-compare warnings
- Change `int` to `uint32_t` for iterator indices in `map_iterate` and `string_iterate` to match capacity/length types
- Update `String.length` field type from `int` to `uint32_t` in `wren_utils.h`
- Modify `wrenStringCodePointAt` parameter type from `int` to `uint32_t` and remove redundant negative index assertion
- Convert loop variable in `markMap` from `int` to `uint32_t` to match `map->capacity` type
- Add `-Wsign-compare`, `-Wtype-limits`, and `-Wuninitialized` compiler flags to catch future mismatches
2015-02-25 05:56:33 +00:00
Bob Nystrom fca963cb48 fix: ensure UINT32_MAX is available in gcc C++ builds by defining __STDC_LIMIT_MACROS before including stdint.h in wren_common.h 2015-02-25 05:09:04 +00:00
Bob Nystrom 29e8708812 fix: add missing stdint.h include for UINT32_MAX in wren_core.c
The UINT32_MAX macro is defined in <stdint.h> but was not included, causing
compilation errors on platforms where it is not implicitly pulled in by other
headers. This commit adds the missing include to ensure the constant is
available for use in the source file.
2015-02-25 04:26:39 +00:00
Bob Nystrom 6396151732 fix: install gcc-multilib for 32-bit compilation support on 64-bit Travis CI VMs
Add before_install step to .travis.yml that updates apt packages and installs
gcc-multilib, enabling 32-bit C library headers and runtime for cross-compilation
in the CI environment.
2015-02-25 04:26:24 +00:00
Bob Nystrom f940f2d9d2 fix: use BENCHMARK_DIR constant for baseline file path in read and write operations
The baseline file path was hardcoded as "benchmark/baseline.txt" in both read_baseline() and generate_baseline() functions, ignoring the BENCHMARK_DIR constant. This caused the baseline file to be created in the wrong directory when BENCHMARK_DIR differed from the default "benchmark" path. Changed both functions to construct the path using os.path.join(BENCHMARK_DIR, "baseline.txt") for consistency and correctness.
2015-02-25 03:49:29 +00:00
Bob Nystrom 6596537e87 refactor: replace platform-specific getcwd with empty root directory for relative imports
Remove conditional getcwd logic for MSVC and POSIX, replacing it with a simple
empty root directory string. This simplifies the import path resolution by
always using relative paths from the current working directory instead of
attempting to resolve an absolute root path at startup.
2015-02-25 03:47:17 +00:00
Bob Nystrom 9d700df1cd fix: replace dynamic allocation with static buffer for rootDirectory in main.c
- Add platform-specific getcwd header includes for MSVC and POSIX
- Replace malloc-based rootDirectory assignment with a static 2048-byte buffer
- Initialize rootDirectory to point to the static buffer instead of an empty string
- Update runFile to use const char* for lastSlash and copy path directly into buffer
- Implement TODO in runRepl by calling getcwd to set rootDirectory to current working directory
2015-02-25 03:43:12 +00:00
Bob Nystrom 77148c2db6 chore: switch travis build script from make to make all for full configs 2015-02-25 03:32:46 +00:00
Bob Nystrom 8022c2b3c2 feat: allow multiple wrenInterpret calls to share module state for REPL
Initialize vm->modules to NULL in wrenNewVM and create a module registry map to track loaded modules. In loadModule, check if a module has already been loaded via wrenMapFind; if found, reuse the existing module object instead of creating a new one, enabling successive wrenInterpret calls to execute in the same module context and preserve variable bindings across REPL invocations.
2015-02-23 15:02:27 +00:00
Bob Nystrom 708b883e1f fix: correct typos in Fn class documentation for parameter name and grammar 2015-02-22 20:34:32 +00:00
Bob Nystrom f51847e9f4 refactor: extract call method helpers and clean up comment formatting in wren_compiler.c
Extract `callMethodInstruction` and `callMethod` helper functions from the
existing `methodCall` function to reduce code duplication and improve
readability. Also fix comment formatting for argument arity overloading
and block argument inclusion.
2015-02-22 19:04:43 +00:00
Bob Nystrom c1fc6adcb4 feat: extract argument list parsing into finishArgumentList helper
Extract the duplicated argument list parsing logic from methodCall and
subscript into a shared finishArgumentList function. This unifies the
comma-separated expression parsing, arity tracking, and newline handling
into a single location. Also add a new test case verifying that newlines
after commas and before closing delimiters are correctly handled in both
method calls and subscript expressions.
2015-02-22 18:42:49 +00:00
Bob Nystrom 609082b3ba fix: correct wrend binary path in test script from root to bin subdirectory 2015-02-22 18:42:21 +00:00
Bob Nystrom 9016d6e12d docs: document removeAt() return value and update list examples 2015-02-22 18:26:31 +00:00