Commit Graph

1376 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 613b03ac18 mruby-compiler: add no_return_value context flag for script optimization
when running scripts via mruby -e or file, return values are unused.
this adds a no_return_value flag to skip generating unnecessary code.

for parallel assignment like a,b = 1,2:
- before: 18 bytes, 5 registers, creates temporary array
- after: 5 bytes, 3 registers, direct register assignment, no RETURN

the flag is set only for the main program, not for libraries loaded
with -r option. eval() and mirb continue returning values correctly.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-21 17:26:49 +09:00
Yukihiro "Matz" Matsumoto 7e28e68dca string.c: add mrb_utf8_to_buf() to consolidate UTF-8 encoding
Extract duplicated UTF-8 codepoint-to-bytes encoding into a shared
function in src/string.c. Update all gems to use it:

- mruby-sprintf: %c specifier
- mruby-io: putc
- mruby-string-ext: Integer#chr
- mruby-pack: pack("U")
- mruby-compiler: Unicode escapes in parser

Also use existing mrb_utf8len() in io.c for character length detection.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-18 16:30:03 +09:00
Yukihiro "Matz" Matsumoto e8096bf745 mruby-compiler: add brace-less hash pattern support
Add support for brace-less hash patterns at top level of case/in.
`in a: x, b: y` is now equivalent to `in {a: x, b: y}`.
`in a:, b:` shorthand now works with newlines (CRuby compatible).

Changes:
- Add EXPR_VALUE to IS_LABEL_POSSIBLE() to recognize labels after `in`
- Add brace-less hash pattern rules to p_expr
- Change p_hash_elem to use p_as instead of p_expr to avoid recursion
- Add in_kwarg flag to parser state for pattern matching context
- Set in_kwarg in lexer when keyword_in is returned
- Use EXPR_ARG after tLABEL_TAG when in_kwarg is set (makes newlines significant)

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-18 16:27:26 +09:00
Yukihiro "Matz" Matsumoto 729b84cf26 mruby-array-ext: fix use-after-free in array set operations; fix #6662
during eql? callbacks, array modifications can cause elements in khash to
be freed by GC, leading to use-after-free. create temporary shared copies
of arrays before populating khash to protect elements during callbacks.

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-13 11:51:53 +09:00
dearblue 893cc758c3 Added the kh_is_end() macro function
The primary reason is to fix an issue that occurs when an element is removed from the khash data during the `KHASH_FOREACH()` loop.
If the value of `kh_end()` becomes smaller than `k` during the loop, it will repeat a meaningless internal loop until an integer overflow occurs.
2025-11-02 21:18:18 +09:00
Yukihiro "Matz" Matsumoto f4d6e67656 throw.h: exclude arm64 from mingw64 builtin setjmp/longjmp; fix #6637
__builtin_setjmp/longjmp are x86/x86_64 specific gcc intrinsics
and not supported on arm64. windows arm64 with msys2 clangarm64
now correctly falls through to standard setjmp/longjmp.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-13 08:41:34 +09:00
Yukihiro "Matz" Matsumoto e7cbd8cc28 mruby-task: add gc protection and optimize task operations
Implements dual-mechanism GC protection and optimizes task lookup
using pointer arithmetic based on PicoRuby reference implementation.

GC Protection:
- Add mrb_gc_register/unregister to protect Task objects
- Implement mrb_task_mark_all() to mark task contexts during GC
- Store proc reference in mrb_task to prevent premature collection
- Integrate marking into gc.c root_scan_phase

Performance Optimizations:
- Add MRB2TASK macro for O(1) context-to-task conversion
- Optimize Task.current: O(n) queue search -> O(1) pointer arithmetic
- Optimize Task.pass: simplify to root context check
- Optimize Task.join: use MRB2TASK for current task lookup

Bug Fixes:
- Fix MRB_TASK_CREATED/STOPPED to use MRB_FIBER_TERMINATED
- Add safety check to prevent execution of terminated tasks
- Initialize callinfo PC to bytecode start in task_init_context

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:23 +09:00
Yukihiro "Matz" Matsumoto 76745161c5 mruby-compiler: remove var_nodes_enabled and use_variable_nodes flags
Eliminates gradual rollout feature flags that controlled variable-sized AST
nodes. Variable-sized nodes are now the default and only behavior, completing
the AST unification and simplification process.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:20 +09:00
Yukihiro "Matz" Matsumoto d15c0271d6 mruby-compiler: remove unused variable node recycling mechanism
Remove var_free_lists, var_alloc_counts, and var_total_allocated fields
from parser_state struct as they were never used since all nodes go
directly to codegen. Replace parser_alloc_var() wrapper with direct
parser_palloc() calls throughout the codebase, reducing parser memory
footprint by 88 bytes.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:20 +09:00
Yukihiro "Matz" Matsumoto ac02635ba5 mruby-compiler: add infrastructure for variable-sized ast nodes
This commit introduces the core infrastructure for variable-sized AST
nodes, designed to improve memory efficiency. The previous fixed-size
nodes are replaced by nodes that can store data inline, such as
strings and integers, reducing pointer indirection and memory overhead.

Key changes include:
- A generic variable-sized node header (`mrb_ast_var_header`).
- A size-class-based memory allocation system for these nodes.
- Implementation of variable-sized nodes for core types: symbols,
  strings, integers, and variables (lvar, gvar, ivar, cvar).
- Integration into the parser and code generator, controlled by a
  feature flag.
- Centralized and improved type-casting macros for AST nodes.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:03 +09:00
Yukihiro "Matz" Matsumoto 9a7211bb25 numeric.h: fix integer multiplication overflow check
The previous implementation of mrb_int_mul_overflow performed
the multiplication before checking for overflow. This is undefined
behavior for signed integers and can lead to incorrect results on
some compilers (e.g., MSVC).

The implementation has been changed to perform the overflow checks
before the multiplication.

Co-authored-by: Gemini <gemini@google.com>
2025-08-23 09:43:02 +09:00
Yukihiro "Matz" Matsumoto 2cbb99c16d mruby-compiler: make mrb_ast_node an opaque struct in compile.h
Move the definition of struct mrb_ast_node to a private header to
hide implementation details from the public API.

Co-authored-by: Gemini <gemini@google.com>
2025-08-21 07:23:14 +09:00
Yukihiro "Matz" Matsumoto ae7e125388 mruby-compiler: encapsulate string and heredoc types
Move STR_FUNC_* macros, enum mrb_string_type, and struct
mrb_parser_heredoc_info from include/mruby/compile.h to
mrbgems/mruby-compiler/core/node.h.

These types are internal to the mruby compiler gem and are used by
both parse.y and codegen.c. Moving them to node.h encapsulates them
within the compiler gem, cleaning up the public mruby/compile.h header.

Co-authored-by: Gemini <gemini@google.com>
2025-08-21 07:23:13 +09:00
Yukihiro "Matz" Matsumoto ac3c160c3a khash.h: refactor rebuild to handle linear tables
This change allows for handling small tables as linear-search arrays,
improving performance for hashes with few elements.

Co-authored-by: Gemini <gemini@google.com>
2025-08-19 10:06:20 +09:00
Yukihiro "Matz" Matsumoto d42326ce80 khash.h: make khash rebuild GC-safe
The hash rebuild process was not GC-safe. When rebuilding the hash
table, the old data was orphaned before the new table was fully
populated, which could lead to a segmentation fault if a GC cycle
was triggered during the process.

This patch refactors the rebuild function to follow a safer pattern:
- A new temporary hash table is allocated on the stack.
- Elements from the original table are copied to the new one.
- The original table's data is swapped with the new table's data
  only after the new table is complete.

This ensures the original data is always reachable by the GC during
the rebuild.

Co-authored-by: Gemini <gemini@google.com>
2025-08-19 10:06:19 +09:00
Yukihiro "Matz" Matsumoto 74f0fd91e9 khash: rename KHASH_SMALL_THRESHOLD to KHASH_SMALL_LIMIT
Rename KHASH_SMALL_THRESHOLD to KHASH_SMALL_LIMIT for brevity and clarity.
The shorter name is more concise while maintaining clear meaning as the
upper bound for small table optimization.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:07 +09:00
Yukihiro "Matz" Matsumoto 250bf6edd6 khash: rename KHASH_DEFAULT_SIZE to KHASH_INITIAL_SIZE
Rename KHASH_DEFAULT_SIZE to KHASH_INITIAL_SIZE for clearer meaning.
The name "initial" better conveys that this is the starting size for
new hash tables, while "default" could be ambiguous.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:07 +09:00
Yukihiro "Matz" Matsumoto 79fe70ffdc khash: move kh_alloc to internal helper
Move kh_alloc_##name from public API to internal helper kh__alloc_##name
since it's only used internally within khash implementation.

Changes:
- Remove kh_alloc_##name from KHASH_DECLARE
- Add kh__alloc_##name as static inline in KHASH_DEFINE
- Update internal calls to use kh__alloc_##name

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:07 +09:00
Yukihiro "Matz" Matsumoto 0be8fdc030 khash: rename internal helpers to kh__ prefix and organize API boundary
Rename internal helper functions from kh_ to kh__ prefix while correctly
organizing the API boundary:

KHASH_DECLARE (public interface):
- kh_keys_##name, kh_vals_##name, kh_flags_##name (used by kh_exist macro)

KHASH_DEFINE (internal helpers with kh__ prefix):
- kh__kv_size_##name, kh__htable_size_##name
- kh__mark_occupied_##name, kh__mark_deleted_##name
- kh__key_idx_##name, kh__next_probe_##name
- kh__insert_key_##name, kh__clear_flags_##name
- kh__is_small_##name, kh__get_small_##name
- kh__rebuild_##name, kh__put_small_##name

This clearly separates public API functions from internal implementation
helpers while ensuring kh_flags_##name remains accessible to the public
kh_exist macro.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:06 +09:00
Yukihiro "Matz" Matsumoto f4e9bf603c khash: add helpers to eliminate key assignment and memset duplication
Add kh_insert_key and kh_clear_flags helper functions to remove remaining
code duplication patterns in KHASH_DEFINE. These helpers consolidate:

- Key assignment pattern: keys[index] = key; kh_mark_occupied; h->size++
- Flag clearing pattern: memset(kh_flags, 0xaa, n_buckets/4)

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:06 +09:00
Yukihiro "Matz" Matsumoto 73111cacfb khash.h: add linear probing helper to eliminate duplication
Added kh_next_probe_##name() helper function to encapsulate the repeated
linear probing step calculation pattern.

Replaced 2 instances of manual probing calculation:
- k = (k+(++step)) & khash_mask(h) -> k = kh_next_probe_##name(k, &step, h)

This eliminates the duplicated bit manipulation pattern and makes the
probing logic more readable and less error-prone.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:06 +09:00
Yukihiro "Matz" Matsumoto f46b57e22e khash.h: add unified rebuild helper to eliminate major duplication
Added kh_rebuild_##name() helper function that consolidates the complete
"save-allocate-rehash-cleanup" pattern shared between kh_resize and
kh_put_small functions.

The helper intelligently handles both scenarios:
- Small table conversion: iterates by size
- Hash table resize: iterates by buckets with flag checks

This eliminates approximately 25 lines of duplicated code across the
two functions while maintaining identical functionality.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:06 +09:00
Yukihiro "Matz" Matsumoto da09bae640 khash.h: inline kh_alloc_small function used only once
Removed kh_alloc_small_##name() function and inlined its body into the
single call site in kh_init_data_##name(). This eliminates unnecessary
function call overhead and reduces code complexity.

The function was only 2 lines and called once, making it an ideal
candidate for inlining.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:06 +09:00
Yukihiro "Matz" Matsumoto 22a6debf40 khash: improve helper function naming and add htable size helper
Renamed size calculation helpers for clarity:
- kh_data_size_##name() -> kh_kv_size_##name() (keys and values only)
- Added kh_htable_size_##name() (complete hash table including flags)

Updated all usages and simplified patterns:
- kh_kv_size_##name(n) + n/4 -> kh_htable_size_##name(n)

The new names clearly distinguish between:
- kv_size: just the key-value data
- htable_size: complete hash table allocation (data + flags)

This eliminates confusion and makes the code more self-documenting.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:06 +09:00
Yukihiro "Matz" Matsumoto 7cfc863353 khash: add hash calculation helper to eliminate duplication
Added kh_key_idx_##name() helper function to encapsulate the repeated
pattern of calculating bucket index from key hash.

Replaced 2 instances of manual hash calculation:
- __hash_func(mrb,key) & khash_mask(h) → kh_key_idx_##name(mrb, key, h)

This eliminates the duplicated hash-and-mask pattern and makes the code
more readable by clearly expressing the intent (get bucket index for key).

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:05 +09:00
Yukihiro "Matz" Matsumoto 633544e087 khash: add flag operation helpers to eliminate bit manipulation duplication
Added two helper functions to encapsulate repeated flag manipulation patterns:
- kh_mark_occupied_##name(): clears both empty and deleted bits
- kh_mark_deleted_##name(): sets the deleted bit

Replaced 3 instances of manual bit manipulation with calls to these helpers:
- ed_flags[del_k/4] &= ~__m_del[del_k%4] → kh_mark_occupied_##name(h, del_k)
- ed_flags[k/4] &= ~__m_empty[k%4] → kh_mark_occupied_##name(h, k)
- ed_flags[x/4] |= __m_del[x%4] → kh_mark_deleted_##name(h, x)

This eliminates error-prone bit operations, improves readability, and makes
the flag state transitions self-documenting.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:05 +09:00
Yukihiro "Matz" Matsumoto 71c5e2c536 khash: move internal helpers from KHASH_DECLARE to KHASH_DEFINE
Moved kh_data_size_##name() and kh_flags_##name() from KHASH_DECLARE
to KHASH_DEFINE section where internal implementation details belong.

This improves the separation of concerns:
- KHASH_DECLARE: public API only (struct definition, function declarations)
- KHASH_DEFINE: implementation details and internal helper functions

No functional changes, only better code organization.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:05 +09:00
Yukihiro "Matz" Matsumoto 8bcd0d247e khash: add size calculation helper and refactor for better organization
Added kh_data_size_##name() helper function to eliminate duplicated size
calculation patterns throughout the khash implementation. This single
universal helper calculates data size for N elements and replaces all
manual sizeof calculations.

Key changes:
- Add kh_data_size_##name(khint_t count) helper in KHASH_DECLARE
- Replace manual calculations in kh_flags, kh_alloc_small, kh_alloc
- Replace complex size calculations in kh_replace function
- Use specific patterns: small tables use KHASH_SMALL_THRESHOLD,
  hash tables add n_buckets/4 for flag space

This refactoring eliminates 6 instances of duplicated size calculation
code while maintaining identical functionality and performance.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:05 +09:00
Yukihiro "Matz" Matsumoto 7368be7568 khash: add kh_replace optimization for efficient copying
Add kh_replace function that uses direct memory copying instead of
element-by-element rehashing for improved performance.

- Add kh_replace_name function with smart handling of different table types
- Optimize kh_copy to use kh_replace instead of element iteration
- Update Set operations to use kh_replace for copying
- Remove redundant kset_copy_replace function

The optimization provides O(1) memory copy vs O(n) hash operations,
handles small tables and hash tables correctly, and avoids infinite
recursion issues with self-referential data structures.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:05 +09:00
Yukihiro "Matz" Matsumoto 069da276f6 khash: fix small table implementation bugs
- Fix kh_exist macro to handle small tables correctly by checking size
  instead of non-existent flags
- Add proper small table deletion in kh_del function with element shifting
- Fix kh_copy to use corrected kh_exist macro instead of direct flag access
- Remove unused ed_flags variable in kh_copy function

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:04 +09:00
Yukihiro "Matz" Matsumoto 344d28f961 khash.h (kh_destroy): both kh_destroy_data and mrb_free works with NULL 2025-08-14 10:53:04 +09:00
Yukihiro "Matz" Matsumoto 4624fcce56 khash: simplify allocation functions by using mrb_malloc directly
Remove kh_alloc_simple_* functions and explicit mrb_raise_nomemory calls
since mrb_malloc already handles memory allocation failures and raises
nomemory exceptions automatically, unlike mrb_malloc_simple.

This simplifies the code by removing redundant error handling.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:04 +09:00
Yukihiro "Matz" Matsumoto 76188b46ef khash: remove unused mrb parameter from KHASH_FOREACH macro
Remove the unused mrb_state parameter from KHASH_FOREACH macro to clean
up the API. The parameter was never used in the macro implementation and
only cluttered the call sites.

Changes:
- Update KHASH_FOREACH macro signature: (name, mrb, kh, k) -> (name, kh, k)
- Update documentation and usage examples in khash.h
- Update KSET_FOREACH wrapper macro in mruby-set
- Update 2 direct call sites in mruby-metaprog
- All mruby-set call sites automatically updated via wrapper macro

This is a breaking change but follows the recent API cleanup where we
already modified KHASH_FOREACH signature. The macro now has a cleaner
interface without the unused parameter.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:03 +09:00
Yukihiro "Matz" Matsumoto 3cd2201b70 khash: add kh_init_data and kh_destroy_data functions
Add core data initialization functions that handle only the internal data
allocation/deallocation without managing the khash struct itself.

Changes:
- Add kh_init_data_##name() for initializing khash internal data
- Add kh_destroy_data_##name() for cleaning up khash internal data
- Refactor kh_init_##name##_size() to use kh_init_data internally
- Refactor kh_destroy_##name() to use kh_destroy_data internally
- Add corresponding kh_init_data() and kh_destroy_data() macros

Benefits:
- Eliminates code duplication between init/destroy and embed functions
- Provides clear separation: data functions handle internals, regular functions handle struct lifecycle
- Enables embedding khash in other structures (e.g., mruby-set's RSet)
- Centralizes complex initialization logic in single implementation

Architecture:
- kh_init_data/kh_destroy_data: core implementation with small table optimization
- kh_init_size/kh_destroy: convenience wrappers that add struct allocation
- Same functionality preserved, all tests pass

This prepares khash for mruby-set integration while improving code organization
and maintainability.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:03 +09:00
Yukihiro "Matz" Matsumoto 56f798fb44 khash: add small table optimization with linear search
Optimize hash tables with <=4 elements by using linear search instead of
hash table structure, eliminating flag storage and hash computation overhead.

Changes:
- Add KHASH_SMALL_THRESHOLD constant (4 elements)
- Implement linear search for small tables (kh_get_small/kh_put_small)
- Add automatic conversion from small table to hash table when growing
- Start with small table mode in kh_init_size for small requests
- Update kh_end macro to handle small table mode (n_buckets == 0)
- Inline conversion logic directly in kh_put_small for efficiency

Memory impact:
- 40-60% memory reduction for tables with <=4 elements
- Eliminates flag storage and wasted bucket allocation for small tables
- 100% memory utilization vs ~50% in regular hash tables
- Particularly beneficial for mruby's embedded environment

Performance impact:
- Linear search faster than hash computation for <=4 elements
- Better cache locality with sequential memory access
- No hash function calls for small tables
- Automatic conversion ensures scalability for larger tables
- All existing tests pass with identical functionality

Small tables are common in mruby (instance variables, method tables,
small configuration objects), making this optimization valuable for
memory-constrained embedded environments.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:03 +09:00
Yukihiro "Matz" Matsumoto 16015f126e khash: optimize load factor from 75% to 87.5% for memory reduction
Increase hash table load factor to reduce memory usage in embedded
environments. Trade slight performance decrease for memory savings.

Changes:
- Rename UPPER_BOUND to KH_UPPER_BOUND to avoid name conflicts
- Adjust load factor from 75% to 87.5% (from (x)*3/4 to (x)*7/8)
- Add documentation explaining memory vs performance trade-off

Memory impact:
- Delays hash table resizes, allowing more efficient memory utilization
- Particularly beneficial for applications with many hash tables
- Reduces wasted bucket allocation in resize-heavy scenarios
- Aligns with mruby's memory-first design priority

Performance impact:
- Slightly more hash collisions (~43% increase in average probes)
- Minimal real-world impact due to good cache locality in linear probing
- All existing tests pass with identical functionality

The optimization is especially valuable for mruby's embedded target
environment where memory is more constrained than CPU cycles.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:03 +09:00
Yukihiro "Matz" Matsumoto 2371b52ab4 khash: optimize structure size by 50% with single data pointer
BREAKING CHANGE: khash field access macros now require type name parameter

Replace individual pointer fields (keys, vals, ed_flags) with single data
pointer and address calculation functions. This reduces khash structure
size from 32 to 16 bytes (50% reduction) while maintaining performance
through pointer caching in hot paths.

Structure changes:
- Single void *data field replaces keys/vals/ed_flags pointers
- Address calculation functions compute array locations on demand
- Hot path functions cache calculated pointers for performance

API changes (BREAKING):
- kh_key(h, x)      -> kh_key(typename, h, x)
- kh_val(h, x)      -> kh_val(typename, h, x)
- kh_exist(h, x)    -> kh_exist(typename, h, x)
- kh_value(h, x)    -> kh_value(typename, h, x)
- KHASH_FOREACH()   -> KHASH_FOREACH(typename, ...)

Migration required:
- mruby-metaprog: 4 call sites updated (familiar macro names, just add type parameter)
- mruby-array-ext: no changes needed (uses function-style API)
- External users: add type name as first parameter to field access macros

Benefits:
- 50% memory reduction per hash table (32 -> 16 bytes)
- 464 bytes total memory savings in mrbtest execution
- Better cache locality with smaller structures
- Optimized hot path performance with pointer caching
- Consistent with mruby memory-first design priority

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:53:02 +09:00
Yukihiro "Matz" Matsumoto ad3a79f236 khash.h: replace kh_fill_flags with memset
Co-authored-by: Gemini <gemini@google.com>
2025-08-14 10:53:02 +09:00
Yukihiro "Matz" Matsumoto fe4ed7e68d mruby-numeric-ext: implement integer#gcd and Integer#lcm methods
implement Integer#gcd and Integer#lcm methods in mruby-numeric-ext with full
support for both regular integers and bigints.

key changes:
- add mrb_int_gcd euclidean algorithm for regular integer gcd calculation
- implement int_gcd and int_lcm methods with proper type checking and bigint fallback
- add mrb_bint_gcd, mrb_bint_lcm, mrb_bint_abs functions to bigint api
- register gcd and lcm methods with integer class
- add comprehensive test coverage for both regular and bigint cases

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:46 +09:00
Yukihiro "Matz" Matsumoto 7b0ee01310 mruby-random: support bigint in rand method
To achieve this, the following changes were made:

- Exported `mrb_bint_size`, `mrb_bint_from_bytes`, and `mrb_bint_sign`
  functions from `mruby-bigint` to be used in other mrbgems.
- Modified `mruby-random` to use these new functions to handle Bigint
  arguments in the `rand` method.

Co-authored-by: Gemini <gemini@google.com>
2025-08-14 10:52:46 +09:00
dearblue 91f2dca111 Merge mrb_obj_iv_inspect() into mrb_obj_inspect()
`mrb_obj_iv_inspect()` is an internal implementation function and is not called by any function other than `mrb_obj_inspect()`.
2025-07-21 20:54:50 +09:00
Yukihiro "Matz" Matsumoto 2735340702 kernel.c: remove mrb_inspect_recursive_p(); #5531
And use mrb_recursive_method_p() and its helper methods.

Co-authored-by: Claude <noreply@anthropic.com>
2025-07-11 10:09:37 +09:00
Yukihiro "Matz" Matsumoto 670b54f859 variable.h: add prefetch to bsearch_idx
This commit introduces memory prefetching to the `bsearch_idx` functions
in `src/class.c` and `src/variable.c` to improve performance.

A new macro `MRB_MEM_PREFETCH` is defined in `include/mruby/variable.h`
which uses `__builtin_prefetch` if available.

Co-authored-by: Gemini <gemini@google.com>
2025-07-11 10:09:35 +09:00
Yukihiro "Matz" Matsumoto c4464fa25a array.c: expose mrb_ary_dup() as a new C API 2025-06-29 20:46:51 +09:00
John Bampton 383cd6a936 misc: fix spelling word case 2025-06-25 10:46:23 +10:00
Yukihiro "Matz" Matsumoto a6a0346e1c mruby-os-memsize: support Set class 2025-06-24 13:56:07 +09:00
Yukihiro "Matz" Matsumoto 132561418b mruby-set: update Set class to use struct RSet not struct RData 2025-06-24 13:45:14 +09:00
google-labs-jules[bot] dfd7251223 Refactor: Improve Set GC marking and freeing
This commit addresses feedback on the initial Set GC marking implementation.

Changes include:
- Renamed set marking function to `mrb_gc_mark_set` and updated its
  return type to `size_t`.
- Introduced an explicit `mrb_gc_free_set` function for Set objects.
- Updated `gc_mark_children` to use the new mark function signature.
- Added an explicit `case MRB_TT_SET:` in `obj_free` to call `mrb_gc_free_set`.
- Adjusted `set_get_khash` in `mruby-set` to work with `MRB_TT_SET` directly,
  rather than relying on `mrb_data_get_ptr`.
- Corrected type checks in `set_init_copy` to use `MRB_TT_SET`.
- Updated function prototypes in internal headers and stubs in mrbc.
2025-06-24 04:02:41 +00:00
Yukihiro "Matz" Matsumoto 791b374155 khash.h: reduce KHASH_DEFAULT_SIZE from 32 to 8 2025-06-23 17:07:31 +09:00
Yukihiro "Matz" Matsumoto bce8cee8f9 khash.h (KHASH_FOREACH): a new macro to iterate over khash table 2025-06-23 17:07:28 +09:00