Commit Graph

17214 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 410516fdff mruby-random: add comprehensive call-seq documentation for missing methods
Added complete call-seq documentation for 7 missing public methods in the
random gem, improving documentation coverage from 25% to 100%.

Documentation added:
- Random.new: Create new random number generator with optional seed
- Random#rand: Generate random numbers (float, integer, or range)
- Random#srand: Seed the random number generator
- Random#bytes: Generate random byte strings
- Random.rand/rand: Class method and Kernel method for default generator
- Random.srand/srand: Class method and Kernel method for seeding
- Random.bytes: Class method for random bytes using default generator

Each method now includes:
- Clear method signatures with parameter and return types
- Detailed descriptions of random number generation behavior
- Practical examples showing different usage patterns
- Notes about default vs instance generators
- Cross-references between class methods and Kernel methods
- Range and numeric type handling explanations

The existing Array methods (shuffle, shuffle!, sample) were already
well-documented and remain unchanged. This completes the documentation
for all random number generation functionality in mruby, covering both
the Random class API and the traditional Kernel methods.

This significantly improves usability for developers working with
random number generation, cryptographic applications, and statistical
sampling in embedded Ruby environments.

Co-authored-by: Atlassian Rovo Dev
2025-07-16 11:58:59 +09:00
Yukihiro "Matz" Matsumoto e7c7b400a1 mruby-pack: add comprehensive call-seq documentation for all methods
Added complete call-seq documentation for all 3 public methods in the
pack gem, improving documentation coverage from 0% to 100%.

Documentation added:
- Array#pack: Pack array elements into binary string using template
- String#unpack: Unpack binary string into array using template
- String#unpack1: Unpack first value from binary string using template

Each method now includes:
- Clear method signatures with parameter and return types
- Comprehensive template directive reference table covering all supported formats
- Detailed descriptions of binary data packing/unpacking behavior
- Practical examples showing common usage patterns for different data types
- Notes about endianness, data type sizes, and string handling
- Cross-references between related methods

Template directives documented include:
- Integer types: C, c, S, s, L, l, Q, q (various sizes and signedness)
- Network/endian specific: n, N, v, V (network and little endian)
- Floating point: f, d (single and double precision)
- String types: A, a, Z (ASCII with different padding)
- Hex and binary: H, h (hex strings with nibble order)
- Special: x, X, @ (null bytes, positioning)

Co-authored-by: Atlassian Rovo Dev
2025-07-16 10:09:54 +09:00
Yukihiro "Matz" Matsumoto 2bd9c4327b mruby-time: add comprehensive call-seq documentation for all methods
Added complete call-seq documentation for all 39 public methods in the
Time class, improving documentation coverage from 0% to 100%.

Documentation added includes:

Class methods (6):
- Time.now: Get current system time
- Time.at: Create time from epoch seconds
- Time.gm/utc: Create UTC time from components
- Time.local/mktime: Create local time from components

Instance methods (33):
- Arithmetic: +, -, <=> for time calculations and comparisons
- Accessors: year, month, day, hour, min, sec, usec, wday, yday
- Timezone: zone, utc, localtime, getutc, getlocal, utc?, gmt?, dst?
- Conversion: to_i, to_f, to_s, inspect, asctime, ctime, hash
- Initialization: new, initialize_copy
- Weekday helpers: sunday?, monday?, tuesday?, wednesday?, thursday?, friday?, saturday?

Each method now includes:
- Clear method signatures with parameter and return types
- Detailed descriptions of time handling behavior
- Practical examples showing common usage patterns
- Notes about timezone handling and precision
- Consistent formatting following mruby documentation standards

This represents a major improvement in maintainability and usability of
time functionality for developers working with date/time operations in
embedded Ruby environments. The Time class is now fully documented with
comprehensive examples covering all aspects of time manipulation.

Co-authored-by: Atlassian Rovo Dev
2025-07-16 08:03:09 +09:00
Yukihiro "Matz" Matsumoto bac7eb984a mruby-errno: add comprehensive documentation and fix internal method comments
Added complete call-seq documentation for public methods and corrected
internal method documentation structure:

Public API methods
- SystemCallError.new: Create SystemCallError with message/errno
- SystemCallError#errno: Get errno number from exception
- SystemCallError._sys_fail: Internal method to raise errno exceptions
- Errno exception classes#new: Create specific errno exceptions

Fixed documentation structure to follow mruby conventions where internal
methods starting with __ should not have call-seq documentation but only
brief explanatory comments.

Each public method now includes:
- Clear method signatures with parameter and return types
- Descriptions of errno handling behavior
- Practical examples showing exception creation and handling
- Consistent formatting following mruby documentation standards

Co-authored-by: Atlassian Rovo Dev
2025-07-15 17:28:39 +09:00
Yukihiro "Matz" Matsumoto b11596891a mruby-encoding: add missing call-seq documentation for string methods
Added comprehensive call-seq documentation for the 2 missing public
methods in the encoding gem, improving documentation coverage from
33% to 100%.

Documentation added:
- String#encoding: Returns the encoding of a string (UTF-8 or ASCII-8BIT)
- String#force_encoding: Changes string encoding in place

Each method now includes:
- Clear method signatures with parameter and return types
- Descriptions of encoding behavior specific to mruby's limitations
- Practical examples showing usage patterns
- Notes about mruby's simplified encoding support (UTF-8, ASCII-8BIT, BINARY)

This complements the existing String#valid_encoding? documentation and
provides complete coverage for mruby's "poorman's encoding" functionality,
making it easier for developers to understand encoding operations in
embedded Ruby environments.

Co-authored-by: Atlassian Rovo Dev
2025-07-15 11:54:12 +09:00
Yukihiro "Matz" Matsumoto a791069abd mruby-cmath: add comprehensive call-seq documentation for all methods
Added complete call-seq documentation for all 17 public methods in the
CMath module, improving documentation coverage from 0% to 100%.

Documentation includes:
- Method signatures with parameter and return types
- Clear descriptions of mathematical operations
- Branch cut information for complex functions
- Practical examples showing real and complex number usage
- Consistent formatting following mruby documentation standards

Methods documented:
- Exponential and logarithmic: exp, log, log2, log10, sqrt
- Trigonometric: sin, cos, tan, asin, acos, atan
- Hyperbolic: sinh, cosh, tanh, asinh, acosh, atanh

This significantly improves maintainability and usability of the complex
math functionality for developers working with mathematical computations
in embedded Ruby environments.

Co-authored-by: Atlassian Rovo Dev
2025-07-15 11:54:12 +09:00
Yukihiro "Matz" Matsumoto b46d6e07c8 mruby-string-ext: add helpful comments for internal helper functions
- Add descriptive comments for key internal helper functions:
  * str_lines: splits string into array of lines
  * str_codepoints: returns array of character codepoints
  * str_chars_ary: fast path for String#chars returning character array
  * str_hex/str_oct: convert hex/octal strings to integers
  * str_ascii_only_p: checks if string contains only ASCII characters
  * str_b: returns binary encoded copy of string
  * str_char_count: counts UTF-8 characters using mruby standard function
  * str_delete_m/str_delete_bang: delete pattern characters (new/in-place)
- Improves code maintainability for large string extension gem (2309 lines)
- Maintains existing excellent call-seq documentation coverage (37 methods)
- Follows mruby documentation standards and internal helper conventions

Co-authored-by: Atlassian Rovo Dev
2025-07-15 11:54:12 +09:00
Yukihiro "Matz" Matsumoto 42399b33e2 mruby-proc-ext: add comprehensive documentation for all public methods
- Add complete call-seq documentation for 4 missing public methods:
  * Proc#lambda?: returns true if proc is a lambda, false if regular proc
  * Proc#source_location: returns [filename, line] or nil for native procs
  * Proc#to_s/inspect: returns string representation with location info
  * Kernel#proc: equivalent to Proc.new, creates proc from block
- Add helpful comment for internal mrb_proc_source_location helper function
- Improve TODO comment clarity for cfunc aspec limitation
- Achieves 100% public API documentation coverage (5/5 methods documented)
- Improves code maintainability and follows mruby documentation standards

Co-authored-by: Atlassian Rovo Dev
2025-07-15 11:54:11 +09:00
Yukihiro "Matz" Matsumoto 0f0d3482ff Merge pull request #6574 from katafrakt/struct-kwargs 2025-07-15 11:53:59 +09:00
Paweł Świątkowski aa874216dc Optimize checking for valid arguments to avoid O(N*M) complexity 2025-07-14 17:24:52 +02:00
Paweł Świątkowski 512d25607b Support :keyword_init argument when defining a new struct 2025-07-14 15:50:33 +02:00
Paweł Świątkowski 40fa5ec46d Support initializing structs via keyword arguments 2025-07-14 15:50:33 +02:00
Yukihiro "Matz" Matsumoto cf9596d339 mruby-array-ext: add comprehensive documentation for values_at and internal helpers
- Add complete call-seq documentation for Array#values_at method
- Add helpful comments for internal helper functions:
  * ary_ref: helper function for values_at
  * rev: helper function to reverse array elements in-place
  * flatten_internal: iterative stack-based flatten implementation
  * Updated comments for fill, uniq, normalize_index, and fetch helpers
- Improves code maintainability and follows mruby documentation standards
- Achieves 100% public API documentation coverage

Co-authored-by: Atlassian Rovo Dev
2025-07-12 08:38:39 +09:00
Yukihiro "Matz" Matsumoto 95656c40ff state.c: optimize mrb_state initialization by deferring method cache clear
During mrb_state initialization, especially when defining core classes and methods,
the method cache is repeatedly cleared. This causes significant overhead in
scenarios like mrbtest where mrb_state is initialized multiple times.

This commit introduces a `bootstrapping` flag in `struct mrb_state`.
When this flag is TRUE (during mrb_open_core), method cache clears
triggered by `mrb_define_method_raw` and `include_module_at` are suppressed.
The cache is cleared only once at the very end of `mrb_open_core` after
all core methods are defined, and the flag is then set to FALSE.

This optimization significantly reduces the number of method cache clears
during initialization, improving performance for repeated mrb_state creations.

Co-authored-by: Gemini <gemini@google.com>
2025-07-11 10:09:38 +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 5ca2d442ce mruby-struct: add recursion detection to Struct#== and Struct#eql?
Prevent SystemStackError when comparing structs with circular
references.  Uses the same recursion detection mechanism as Hash and
Array equality methods.

Co-authored-by: Claude <noreply@anthropic.com>
2025-07-11 10:09:37 +09:00
Yukihiro "Matz" Matsumoto 38882aecee array.c: add recursion detection to Array#== and Array#eql?
Prevent SystemStackError when comparing arrays with circular references.
Uses the same recursion detection mechanism as Hash equality methods.

Co-authored-by: Claude <noreply@anthropic.com>
2025-07-11 10:09:37 +09:00
Yukihiro "Matz" Matsumoto 5a85350121 kernel.c: replace __inspect_recursive? with __method_recursive?
Add more general __method_recursive?(method_name[, arg]) method that can
check recursion for any method, not just inspect. This provides a more
useful API for Ruby code while cleaning up the implementation.

Co-authored-by: Claude <noreply@anthropic.com>
2025-07-11 10:09:36 +09:00
Yukihiro "Matz" Matsumoto b64fc03182 kernel.c: simplify mrb_inspect_recursive_p using new recursion detection
Replace custom inspect_recursive_p implementation with the new
generalized mrb_recursive_method_p for better code reuse and
consistency.

Co-authored-by: Claude <noreply@anthropic.com>
2025-07-11 10:09:36 +09:00
Yukihiro "Matz" Matsumoto 419c8ebfb2 hash.c: add recursion detection to prevent SystemStackError; fix #5531
Add generalized recursion detection system and integrate it into Hash#==
and Hash#eql? to prevent infinite recursion with mutually recursive hash
structures. Uses call stack inspection for minimal memory overhead.

Co-authored-by: Claude <noreply@anthropic.com>
2025-07-11 10:09:36 +09:00
Yukihiro "Matz" Matsumoto 96355f33b2 hash.c: implement Hash#eql? in C for better performance
Move Hash#eql? implementation from Ruby to C to improve performance and
consistency with other core methods. The C implementation uses mrb_eql
for value comparison, providing proper eql? semantics.

Co-authored-by: Claude <noreply@anthropic.com>
2025-07-11 10:09:36 +09:00
Yukihiro "Matz" Matsumoto 633317a809 hash.c: implement Hash#== in C for better performance
Move Hash#== implementation from Ruby to C to improve performance
and consistency with other core methods. The C implementation
provides the same functionality while being more efficient.

Co-authored-by: Claude <noreply@anthropic.com>
2025-07-11 10:09:35 +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 e6071d5331 mruby-compiler: simplify the code for NODE_WHILE_MOD & NODE_UNTIL_MOD
Instead of having dedicated code, we now share the fundamental part with
normal NODE_WHILE and NODE_UNTIL.
2025-07-11 10:09:35 +09:00
Yukihiro "Matz" Matsumoto 451f67e0ae test/syntax.rb: add at-least-once loop tests
Co-authored-by: Claude <noreply@anthropic.com>
2025-07-11 10:09:34 +09:00
Yukihiro "Matz" Matsumoto ee30d1d0f8 mruby-compiler: allow at-least-once loop behavior for mruby
mruby does not provide `begin ... end while cond` that behave at-least-once
loop, like CRuby does. It remains in TODO.md for long time. But finally we have
implemented the behavior.
2025-07-11 10:09:34 +09:00
Yukihiro "Matz" Matsumoto ebc10f3c57 Add NODE_BEGIN for explicit begin...end blocks
This commit introduces NODE_BEGIN as a distinct AST node type for
explicit begin...end blocks, separate from NODE_STMTS which represents
general statement sequences. This distinction will be essential for
implementing CRuby-compatible begin...end while/until constructs.

Key changes:
- Added NODE_BEGIN enum in node.h
- Added new_begin() function in parse.y using optimized cons() structure
- Modified begin...end grammar rule to generate NODE_BEGIN nodes
- Added NODE_BEGIN codegen support in codegen.c
- Added NODE_BEGIN to parser dump functionality

NODE_BEGIN uses a simpler cons() structure instead of list2() for
better memory efficiency, as it only contains a single body node.

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-11 10:09:34 +09:00
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