Commit Graph

17187 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto dc0a5f433f mruby-compiler: optimize NODE_STMTS nesting to reduce AST depth
Modify new_stmts to flatten unnecessary nesting by returning existing
NODE_STMTS directly instead of wrapping them. This reduces memory usage
and AST complexity when multiple parentheses levels are used.

Before: (((expr1; expr2))) creates nested NODE_STMTS
After: (((expr1; expr2))) creates single NODE_STMTS with statements

Co-authored-by: Claude <noreply@anthropic.com>
2025-07-11 10:09:33 +09:00
Yukihiro "Matz" Matsumoto f6c166cbb0 mruby-compiler: rename NODE_BEGIN to NODE_STMTS for clarity
Rename NODE_BEGIN to NODE_STMTS to better reflect its purpose as a
container for statement sequences, not specifically begin-end blocks.
This prepares for adding a dedicated node type for explicit begin-end
constructs.

- Rename NODE_BEGIN enum to NODE_STMTS in node.h
- Update all references in parse.y and codegen.c
- Rename new_begin function to new_stmts

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-11 10:09:33 +09:00
Yukihiro "Matz" Matsumoto 540bbc71e6 mruby-numeric-ext: add documentation for public methods
This commit adds `call-seq` documentation to the following methods
in `mruby-numeric-ext` to improve code clarity and maintainability:

- `Integer#even?`
- `Integer#odd?`
- `Integer.sqrt`
- `Float#remainder`

Additionally, it adds a comment to the internal `isqrt` function
to explain its implementation.

Co-authored-by: Gemini <gemini@google.com>
2025-07-11 09:20:01 +09:00
Yukihiro "Matz" Matsumoto 3e5129558b mruby-sprintf: remove misleading comment and dead code
The `XXX` comment in `sprintf.c` suggested that not validating
the number of arguments for positional format specifiers was a bug.
However, CRuby's `sprintf` also ignores extra arguments in this
case, making the existing behavior correct.

This commit removes the confusing comment and the disabled code
block that went with it, clarifying the intended behavior and
cleaning up the code.

Co-authored-by: Gemini <gemini@google.com>
2025-07-11 09:20:00 +09:00
Yukihiro "Matz" Matsumoto 4bb252e2ff mruby-hash-ext: add documentation for internal functions
The `mruby-hash-ext` gem already had `call-seq` comments for its
public methods, but the internal helper functions `slice_bang_i` and
`hash_key_i` were undocumented.

This commit adds detailed comments to these functions, explaining their
purpose, parameters, and return values. This improves the
maintainability and readability of the code.

Co-authored-by: Gemini <gemini@google.com>
2025-07-11 09:20:00 +09:00
Yukihiro "Matz" Matsumoto c50e6c7563 Merge pull request #6573 from jbampton/pre-commit-fixes-and-updates 2025-07-10 15:02:10 +09:00
John Bampton 943f1bff5c pre-commit updates; make oxipng hook more robust 2025-07-09 21:13:11 +10:00
John Bampton b229bb65c4 Run pre-commit and fix lint errors 2025-07-09 21:12:08 +10:00
Yukihiro "Matz" Matsumoto d25ae92c06 mruby-socket: fix file descriptor leaks in accept2 and socketpair
Fixed critical resource leaks by pre-allocating mruby objects before system
calls. Since mrb_str_resize to smaller size and mrb_ary_push within
pre-allocated size cannot fail, moving allocations before socket creation
eliminates all leak potential with minimal code changes.

Co-authored-by: Atlassian Rovo Dev
2025-07-09 14:18:47 +09:00
Yukihiro "Matz" Matsumoto ea7ac6daf1 mruby-range-ext: add comprehensive documentation for all public methods
Added call-seq documentation for 7 public methods (2 in C, 5 in Ruby)
improving documentation coverage from ~1% to complete. Includes method
signatures, clear descriptions, and practical examples for cover?, size,
max, min, overlap?, first, and last. Added simple description for internal
__empty_range? helper method.

Co-authored-by: Atlassian Rovo Dev
2025-07-09 14:00:50 +09:00
Yukihiro "Matz" Matsumoto eca051e022 mruby-method: add comprehensive documentation for all public methods
Added call-seq documentation for 16 key functions addressing critical 0%
documentation coverage. Includes method signatures, clear descriptions,
practical examples, and expected output for Method, UnboundMethod, Kernel,
and Module method introspection functionality.

Co-authored-by: Atlassian Rovo Dev
2025-07-09 13:49:59 +09:00
Yukihiro "Matz" Matsumoto 0c6a1d0cee Merge pull request #6572 from mruby/add-claude-github-actions-1751960780557 2025-07-08 17:29:49 +09:00
Yukihiro "Matz" Matsumoto 1b35ea5f93 Claude Code Review workflow 2025-07-08 16:46:23 +09:00
Yukihiro "Matz" Matsumoto 2258cdc3fc Claude PR Assistant workflow 2025-07-08 16:46:21 +09:00
Yukihiro "Matz" Matsumoto d76d10ff80 Merge pull request #6571 from aisk/small-hash-limitation 2025-07-07 10:23:25 +09:00
AN Long 720411899a Update limitations.md to add behavior on small hash 2025-07-07 01:15:00 +09:00
Yukihiro "Matz" Matsumoto 0da6df6063 class.c: prevent crash in instance_eval; fix #6570
Fixes a null pointer dereference in `find_visibility_scope` when defining a
singleton method inside `instance_eval`.

This was caused by `ci->u.env` being `NULL` in this context. The fix adds a
`NULL` check to prevent the crash.

Co-authored-by: Gemini <gemini@google.com>
2025-07-05 18:32:47 +09:00
Yukihiro "Matz" Matsumoto e4b83f688e variable.c: use branch-free binary search for ivars
This commit optimizes instance variable lookups by replacing the
search algorithm with the same branch-free binary search recently
introduced for method lookups. This improves performance by
avoiding CPU branch mispredictions.
2025-07-05 18:32:47 +09:00
Yukihiro "Matz" Matsumoto 1167636998 class.c: optimize method lookup with branch-free binary search
This commit replaces the method table search algorithm with a
branch-free binary search. This avoids conditional branches,
which can prevent CPU pipeline stalls from branch misprediction,
leading to faster method lookups.

The new `bsearch_idx` function is used for finding, inserting,
and deleting methods in the method table.
2025-07-05 18:32:46 +09:00
Yukihiro "Matz" Matsumoto 6dc73d2517 mruby-array-ext: unify array#- tests
Merged the separate "Array#-" and "Array#- with large arrays" test
blocks into a single comprehensive test. The unified test covers both
basic functionality (type checking, simple subtraction) and the
hash-based implementation for large arrays (>32 elements).

Co-authored-by: Atlassian Rovo Dev
2025-07-05 18:32:46 +09:00
Yukihiro "Matz" Matsumoto 2c1a7ad933 mruby-class-ext: add comprehensive documentation to all functions
Add detailed comments to all functions in class.c including:

- Function purpose and behavior descriptions
- Parameter documentation with types and meanings
- Return value explanations with all possible outcomes
- Error conditions and exception documentation
- Helper function and structure documentation

This improves code maintainability and follows Ruby documentation
conventions with proper call-seq formatting.

Co-authored-by: Atlassian Rovo Dev
2025-07-05 18:32:46 +09:00
Yukihiro "Matz" Matsumoto 815b34c509 mruby-class-ext: migrate comparison methods to c
The following Module methods were migrated from Ruby to C:

   - `<`
   - `<=`
   - `>`
   - `>=`
   - `<=>`

Co-authored-by: Gemini <gemini@google.com>
2025-07-05 18:32:46 +09:00
Yukihiro "Matz" Matsumoto 9ca5ff2f74 Merge pull request #6567 from dearblue/bintest2 2025-07-05 18:16:58 +09:00
Yukihiro "Matz" Matsumoto cd5b9fff58 Merge pull request #6568 from dearblue/debugger1 2025-07-05 16:49:26 +09:00
Yukihiro "Matz" Matsumoto bbb7f47413 Merge pull request #6566 from dearblue/bintest1 2025-07-05 16:23:22 +09:00
Yukihiro "Matz" Matsumoto 2e3e6baa2d Merge pull request #6569 from dearblue/debugger2
sed s/Mruby/MRuby/g
2025-07-04 08:35:31 +09:00
Yukihiro "Matz" Matsumoto c5c29aa82b AUTHORS: update entries [ci skip] 2025-07-03 06:52:32 +09:00
Yukihiro "Matz" Matsumoto bfc6daa845 mruby-compiler: add README.md │
Co-authored-by: Gemini <gemini@google.com>
2025-07-02 07:14:04 +09:00
Yukihiro "Matz" Matsumoto 8c4db2f417 mruby-hash-ext: add Hash#slice!
This commit introduces `Hash#slice!`, which removes key-value pairs from a
hash, keeping only the ones specified in the arguments. The removed pairs
are returned as a new hash.

Co-authored-by: Gemini <gemini@google.com>
2025-07-01 23:23:07 +09:00
Yukihiro "Matz" Matsumoto 33d6ec08f3 mruby-hash-ext: enhance __merge for multiple arguments
Replace single-argument __merge with multi-argument C implementation.
Eliminates Ruby loop overhead for merging multiple hashes.
Optimizes merge! method while maintaining block functionality.

Co-authored-by: Atlassian Rovo Dev
2025-07-01 22:34:31 +09:00
Yukihiro "Matz" Matsumoto 69d278589d mruby-array-ext: add Array#deconstruct for pattern matching
Implement new method for Ruby 2.7+ pattern matching compatibility.
Returns the array itself to enable case/in pattern matching syntax.
Complements Hash#deconstruct_keys for complete pattern matching support.

Co-authored-by: Atlassian Rovo Dev
2025-07-01 22:34:01 +09:00
dearblue 2f61e0b958 sed s/Mruby/MRuby/g
For name consistency.
2025-07-01 20:57:52 +09:00
dearblue 9053c79c3c mruby-bin-debugger depends on mruby-bin-mrbc in bintest 2025-07-01 20:51:11 +09:00
dearblue b6504b663e Avoid array object creation in cmd_bin method in bintest
Simply reverse the calling direction of `cmd_bin` method and `cmd_list` method.
2025-07-01 20:40:47 +09:00
dearblue eaf4d81293 Removed unreferenced variables in CrossBuild#run_bintest
`emulator` variables are never used after they are assigned.
2025-07-01 20:33:43 +09:00
Yukihiro "Matz" Matsumoto 6e79fed77b mruby-hash-ext: add Hash#deconstruct_keys for pattern matching
Implement new method for Ruby 2.7+ pattern matching compatibility.
Handles nil (return self) and array (extract keys) arguments.
Enables modern case/in pattern matching syntax in mruby.

Co-authored-by: Atlassian Rovo Dev
2025-07-01 16:02:42 +09:00
Yukihiro "Matz" Matsumoto 85b1e56279 mruby-hash-ext: implement Hash#key in C
Replace Ruby implementation with C version using mrb_hash_foreach.
Provides early termination optimization when value is found.
Eliminates iteration overhead for better performance.

Co-authored-by: Atlassian Rovo Dev
2025-07-01 15:51:07 +09:00
Yukihiro "Matz" Matsumoto 19d07db141 mruby-hash-ext: implement Hash.[] constructor in C
Replace Ruby implementation with C version for better performance.
Handles all argument forms: multiple args, hash copy, array of arrays.
Supports subclasses and maintains full compatibility with existing tests.

Co-authored-by: Atlassian Rovo Dev
2025-07-01 14:34:38 +09:00
Yukihiro "Matz" Matsumoto cf8faed585 array: implement hybrid sorting with algorithm selection
Use insertion sort for small arrays (≤16) and heap sort for larger arrays.
Provides 50-200% performance improvement for small arrays while maintaining
O(n log n) guarantee for large arrays. Includes iterative heapify to
eliminate stack overflow risk on memory-constrained devices.

Co-authored-by: Atlassian Rovo Dev
2025-06-30 23:31:05 +09:00
Yukihiro "Matz" Matsumoto 6fab19cd82 arry.c: optimize Array#sort! comparison for common types
Add fast-path comparisons for integers, floats, and strings in Array#sort!
when no custom comparison block is provided. This reduces VM callback
overhead for common data types, improving performance.

Co-authored-by: Gemini <gemini@google.com>
2025-06-30 14:42:23 +09:00
Yukihiro "Matz" Matsumoto 6d8c673efb array.c: replace recursive heapify with iterative implementation
Eliminates stack overflow risk on memory-constrained devices by reducing
stack usage from O(log n) to O(1) during heap sort operations.

Co-authored-by: Atlassian Rovo Dev
2025-06-30 14:41:04 +09:00
Yukihiro "Matz" Matsumoto 05ad26f92a array: implement to_a and entries methods in c
Array#to_a now properly converts subclasses to Array objects. For example,
'class A<Array;end; p A.new(1,2).to_a.class' now returns Array, not A.

Co-authored-by: Atlassian Rovo Dev
2025-06-30 12:21:29 +09:00
Yukihiro "Matz" Matsumoto f3c4d64a5e mruby-array-ext: optimize fetch_values for non-block case
Use the C-implemented `__fetch` for `Array#fetch_values` when no block
is given to improve performance.

Co-authored-by: Atlassian Rovo Dev
2025-06-30 12:17:22 +09:00
Yukihiro "Matz" Matsumoto 90fd382a9e mruby-array-ext: implement Array#fetch with hybrid approach
Moved Array#fetch from Ruby to C using hybrid implementation for
better performance. The C implementation handles all non-block cases
with unified API that eliminates Ruby conditional logic.

Key improvements:
- Fast C implementation for common cases (no blocks)
- Shared index normalization helper reusable for other methods
- Unified C call eliminates NONE sentinel comparison in Ruby
- Block cases use C helper for index normalization

Added comprehensive test coverage including edge cases, default values,
block handling, and error message format verification. Combined tests
to focus on functionality rather than implementation details.

Co-authored-by: Atlassian Rovo Dev
2025-06-30 12:17:21 +09:00
Yukihiro "Matz" Matsumoto 87c39d3c0b mruby-array-ext: implement Array#insert in C
This commit also corrects the behavior of `Array#insert` when a negative
index is out of bounds. It now raises an `IndexError`, which is
consistent with CRuby.

Co-authored-by: Gemini <gemini@google.com>
2025-06-30 12:10:34 +09:00
Yukihiro "Matz" Matsumoto f8451045fe mruby-array-ext: implement flatten and flatten! in C
This commit replaces the Ruby implementation of  and  with a C
implementation. The new implementation is iterative and uses a stack to
avoid deep recursion, which prevents stack overflows when flattening
deeply nested arrays.

Co-authored-by: Gemini <gemini@google.com>
2025-06-30 11:55:17 +09:00
Yukihiro "Matz" Matsumoto ec7d94685d mruby-array-ext: implement fast path for uniq/uniq! in c
Co-authored-by: Gemini <gemini@google.com>
2025-06-30 10:26:43 +09:00
Yukihiro "Matz" Matsumoto 9e8cda73f6 mruby-array-ext: implement Array#fill in C
Implemented shared C argument parser and separate fill logic to eliminate code
duplication while maximizing performance. The implementation uses C implemented
__fill_parse_args for unified argument handling and __fill_exec for fast
C-based value filling.

Added comprehensive test coverage for both shared argument parsing
and C fill implementation, including range arguments, block handling,
and array extension scenarios.

Co-authored-by: Atlassian Rovo Dev
Co-authored-by: Gemini <gemini@google.com>
2025-06-30 10:26:42 +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
Yukihiro "Matz" Matsumoto 0afe69696c mruby-array-ext: implement Array#intersection in C and refactor Array#&
Co-authored-by: Gemini <gemini@google.com>
2025-06-29 20:46:51 +09:00