Commit Graph
9 Commits
Author SHA1 Message Date
Evan Shaw ffcdd8ae9e fix: correct operator precedence for % token from PREC_TERM to PREC_FACTOR
The modulo operator was incorrectly assigned PREC_TERM precedence, making it
evaluate at the same level as + and -. This caused expressions like "13 + 1 % 7"
to parse as "(13 + 1) % 7" instead of the correct "13 + (1 % 7)".

Changed the grammar rule for TOKEN_PERCENT to use PREC_FACTOR, matching the
precedence of * and / operators. Added a precedence test case in mod.wren to
verify the fix.
2015-01-21 20:49:43 +00:00
Evan Shaw 0526cee655 fix: stop lexing negative numbers as single tokens to fix parsing of subtraction
Previously, the lexer greedily consumed a `-` followed by a digit as a single negative number token, causing "1 -1" to be lexed as two number tokens instead of a minus operator and a positive literal. This broke parsing of subtraction expressions without spaces.

Now `-` always emits a TOKEN_MINUS, and the parser handles unary negation. This is a breaking change: `-16.sqrt` is now parsed as `-(16.sqrt)` instead of `(-16).sqrt`, requiring parentheses for negative method receivers. All number method tests (abs, ceil, floor, sqrt, toString) are updated to use explicit parentheses for negative receivers.
2015-01-09 07:06:50 +00:00
Evan Shaw 38d93e9850 style: align continuation indentation and rephrase comment in ObjString length field 2015-01-08 06:34:58 +00:00
Evan Shaw 1293a64451 refactor: use sprintf return value to eliminate redundant strlen calls in num_toString and range_toString
Replace separate strlen(buffer) calls with the length returned directly by sprintf in both
num_toString and range_toString native functions. This avoids an unnecessary pass over the
formatted string buffer, improving performance for these hot-path number and range conversions.
2015-01-08 00:41:22 +00:00
Evan Shaw 7a80f801a8 feat: replace strlen calls with stored ObjString length for string operations
Refactor string_contains, string_count, string_eqeq, string_bangeq, and string_subscript to use the precomputed ObjString->length field instead of calling strlen() on the C string. This avoids O(n) length calculations on every string comparison and count operation.

Also update markString memory accounting to use the stored length plus null terminator instead of recalculating with strlen().
2015-01-07 21:05:33 +00:00
Evan Shaw 34670fa586 feat: store explicit string length in ObjString struct for wren values
Add a `length` field to the `ObjString` struct in `wren_value.h` and initialize it in `wrenNewUninitializedString()` in `wren_value.c`. This stores the string's byte count excluding the null terminator, enabling O(1) length retrieval while preserving null-terminated C string compatibility.
2015-01-07 20:53:32 +00:00
Evan Shaw 3e8d740c12 chore: add Evan Shaw to AUTHORS file with email address 2015-01-07 20:51:13 +00:00
Evan Shaw ac44be651c style: remove trailing semicolons from assignment statements in delta_blue.wren benchmark 2015-01-06 19:06:44 +00:00
Evan Shaw 0dcd7bbffc refactor: embed string data as flexible array member in ObjString struct
Remove separate heap allocation for string text by storing it directly in the ObjString struct using a C99 flexible array member. This eliminates the need for an extra pointer indirection and a separate memory allocation call in wrenNewUninitializedString, while also simplifying the cleanup logic in wrenFreeObj by removing the explicit deallocation of the string's value buffer.
2015-01-05 02:03:50 +00:00