Commit Graph
40 Commits
Author SHA1 Message Date
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 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