Since presym is now mandatory, mruby.h includes presym.h so that
MRB_SYM() macros are available everywhere without explicit include.
Remove redundant #include <mruby/presym.h> from all source files.
Co-authored-by: Claude <noreply@anthropic.com>
ROM method tables used static mrb_mt_tbl variables shared
across the process. The next pointer in each wrapper was
mutated by mrb_mt_init_rom(), causing cross-state
contamination when multiple mrb_state instances existed.
Allocate mrb_mt_tbl wrappers per-state via mrb_malloc().
The const mrb_mt_entry[] arrays remain static and shared.
Wrappers are tracked in mrb->rom_mt and freed at mrb_close().
Remove MRB_MT_ROM_TAB macro; add MRB_MT_INIT_ROM macro that
auto-computes size and calls the new mrb_mt_init_rom().
Co-authored-by: Claude <noreply@anthropic.com>
Restore MRB_ARGS_* argument specs and ISO section comments to all
709 ROM method table entries. The aspec is encoded in bits 4-27 of
the flags field; MRB_MT_NOARG is now auto-derived from aspec==0.
Add MRB_MT_ENTRY_PRIVATE() macro for private methods (53 entries)
and MRB_MT_ASPEC() accessor for extracting aspec from flags.
Co-authored-by: Claude <noreply@anthropic.com>
Move conditional mrb_define_method_id() calls into ROM entry
arrays using #ifdef guards. With linear search, sizeof in
MRB_MT_ROM_TAB() adjusts automatically after preprocessing.
Cross-class ROM tables (methods a gem defines on a class it does
not own) are reverted to mrb_define_method_id(). Multiple gems
should not add ROM table layers to the same class; each layer
costs a 16-byte mrb_mt_tbl struct in RAM and deepens the lookup
chain. Use mrb_define_method_id() for cross-class methods.
Co-authored-by: Claude <noreply@anthropic.com>
Since ROM table entries are always C functions, have the
MRB_MT_ENTRY() macro set MRB_MT_FUNC automatically. This
simplifies entry definitions across all 32 source files.
Co-authored-by: Claude <noreply@anthropic.com>
Replace binary search with linear scan in mt_get(), mt_put(),
mt_del(), mt_chain_has(), and mrb_mt_foreach(). The method cache
makes repeated lookups O(1), so linear scan on cache misses is
acceptable.
This removes the sorting requirement, allowing ROM entry arrays
to be declared const. On embedded systems, const static data
resides in flash/ROM instead of RAM, saving ~8.4KB for ~700
method entries on 32-bit MCUs.
Co-authored-by: Claude <noreply@anthropic.com>
Replace the parallel-arrays (struct-of-arrays) ROM method table
layout with an array-of-structs layout where each mrb_mt_entry
bundles its function pointer and symbol key together.
New MRB_MT_ENTRY() and MRB_MT_ROM_TAB() macros simplify ROM table
definitions from a 3-part pattern (SIZE define + anonymous struct +
mrb_mt_tbl) to a 2-part pattern (entries array + mrb_mt_tbl).
Internal mt_* functions in class.c are simplified: single memmove/
memcpy operations replace paired key+value operations.
Co-authored-by: Claude <noreply@anthropic.com>
Implement the Complex#** method in C. This method calculates complex
exponentiation using `exp(w * log(z))` for complex exponents and
`(abs(z)**n) * Complex.polar(1, n * arg(z))` for real exponents.
Optimize the performance of `Complex#div` by using a hybrid approach.
For common cases, a direct calculation is used. For extreme values,
it falls back to the `frexp`/`ldexp` based calculation for numerical
stability.
Co-authored-by: Gemini <gemini@google.com>
Refactor the C implementation of arithmetic operations (+, -, *)
to reduce code duplication. A new static helper function `complex_op`
is introduced to handle the common logic of the operations.
Co-authored-by: Gemini <gemini@google.com>
Added complete call-seq documentation for all Complex methods in
mrblib/complex.rb (18 methods):
## Complex Class Methods:
- polar: creates complex number from polar coordinates (magnitude, angle)
with trigonometric conversion using Math.cos and Math.sin
## Complex Instance Methods:
- inspect, to_s: string representation methods for debugging and display
with proper formatting of real and imaginary parts
- +@, -@: unary plus and minus operators for identity and negation
- <=>: spaceship operator for comparison with other numeric types,
enables Comparable module functionality with proper nil handling
- abs/magnitude: absolute value (magnitude) calculation using hypot
- abs2: square of absolute value for performance-critical calculations
- arg/angle/phase: argument (angle) calculation using atan2
- conjugate/conj: complex conjugate operation (negates imaginary part)
- fdiv: floating-point division ensuring float results
- polar: returns [magnitude, angle] array representation
- real?: always returns false for complex numbers
- rectangular/rect: returns [real, imaginary] array representation
- to_c: returns self (identity conversion)
- to_r: converts to rational when imaginary part is zero, raises RangeError otherwise
## Numeric Extension Methods:
- i: creates pure imaginary number (0+num*i) for convenient complex creation
- to_c: converts any numeric to complex with zero imaginary part
Co-authored-by: Atlassian Rovo Dev
The method introduced by #5979 causes a fault by swapping classes.
```console
% bin/mruby -e 'Method = Proc; p Object.method(:inspect)'
zsh: segmentation fault (core dumped) bin/mruby -e 'Method = Proc; p Object.method(:inspect)'
```
After applying this patch, a `TypeError` exception will be raised.
```console
% bin/mruby -e 'Method = Proc; p Object.method(:inspect)'
trace (most recent call last):
[1] -e:1
-e:1:in method: allocation failure of Proc (TypeError)
```
However, if the `mrb_vtype` is the same object, the same care must still be taken as before.
```console
% bin/mruby -e 'Method = Binding; p method(:puts).eval("12345")'
trace (most recent call last):
[1] -e:1
-e:1:in eval: wrong argument type nil (expected Proc) (TypeError)
```
Calling `Class#allocate` with `UnboundMethod#bind_call` usually succeeds without problems.
If this behavior does not make us happy, we can now prohibit it with `MRB_SET_INSTANCE_TT(klass, MRB_TT_UNDEF)`.
At the same time, it applies to the `Binding`, `Complex`, `Data`, `Float`, `Integer`, `Method`, `Rational` and `UnboundMethod` classes.
ref. commit 7f40b645d2
Currently, the build configurations `MRB_USE_COMPLEX` and `MRB_USE_RATIONAL` are not listed in the documentation.
In other words, they are hidden settings.
They are defined in `mrbgems/mruby-{complex,rational}/mrbgem.rake`.
So this patch assumes that it is safe to refer to these functions in core-gems directly from core functions.
However, applications that link with `libmruby_core.a` will have compatibility issues.
In fact, `mrbgems/mruby-bin-mrbc` links with `libmruby_core.a`, so I had to prepare a dummy function.
- `#include <math.h>` is done in `mruby.h`.
Eliminate the need to worry about the `MRB_NO_FLOAT` macro.
- Include mruby header files before standard header files.
If the standard header file is already placed before `mruby.h`, the standard header file added in the future tends to be placed before `mruby.h`.
This change should some reduce the chances of macros that must be defined becoming undefined in C++ or including problematic header files in a particular mruby build configuration.
Running pre-commit with GitHub Actions now gives us more tests and coverage
Remove duplicate GitHub Actions for merge conflicts and trailing whitespace
Remove duplicate checks for markdownlint and yamllint from the GitHub Super-Linter
Add new custom pre-commit hook running with a shell script to sort alphabetically and uniquify codespell.txt
Add new pre-commit hook to check spelling with codespell
https://github.com/codespell-project/codespell
Fix spelling
The GitHub Super Linter is a more robust and better supported
tool than the current GitHub Actions we are using.
Running these checks:
ERROR_ON_MISSING_EXEC_BIT: true
VALIDATE_BASH: true
VALIDATE_BASH_EXEC: true
VALIDATE_EDITORCONFIG: true
VALIDATE_MARKDOWN: true
VALIDATE_SHELL_SHFMT: true
VALIDATE_YAML: true
https://github.com/marketplace/actions/super-linterhttps://github.com/github/super-linter
Added the GitHub Super Linter badge to the README.
Also updated the pre-commit framework and added
more documentation on pre-commit.
Added one more pre-commit check: check-executables-have-shebangs
Added one extra check for merge conflicts to our
GitHub Actions.
EditorConfig and Markdown linting.
Minor grammar and spelling fixes.
Update linter.yml
- `mrb_num_div_int(mrb,x,y)` -> `mrb_div_int(mrb,x,y)`
- `mrb_num_div_flo(mrb,x,y)` -> `mrb_div_flo(x,y)`
They are internal function not supposed to be used outside of the core.