Commit Graph

6 Commits

Author SHA1 Message Date
Bob Nystrom
d4df37703d refactor: replace manual error assignment with RETURN_ERROR and RETURN_ERROR_FMT macros across validation and fiber functions
Consolidate repetitive `vm->fiber->error = wrenStringFormat(...)` and `return false` patterns into two new macros defined in wren_primitive.h, reducing code duplication and improving consistency in error reporting for fiber operations, number parsing, and type validation helpers.
2016-03-04 01:11:52 +00:00
Bob Nystrom
ba0d308fba fix: remove fiber support as map keys and revert to value-only key validation
The previous implementation allowed fibers as map keys by assigning each fiber a unique numeric ID for hashing and equality. This was originally added to support a misguided attempt at thread-local storage that was never used. This commit removes the fiber ID field from ObjFiber, the nextFiberId counter from WrenVM, the fiber hashing case in hashObject(), and the IS_FIBER check in validateKey(). The error message for invalid keys is updated from "Key must be a value type or fiber." to "Key must be a value type." and all affected test expectations are updated accordingly.
2015-12-15 18:42:21 +00:00
Bob Nystrom
9d2b4af508 fix: allow empty ranges at the end of a sequence for lists and strings
Previously, empty ranges were only permitted at index zero on an empty sequence.
This change extends the `calculateRange` function to allow empty ranges at the
end of a non-empty sequence, enabling `list[3...3]` and `list[3..-1]` to return
an empty slice. Updated the range validation logic to check `range->from == *length`
instead of requiring a zero-length sequence, and added test cases for both lists
and strings to verify the new behavior.
2015-12-06 18:37:58 +00:00
Bob Nystrom
2dcb3660b5 feat: add Fiber.transferError and allow non-string error objects in fiber abort
Refactor runtime error handling to store errors directly in the fiber's error field instead of on the stack, enabling any object (except null) as an error value. Add Fiber.transferError(_) primitive for transferring errors between fibers. Update validation helpers to accept Value arguments directly and modify RETURN_ERROR macro to set fiber error. Adjust GC marking to use wrenMarkValue for the error field. Add tests for aborting with non-string errors and null abort behavior.
2015-09-30 05:57:03 +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
d92a8f1c93 fix: replace foreign Meta.eval with primitive and suppress compile errors in wrenCompile 2015-04-04 04:22:58 +00:00