Instances cannot be created with `MRB_TT_FALSE`.
_**Compatibility Note**_
This change may cause runtime errors.
However, that is probably because it is not set correctly by `MRB_SET_INSTANCE_TT()`.
The purpose is to force the setting of the type tag.
This is in preparation for subsequent commits that will prevent the creation of instances with `MRB_TT_FALSE`.
Added complete call-seq documentation for proc binding functionality across
both source and test files:
## Core Implementation (src/proc_binding.c):
### Main Method:
- binding: returns Binding object capturing proc's execution context,
includes comprehensive examples showing local variable access, parameter
binding, and scope retention with practical usage patterns
### Helper Functions:
- mrb_mruby_proc_binding_gem_init: initializes gem by adding binding method
to Proc class, explains method signature and return type behavior
Co-authored-by: Atlassian Rovo Dev
Enhanced documentation for Binding class methods with detailed examples:
- local_variable_defined?: Added examples showing usage within methods and at
top-level, including interaction with local_variable_set
- local_variable_get: Added examples demonstrating retrieval of different data
types, variable modification tracking, and NameError behavior
- local_variable_set: Added examples showing variable assignment and creation
- local_variables: Added examples showing array of local variable names
- receiver: Added examples showing bound receiver object access
- binding (Kernel method): Added examples showing binding creation and usage
Co-authored-by: Atlassian Rovo Dev
Added complete call-seq documentation for 4 missing public methods in the
data gem, improving documentation coverage from 46% to 77%.
Documentation added:
- Data.members: Returns array of member symbols for the class
- Data.define: Creates new data instances with positional or keyword arguments
- Data#initialize: Initializes data structure with hash values
- Data#initialize_copy: Copies data structure for dup/clone operations
Each method now includes:
- Clear method signatures with parameter and return types
- Detailed descriptions of data structure behavior
- Practical examples showing usage patterns
- Notes about member access and initialization
- Cross-references between class and instance methods
Co-authored-by: Atlassian Rovo Dev
Added comprehensive call-seq documentation for the missing caller method
in the kernel-ext gem, improving documentation coverage from 78% to 100%.
Documentation added:
- caller: Returns execution stack as array of strings with file:line format
The caller method now includes:
- Clear method signatures with multiple calling conventions
- Detailed description of stack trace functionality
- Practical examples showing usage patterns
- Notes about start parameter and stack omission behavior
- Explanation of output format variations
This completes the documentation for all kernel extension methods,
providing full coverage for type conversion functions (Integer, Float,
String, Array, Hash), introspection methods (__method__, __callee__),
and debugging utilities (caller). The fail method references the core
mrb_f_raise function which is documented elsewhere.
Co-authored-by: Atlassian Rovo Dev
Added complete call-seq documentation for all 5 public methods in the
eval gem, improving documentation coverage from 0% to 100%.
Documentation added:
- eval: Evaluate Ruby expressions with optional binding and file context
- Object#instance_eval: Evaluate code in the context of an object instance
- Module#class_eval/module_eval: Evaluate code in the context of a class/module
- Binding#eval: Evaluate code within a specific binding context
Each method now includes:
- Clear method signatures with parameter and return types
- Detailed descriptions of evaluation context and scope behavior
- Comprehensive examples showing practical usage patterns
- Notes about binding objects, file/line reporting, and block alternatives
- Explanations of self context changes and variable access
- Security and error handling considerations
Key documentation features:
- String vs block evaluation differences explained
- Binding context usage with practical examples
- Instance variable and private method access patterns
- Class/module modification examples
- Error reporting with filename and line number context
Co-authored-by: Atlassian Rovo Dev
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
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
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
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
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
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
- 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
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>
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>
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>
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>
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>
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>
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>
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>
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>
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.
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>
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>
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>
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>
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>