Commit Graph
59 Commits
Author SHA1 Message Date
Marco Lizza e70d6411fb fix: correct fraction and truncate test expectations for negative zero and large values
- Update fraction.wren test to cover edge cases for negative zero, small fractions, and large mantissa approximations
- Fix truncate.wren expected output for negative zero cases from 0 to -0
- Add truncate tests for large 32-bit representation values with approximation notes
2015-03-05 10:24:54 +00:00
Marco Lizza ea20c2d086 fix: remove redundant integer division primitive from wren core
The `num_div` primitive performed integer division on two int32 values, but this
functionality is already covered by the existing `num_divide` primitive which
handles floating-point division. Removing this duplicate method eliminates
confusion and reduces code maintenance burden.
2015-03-05 08:48:52 +00:00
Marco Lizza 86ab538c21 style: reformat num_sign primitive to use early returns and consistent brace style 2015-03-04 23:47:54 +00:00
Marco Lizza a4ebc39877 fix: replace int32_t cast with modf for correct truncate behavior
The previous implementation cast the number to int32_t, which incorrectly
truncated values outside the int32_t range and produced wrong results for
large doubles. The new implementation uses the standard C `modf` function
to correctly truncate the fractional part while preserving the full
double precision of the integer portion.
2015-03-04 23:46:45 +00:00
Marco Lizza adca2b3aac feat: rename 'decimal' primitive to 'fraction' and reimplement using modf
Replace the num_decimal primitive with num_fraction, changing the implementation from a simple subtraction of integer part to using the standard C modf function for more robust fractional part extraction. Update the method registration in wrenInitializeCore to bind the new name and function.
2015-03-04 23:45:30 +00:00
Marco Lizza 11911826ff test: add test files for decimal, div, sign, and truncate methods on Number
Add four new test files covering edge cases for Number methods:
- decimal.wren tests fractional part extraction including negative zero
- div.wren tests integer division behavior with mixed integer/float operands
- sign.wren tests sign determination including zero and negative zero
- truncate.wren tests truncation of positive and negative numbers
2015-03-04 15:12:08 +00:00
Marco Lizza 5ffb2815ae feat: add integer division primitive 'div' to num class in wren_core.c
Implement DEF_PRIMITIVE(num_div) that casts both operands to int32_t
and performs integer division, returning the truncated quotient.
Register the new primitive as "div(_)" on the num class in
wrenInitializeCore, placed alphabetically between "deg" and "floor".
2015-03-04 15:10:37 +00:00
Marco Lizza 610f98957f style: rename local variable num to value in num_decimal and num_sign primitives for consistency 2015-03-04 13:46:24 +00:00
Marco Lizza 2e36078d6e fix: extend num_sign primitive to return 0 for zero-valued numbers 2015-03-04 13:45:51 +00:00
Marco Lizza 1a60874e9c feat: add 'sign' primitive method to Number class returning 1 for non-negative and -1 for negative
Implement the num_sign primitive that checks if the numeric argument is >= 0.0
and returns 1.0 for non-negative values or -1.0 for negative values. Register
the new primitive on the Number class in wrenInitializeCore.
2015-03-04 13:42:50 +00:00
Marco Lizza 74943b558c fix: swap implementations of num_decimal and num_truncate primitives
The num_decimal primitive was incorrectly returning the integer part of a number
instead of the fractional part, while num_truncate was returning the fractional
part instead of truncating to the integer portion. This commit corrects both
functions by exchanging their logic bodies.
2015-03-04 13:42:34 +00:00
Marco Lizza 0a448e08d1 feat: add decimal and truncate number methods to wren core
Implement two new primitive methods for the Number class: `decimal` returns the integer part by casting to uint32_t, and `truncate` returns the fractional part by subtracting the integer portion from the original value. Register both primitives in the core initialization.
2015-03-03 23:29:19 +00:00
Marco Lizza 3c2c84e390 feat: add deg and rad number conversion primitives to Num class
Implement two new primitive methods on the Num class: `deg` converts radians to degrees by multiplying by 180/Ď€ (57.29578) and flooring, while `rad` converts degrees to radians by dividing by the same factor and flooring. Both are registered in `wrenInitializeCore` alongside existing trigonometric primitives.
2015-03-03 23:28:44 +00:00
Marco Lizza e09d8c9b9e fix: raise '&&' precedence above '||' in wren compiler's operator precedence table
Split the former PREC_LOGIC into PREC_LOGICAL_OR and PREC_LOGICAL_AND, inserting PREC_TERNARY between them, and updated all parsePrecedence calls and grammar rule entries to use the new precedence levels.
2015-02-25 15:04:02 +00:00
Marco Lizza 5ff3e291da fix: adjust bitwise operator precedence between comparison and range in compiler enum 2015-02-25 15:02:29 +00:00
Marco Lizza c6c934f552 chore: move bitwise_precedence.wren to test/ root and add precedence comments
The test file was relocated from test/number/ to test/ to match the project's test organization conventions. Added clarifying comments documenting the relative precedence of bitwise operators (<< > & > ^ > |) directly in the test assertions.
2015-02-25 15:00:53 +00:00
Marco Lizza 1e0f4aefbd feat: add bitwise operator precedence test file with shift and logical combinations
Add test/number/bitwise_precedence.wren covering operator precedence between <<, |, &, and ^ with 12 assertions verifying correct evaluation order for mixed expressions like 2 | 1 << 1 and 1 & 1 | 2.
2015-02-23 16:29:31 +00:00
Marco Lizza 4f45d18150 fix: split monolithic PREC_BITWISE into separate precedence levels for | ^ & << >> operators 2015-02-23 16:28:43 +00:00
Marco Lizza 4b37134bfa feat: set REPL module root to current working directory via getcwd
Replace the TODO placeholder for rootDirectory initialization in the REPL
with a call to getcwd (with _getcwd fallback for MSVC), enabling module
imports to resolve relative to the user's working directory at startup.
2015-02-23 12:57:56 +00:00
Marco Lizza 3b28ac8435 fix: replace malloc with stack buffer for rootDirectory to fix memory leak and GCC warnings 2015-02-23 12:57:20 +00:00
Marco Lizza 2fa5964321 fix: use BENCHMARK_DIR constant for baseline file path in read and write operations 2015-02-23 09:01:57 +00:00
Marco Lizza cc38b6f35a refactor: rename num_bitwiseLsh and num_bitwiseRsh to num_bitwiseLeftShift and num_bitwiseRightShift for clarity
Renamed the native function identifiers for left and right bitwise shift operations
in wren_core.c to use the more explicit names num_bitwiseLeftShift and
num_bitwiseRightShift, replacing the abbreviated Lsh and Rsh suffixes. Updated
both the DEF_NATIVE macro definitions and the corresponding NATIVE registrations
in wrenInitializeCore to use the new names.
2015-02-16 21:29:30 +00:00
Marco Lizza 668df8d1af fix: rename TOKEN_LEFT_SHIFT and TOKEN_RIGHT_SHIFT to TOKEN_LTLT and TOKEN_GTGT
Rename the token enum values and all references in the compiler to use the more concise
TOKEN_LTLT and TOKEN_GTGT names for the '<<' and '>>' operators, updating both the
token type definitions and the grammar rule table entries.
2015-02-16 21:26:54 +00:00
Marco Lizza cbaeef8469 feat: add static IO.time method returning current Unix timestamp via time(NULL) 2015-02-16 11:04:56 +00:00
Marco Lizza ef891e8da9 feat: add bitwise left shift, right shift, and xor operand tests
Add comprehensive test files for bitwise lsh, rsh, and xor operations
covering basic cases, max u32 boundary, past max u32 wrap, and operand
type error checks for non-numeric right operands.
2015-02-16 10:30:15 +00:00
Marco Lizza 8c8a059dda feat: add bitwise XOR, left-shift, and right-shift primitives for numbers
Implement three new native methods on the Num class: `^` (bitwise XOR), `<<` (left shift), and `>>` (right shift). Each operates on 32-bit unsigned integers, matching the existing bitwise AND/OR convention. The new primitives are registered in `wrenInitializeCore` alongside the existing bitwise operators.
2015-02-16 10:29:14 +00:00
Marco Lizza a9b9c483cc feat: add bitwise shift and XOR operators to compiler tokenizer and parser
Add TOKEN_LEFT_SHIFT, TOKEN_RIGHT_SHIFT, and TOKEN_CARET to the token enum, implement lexing for '^' as single-char token and '<<'/'>>' as two-char tokens in nextToken(), and register them as infix operators at PREC_BITWISE precedence in the grammar rules table.
2015-02-16 10:28:34 +00:00
Marco Lizza 16c13765de feat: add map benchmark scripts for lua, python, ruby, and wren
Add four new benchmark scripts (maps.lua, maps.py, maps.rb, maps.wren) that measure
hash map insertion, lookup, and deletion performance across 100,000 elements.
Register the new "maps" benchmark in run_bench.py with expected output 5000050000.
2015-02-09 10:51:09 +00:00
Marco Lizza f5def0e3ca chore: move run_bench script to script folder and update path references
- Relocate benchmark/run_bench to script/run_bench.py
- Replace WREN_DIR with HOME_DIR and update BENCHMARK_DIR construction
- Change wren binary path from relative "../wren" to absolute using HOME_DIR
2015-02-09 10:49:06 +00:00
Marco Lizza 4f16886150 fix: add unsigned suffix to FNV-1a hash constant to suppress GCC C++ compilation warning
The FNV-1a hash initializer constant 2166136261 exceeds the maximum value
for a signed 32-bit integer, causing GCC to emit a constant unsigned error
when compiling as C++. Adding the 'u' suffix explicitly marks the literal
as unsigned, resolving the compilation issue without changing behavior.
2015-02-04 12:59:53 +00:00
Marco Lizza 269ed9a152 feat: add 8-bit string test cases across concatenation, contains, count, ends_with, equality, index_of, iterate, iterator_value, join, starts_with, subscript, and to_string
Add comprehensive test coverage for strings containing null bytes (\0) to ensure
all string operations correctly handle 8-bit clean data. Tests verify that
concatenation, substring search, length counting, boundary checks, equality
comparisons, index lookups, iteration, joining, and conversion to string all
treat embedded null bytes as regular characters rather than terminators.
2015-02-04 12:58:16 +00:00
Marco Lizza a7ad4ead70 fix: handle empty search string in string_contains by checking search length only
Previously, the corner case for empty strings only returned true when both the source and search strings were empty. This fix changes the condition to return true whenever the search string is empty, as the empty string is always contained within any string.
2015-02-04 12:53:59 +00:00
Marco Lizza 23dcd3feb3 refactor: replace strcpy/strncpy with memcpy for safer string handling across compiler, core, utils, value, and vm modules 2015-02-04 12:51:54 +00:00
Marco Lizza 7127012cf7 fix: cast index to uint32_t in string_iterate to suppress signed comparison warning 2015-02-04 12:47:09 +00:00
Marco Lizza 81a1a5a72f fix: add explicit length parameters to wrenStringConcat for null-containing string support
The function signature was changed from accepting null-terminated C strings to accepting explicit length parameters, with -1 indicating automatic strlen calculation. All call sites were updated to pass -1 for both lengths, and internal implementation switched from strcpy to memcpy to handle embedded null bytes correctly.
2015-02-04 12:44:39 +00:00
Marco Lizza b43788a221 feat: replace strstr with wrenStringFind using Boyer-Moore-Horspool for 8-bit string support
Implement wrenStringFind function in wren_value.c that uses the Boyer-Moore-Horspool algorithm with a 256-entry shift table for full 8-bit character support. Update string_contains and string_indexOf native methods in wren_core.c to call the new function instead of strstr, fixing substring searches on strings containing null bytes or extended ASCII characters.
2015-02-04 12:38:15 +00:00
Marco Lizza f5942f0123 fix: change ObjString length field type from int to uint32_t
The length field in ObjString struct is updated to use uint32_t instead of int,
ensuring consistent unsigned semantics for string size representation across
the codebase and preventing potential issues with negative length values.
2015-02-04 12:29:15 +00:00
Marco Lizza ed38494eba feat: add '\0' escape sequence support in string literal parsing
Add handling for the null character escape sequence '\0' in the
readString function within the Wren compiler. This allows string
literals to include null bytes via the standard C escape syntax,
matching the existing support for other escape sequences like '\a',
'\b', and '\f'.
2015-02-04 12:25:25 +00:00
Marco Lizza 9329503ea7 perf: replace strncmp with memcmp in wrenSymbolTableFind for length-known string comparison 2015-01-30 08:24:10 +00:00
Marco Lizza 2108cb39be fix: align pointer asterisk to type in String struct declaration 2015-01-30 08:23:30 +00:00
Marco Lizza 3b1ab09a7e fix: access .buffer field on global and method name string arrays in debug print
The debug instruction printer was dereferencing string arrays directly instead of accessing their .buffer member, causing incorrect symbol name display for LOAD_GLOBAL, STORE_GLOBAL, CALL, SUPER, METHOD_INSTANCE, and METHOD_STATIC instructions. Updated all six printf calls to use vm->globalNames.data[global].buffer and vm->methodNames.data[symbol].buffer respectively.
2015-01-29 16:08:05 +00:00
Marco Lizza c3a5260cfe feat: store string length alongside buffer in SymbolTable entries
Replace the `char*` buffer element type with a `String` struct that holds both the buffer pointer and its length. This eliminates O(n) `strlen()` calls in `wrenSymbolTableFind` and ensures length is always available without scanning for the null terminator. Update `wrenSymbolTableAdd` to populate the new `length` field, `wrenSymbolTableClear` to free via `symbol.buffer`, and all call sites (e.g., `methodNotFound` in `wren_vm.c`) to access `.buffer` explicitly.
2015-01-29 15:54:21 +00:00
Marco Lizza ef9d17f641 refactor: replace bitwise ObjFlags with boolean marked field for GC tracking
Replace the single-bit FLAG_MARKED enum and ObjFlags bitfield with a direct bool 'marked' field on the Obj struct. This simplifies the garbage collector's mark-sweep logic by removing unnecessary bitwise operations (|, &, ~) and the associated enum definition, making the intent clearer and reducing cognitive overhead when reading GC-related code paths.
2015-01-27 13:13:26 +00:00
Marco Lizza 1acddac5e8 refactor: replace bitfield members with full-width ObjType and ObjFlags in Obj struct 2015-01-27 13:09:32 +00:00
Marco Lizza ddc6cd79f8 feat: remove Math library source, header, tests, and build references from MSVC projects
Remove the entire wren_math.c and wren_math.h implementation files, delete all math test scripts under test/math/, and strip the WREN_USE_LIB_MATH compile flag from wren_common.h. Also remove the wrenLoadMathLibrary call from wren_vm.c and delete the wren_math.c/h entries from both the MSVC project file and its filters file.
2015-01-23 09:08:34 +00:00
Marco Lizza 915f403bc7 chore: restore standard header include order and move CRT secure warning to MSVC project
The diff reorders includes across multiple source files to place standard library headers before project headers, removes the `_CRT_SECURE_NO_WARNINGS` define from `wren_common.h`, and adds it as a preprocessor definition in both Debug and Release configurations of the MSVC 2013 project file.
2015-01-23 09:05:10 +00:00
Marco Lizza 88d7c318ef feat: add Math library source and integrate into MSVC project and VM initialization
Add wren_math.c and wren_math.h to the MSVC 2013 project files, including both the .vcxproj and .vcxproj.filters. Also fix the indentation of the WREN_COMPUTED_GOTO comment in wren_common.h and correct a conditional guard bug in wren_vm.c where wrenLoadMathLibrary was guarded by WREN_USE_LIB_IO instead of WREN_USE_LIB_MATH.
2015-01-22 16:46:09 +00:00
Marco Lizza a34eb52d6c feat: add Math library with abs, ceil, floor, int, frac, trig, and xorshift RNG
Implement the Math standard library module for Wren, including absolute value, ceiling, floor, integer/fractional decomposition, trigonometric functions (sin, cos, tan), degree/radian conversion, and a seeded xorshift random number generator. Add WREN_USE_LIB_MATH compile-time flag to wren_common.h and provide comprehensive test suite under test/math/.
2015-01-22 15:42:40 +00:00
Marco Lizza 9a50b5f318 feat: add Math library with abs, ceil, floor, trig, and xorshift RNG
Implement a new optional Math module for the Wren standard library, gated behind the WREN_USE_LIB_MATH flag (default on). The module provides double-precision math functions (abs, ceil, floor, int, frac, sin, cos, tan, deg, rad) and a xorshift-based pseudo-random number generator with srand/rand methods. Includes comprehensive test files for each function and an all_tests runner.
2015-01-22 15:41:19 +00:00
Marco Lizza c2f1a962d6 fix: replace WREN_PIN/WREN_UNPIN macros with wrenPushRoot/wrenPopRoot and fix modulo operator precedence 2015-01-22 09:13:16 +00:00
Marco Lizza 14a2c8b19c chore: add Marco Lizza to AUTHORS file for project contributions 2015-01-21 10:06:22 +00:00
Marco Lizza 3cdc3dde84 fix: work around MSVC 2013 optimizer bug causing memory access violation in wrenPinObj and wrenUnpinObj
Disable optimization for wrenPinObj and wrenUnpinObj functions under Microsoft Visual Studio 2013 to prevent the compiler from incorrectly inlining them, which triggers a memory access violation. The pragma directives bracket only these two functions to minimize the impact on the rest of the compilation unit.
2015-01-21 10:01:09 +00:00
Marco Lizza cb62bcda8e feat: add Visual Studio 2013 solution and project files for building wren on Windows
Add MSVC 2013 project scaffolding under project/msvc2013/ including wren.sln solution file, wren.vcxproj with Debug/Release Win32 configurations using v120 toolset, and wren.vcxproj.filters organizing source and header files from ../src/ into Visual Studio filter categories.
2015-01-21 10:00:35 +00:00
Marco Lizza ff9625a80d chore: reorder include directives to place wren_common.h first across all source files
Enforce a consistent include ordering convention across the codebase: wren_common.h (as configuration header) first, followed by the module's own header, then other wren_*.h headers in lexicographic order, and finally standard library includes. Also add missing wren_common.h include to main.c and wren_io.c, and add _CRT_SECURE_NO_WARNINGS define for MSVC in wren_common.h.
2015-01-21 09:30:37 +00:00
Marco Lizza 80620957b3 fix: disable computed goto for MSVC due to lack of compiler support
The WREN_COMPUTED_GOTO macro is now conditionally set to 0 when
compiling with _MSC_VER, as Microsoft's compiler does not support
the computed-goto extension used by the VM dispatch loop.
2015-01-21 09:27:27 +00:00
Marco Lizza a70a23e03d fix: avoid returning void function result in for/while/class/var statements 2015-01-21 09:23:46 +00:00
Marco Lizza 19862a2959 fix: change readHexDigit return type from char to int to prevent sign extension bugs 2015-01-21 09:22:56 +00:00
Marco Lizza 25b6a37b2c fix: add _inline fallback for MSVC plain-C compilation in wren_common.h 2015-01-21 09:22:18 +00:00
Marco Lizza 9b350e3e7d fix: replace zero-length flexible array members with zero-sized arrays to suppress non-standard warnings
In `src/wren_value.h`, change three flexible array members (`char value[]`, `Upvalue* upvalues[]`, `Value fields[]`) to explicit zero-sized arrays (`char value[0]`, `Upvalue* upvalues[0]`, `Value fields[0]`) to resolve compiler warnings about non-standard zero-sized array usage in structs `ObjString`, `ObjClosure`, and `ObjInstance`.
2015-01-21 09:21:04 +00:00