Commit Graph

54 Commits

Author SHA1 Message Date
Thorbjørn Lindeijer
9dc939380c feat: add Sequence.count(predicate) method and update documentation
Implement a new `count(f)` method on the Sequence class that accepts a predicate function and returns the number of elements for which the predicate evaluates to true. The implementation iterates over the sequence, calling `f.call(element)` on each element and incrementing a counter when the result is truthy.

Also update the documentation for both Sequence and List classes: add full documentation for the new `count(predicate)` method on Sequence, and change the terminology in List docs from "items" to "elements" for consistency. Add three test files covering the basic predicate behavior, non-boolean return values from the predicate, and the error case when a non-function argument is passed.
2015-03-14 13:17:21 +00:00
Peter Reijnders
875c74b211 fix: align ObjList capacity and count types with ObjMap's uint32_t
Change the `capacity` and `count` fields in `ObjList` from `int` to `uint32_t` to match the
types used in `ObjMap`, ensuring consistency between the two structures. Update all loop
variables and index calculations in `wren_core.c` and `wren_value.c` that interact with
these fields to use `uint32_t` instead of `int`, and remove the now-unnecessary negative
bounds check in `list_iterate` since unsigned types cannot be negative.
2015-03-08 11:33:29 +00:00
Peter Reijnders
0ddef2c17f chore: enable -Wextra compiler flag and suppress unused-parameter warnings
Enable the -Wextra compiler flag in the wren.mk build configuration, which was previously commented out with a TODO. To handle the new unused parameter warnings triggered by -Wextra (particularly for WrenVM* vm parameters in several functions), add -Wno-unused-parameter to suppress them. Also fix a declaration ordering issue in wren_vm.c where the 'static' keyword was placed after the return type in loadIntoCore, moving it to the correct position before the type specifier.
2015-02-28 12:52:48 +00:00
Peter Reijnders
21e387efec fix: add null and already-freed guard to wrenFreeVM to prevent double-free crash
The guard checks if the VM pointer is NULL or if its methodNames count is zero,
which serves as a heuristic to detect an already-freed VM instance. This prevents
a segmentation fault or memory corruption when wrenFreeVM is called multiple times
on the same VM object.
2015-02-28 12:29:17 +00:00