43 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 8956c5abb5 mruby.h: include mruby/presym.h for all source files
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>
2026-03-09 16:50:58 +09:00
Yukihiro "Matz" Matsumoto 71cb3c2e3a class.c: allocate ROM table wrappers per mrb_state
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>
2026-02-20 22:24:31 +09:00
Yukihiro "Matz" Matsumoto 483c155a41 class.c: store aspec in ROM method table entries
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>
2026-02-20 11:44:28 +09:00
Yukihiro "Matz" Matsumoto 20b9002214 class.c: merge conditional methods into ROM tables
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>
2026-02-20 11:05:03 +09:00
Yukihiro "Matz" Matsumoto 8adba34bd9 class.c: auto-set MRB_MT_FUNC in MRB_MT_ENTRY macro
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>
2026-02-20 10:37:06 +09:00
Yukihiro "Matz" Matsumoto 0fab703028 class.c: use linear search for method tables; make ROM entries const
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>
2026-02-20 08:26:05 +09:00
Yukihiro "Matz" Matsumoto bde2202100 class.c: refactor ROM method tables to array-of-structs layout
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>
2026-02-19 23:59:30 +09:00
Yukihiro "Matz" Matsumoto 0ed26f8352 class.c: rename mt_/MT_ to mrb_mt_/MRB_MT_ for non-static identifiers
Follow mruby's naming convention: non-static types, macros, and
functions use the mrb_/MRB_ prefix. Renamed:
- union mt_ptr -> union mrb_mt_ptr
- mt_tbl -> mrb_mt_tbl
- MT_KEY(), MT_FUNC, MT_NOARG, MT_PUBLIC, MT_PRIVATE -> MRB_MT_*
- MT_KEY_SHIFT, MT_READONLY_BIT, MT_REMOVED_P -> MRB_MT_*
- mt_init_rom() -> mrb_mt_init_rom()
File-local static functions and macros in class.c are unchanged.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-19 15:22:55 +09:00
Yukihiro "Matz" Matsumoto 9fbc11c6d0 mrbgems: remove MRB_NO_PRESYM guards from core extension gems
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-19 12:17:34 +09:00
Yukihiro "Matz" Matsumoto 63df017ff6 mruby-object-ext: ROM method tables for NilClass/Kernel/BasicObject extensions (5 methods)
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 16:44:27 +09:00
Yukihiro "Matz" Matsumoto 07b803e28a docs: replace xml-style markup with markdown in comments
Replace XML-style markup tags in comments with markdown equivalents:
- <code>...</code> to `...` (inline code)
- <tt>...</tt> to `...` (teletype/monospace)
- <i>...</i> to *...* (italics/emphasis)
- +...+ to `...` (parameter/variable references)

Updated 80+ files across core source, headers, mrbgems, and libraries
to use consistent markdown formatting in documentation comments.
Handled edge cases including special characters like <=> operators.

Co-authored-by: Atlassian Rovo Dev
2025-08-14 10:52:49 +09:00
dearblue f9151e0bd9 Fixed argument forwarding in instance_exec
However, on C, there is no easy way to pass keyword arguments.
Therefore, when called `Kernel#instance_exec` on C, keyword arguments are converted to positional arguments.
This is a limitation of current mruby.

fixed #6389
2024-10-24 21:20:46 +09:00
Yukihiro "Matz" Matsumoto e1a62a581f mruby-object-ext: use presym for initialization 2024-06-14 00:33:18 +09:00
dearblue 3111990089 Introduce mrb_obj_itself()
Some method definitions were changed to use this function.
2024-01-20 22:07:29 +09:00
Yukihiro "Matz" Matsumoto 49b887d75f mruby-object-ext/object.c: remove mrb_ prefix from static functions 2023-04-20 22:40:10 +09:00
Yukihiro "Matz" Matsumoto 7df31d9451 mruby.h: remove acc from callinfo; add cci instead.
`acc` was used as an index of the receiver (if positive), or a flag for
methods implemented in C. We replace `regs[ci->acc]` by `ci[1].stack[0]`.
And renamed `acc` (originally meant accumulator position) to `cci`
(means callinfo for C implemented method).
2021-09-10 12:39:51 +09:00
Yukihiro "Matz" Matsumoto 17ecf14511 Revert "Minimize the changes in #5277"
This reverts commit dc51d89ac2.
2021-01-26 10:57:07 +09:00
Yukihiro "Matz" Matsumoto dc51d89ac2 Minimize the changes in #5277
Instead of including `mruby/presym.h` everywhere, we provided the
fallback `mruby/presym.inc` under `include/mruby` directory, and specify
`-I<build-dir>/include` before `-I<top-dir>/include` in `presym.rake`.
So even when someone drops `-I<build-dir>/include` in compiler options,
it just compiles without failure.
2021-01-22 18:38:53 +09:00
Yukihiro "Matz" Matsumoto 6c5ccd5abe Merge branch 'avoid-including-presym.inc-in-existing-header-files' of https://github.com/shuujii/mruby into shuujii-avoid-including-presym.inc-in-existing-header-files 2021-01-21 14:53:18 +09:00
KOBAYASHI Shuji 90b53f4c29 Avoid including presym.inc in existing header files
Addressed an issue where existing programs linking `libmruby.a` could only
be built by adding `<build-dir>/include` to compiler's include path.
2021-01-11 09:21:07 +09:00
dearblue 58e9442737 Unified target_class and env of mrb_callinfo
If there is `env`, `env->c` means `target_class`.
2021-01-10 13:23:28 +09:00
Yukihiro "Matz" Matsumoto 8a87549315 Rename float configuration option names.
- `MRB_WITHOUT_FLOAT` => `MRB_NO_FLOAT`
- `MRB_USE_FLOAT` => `MRB_USE_FLOAT32`

The former is to use `USE_XXX` naming convention. The latter is to make
sure `float` is 32bit float and not floating point number in general.
2020-10-12 16:21:40 +09:00
Yukihiro "Matz" Matsumoto 2a366ffba8 Use functions that take symbols to reduce string litrals in C. 2020-10-12 16:20:59 +09:00
Yukihiro "Matz" Matsumoto d3a02a297f Fix instance_exec and class_exec to avoid crash on indirect calls.
Thank you @shuujii to additional report on #4973
2020-04-22 16:48:33 +09:00
dearblue 099a4f3969 Entrust "no block given" error to mrb_get_args()
Some error messages will be changed.
2019-09-16 20:29:58 +09:00
KOBAYASHI Shuji 2d520eaf6f Move NilClass#to_h to mruby-object-ext from mruby-enum-ext 2019-07-24 20:13:26 +09:00
KOBAYASHI Shuji 03fce2e206 Kernel#itself should not be a module function 2019-05-29 15:57:18 +09:00
Yukihiro "Matz" Matsumoto 8170f6899c Merge pull request #4450 from shuujii/move-Kernel-instance_exec-to-BasicObject
Move `Kernel#instance_exec` to `BasicObject`
2019-05-19 22:21:31 +09:00
Yukihiro "Matz" Matsumoto 8e637bdd83 Should clarify the role of mruby-kernel-ext and mruby-object-ext; close #4449
The former should contain function like methods, and the latter should
contain methods shared by all objects.
2019-05-19 22:17:56 +09:00
KOBAYASHI Shuji ef5dd5d31d Move Kernel#instance_exec to BasicObject 2019-05-18 19:19:52 +09:00
YAMAMOTO Masaya 9afd376fa4 Support MRB_WIHTOUT_FLOAT to mruby-object-ext 2017-10-16 18:15:25 +09:00
Yukihiro "Matz" Matsumoto 877e16501c No longer need to copy argv from mrb_get_args; ref #3722 2017-06-27 22:47:26 +09:00
Yukihiro "Matz" Matsumoto 6a0b68f8b8 Use trampoline technique for instance_exec; ref #3359
A new function `mrb_yield_cont()` is provided. You have to call it
at the end of a C defined method, e.g. `return mrb_yield_cont()`.
2017-04-19 19:54:55 +09:00
Yukihiro "Matz" Matsumoto 191ee2596c Need to copy argv since it may be reallocated; fix #3500
The argv for `mrb_yield_with_class()` should not be on mruby stack.
Note the result from `mrb_get_args("*")` is on the stack.
2017-03-13 22:51:53 +09:00
Yukihiro "Matz" Matsumoto b165708c8d Move #instance_exec to Kernel module
CRuby defines #instance_exec in BasicObject, but we don't.
It's a small incompatibility that isn't worth accomplish at
the price of implementation complexity.
2017-02-15 13:24:03 +09:00
Yukihiro "Matz" Matsumoto 5c405dea3d include changed from by quotes ("") to by brackets (<>); close #3032 2015-11-27 17:48:23 +09:00
kkkkkt d94469ac23 changed to call check_cv_name_str in check_cv_name_sym and adjust indent 2014-08-21 13:56:43 +09:00
take_cheeze b5028421b9 Use mrb_int in mrbgem rest argument getting. 2014-04-25 22:02:10 +09:00
Yukihiro "Matz" Matsumoto 9084e03556 rename mrb_yield_internal to mrb_yield_with_class since it's no longer internal 2014-03-19 08:57:54 +09:00
Tomoyuki Sahara 93694fe521 export mrb_yield_internal. 2014-03-19 01:08:01 +09:00
Jun Hiroe 0804800921 I replace 0 with NULL because struct pointer be should set NULL in. 2013-07-27 13:16:08 +09:00
h2so5 2117f0973c Add Object#instance_exec 2013-07-01 16:23:14 +09:00
Akira Yumiyama 36fc42e7db add nil.to_a, nil.to_f, nil.to_i methods 2013-06-28 10:01:07 +09:00