105 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 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 0ac01f23ba mruby-hash-ext: ROM method table for Hash extensions (6 methods)
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 16:44:23 +09:00
Yukihiro "Matz" Matsumoto 34b94129d2 mruby-hash-ext: remove non-compatible Hash#deconstruct_keys
CRuby's Hash#deconstruct_keys simply returns self regardless of
arguments. The mruby-hash-ext version filtered keys, which was
unnecessary since the compiler accesses individual keys via []
after calling deconstruct_keys. The Ruby implementation in
mrblib/hash.rb (returning self) is sufficient and CRuby-compatible.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-16 16:57:21 +09:00
Yukihiro "Matz" Matsumoto 7cc41d5bc0 mruby-hash-ext: standardize block parameter spacing
changed block spacing from method{ to method { for consistency.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-11 18:09:09 +09:00
Yukihiro "Matz" Matsumoto 6e67d64068 mruby-hash-ext: add parentheses to to_enum calls
added parentheses to all to_enum calls where the return value is used.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-11 18:09:06 +09:00
Yukihiro "Matz" Matsumoto 5a147838ba mruby-hash-ext: combine variable declaration with initialization 2025-10-26 23:52:20 +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
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 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 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 8fbe5523cf mruby-hash-ext: add README.md
The document is written by Google Jules.
2025-06-10 10:53:57 +09:00
John Bampton 4f2f2cfd20 Add ls-lint with GitHub Actions
Rename files in the `mrbgems` directory
2025-05-14 01:14:02 +10:00
Yukihiro "Matz" Matsumoto 4104837ba1 mruby-hash-ext: use presym for initialization 2024-06-14 01:41:55 +09:00
Yukihiro "Matz" Matsumoto dcee404ebb mruby-hash-ext: use NONE.equal?() for NONE comparison; ref #6262 2024-05-10 20:40:11 +09:00
Yukihiro "Matz" Matsumoto e71e1bc50e mruby-hash-ext: reduce the scope of the loop variable i 2024-01-03 07:23:55 +09:00
Yukihiro "Matz" Matsumoto 1b299addaf mruby-hash-ext/hash.rb: implement Hash#compact! in C
Using `__compact` method defined in the core, since hash access
functions are private to `src/hash.c`.
2023-02-02 22:44:04 +09:00
Yukihiro "Matz" Matsumoto 9cda737a56 mruby-hash-ext/test: test Hash#compact! returns nil if unmodified 2023-02-02 22:42:36 +09:00
Yukihiro "Matz" Matsumoto d6dc9caa02 mruby-hash-ext/hash.rb: make transform_keys! to keep old keys
```ruby
h={1=>2,2=>3}
h.transform_keys!{_1.succ}
```

used to make `h` to `{2=>2}` (duplicated keys were squashed), but now
makes it `{2=>2,3=>3}`.
2022-12-14 07:39:10 +09:00
John Bampton ea8964ef35 ruby: standardize whitespace 2022-10-31 16:25:56 +10:00
Yukihiro "Matz" Matsumoto 3b55a09f91 mruby-hash-ext/hash.c (hash_values_at): early return from the function. 2022-10-21 13:41:38 +09:00
Yukihiro "Matz" Matsumoto d2a24a540c hash.c: implement typical part of merge in C. 2022-06-19 22:28:31 +09:00
Yukihiro "Matz" Matsumoto 909e1044ed mruby-hash-ext/hash.rb (merge!): takes multiple arguments. 2022-06-18 16:12:14 +09:00
dearblue 2d0b50f6f3 Avoid warnings with ruby -cw
```console
% for rb in `git ls-files '*/mrblib/*.rb' 'mrblib'`; do ruby30 -cw $rb > /dev/null; done
mrbgems/mruby-array-ext/mrblib/array.rb:389: warning: assigned but unused variable - ary
mrbgems/mruby-array-ext/mrblib/array.rb:663: warning: assigned but unused variable - len
mrbgems/mruby-hash-ext/mrblib/hash.rb:119: warning: possibly useless use of a variable in void context
mrbgems/mruby-hash-ext/mrblib/hash.rb:259: warning: assigned but unused variable - keys
mrbgems/mruby-io/mrblib/io.rb:229: warning: literal in condition
mrbgems/mruby-io/mrblib/io.rb:280: warning: literal in condition
mrbgems/mruby-string-ext/mrblib/string.rb:347: warning: assigned but unused variable - len
mrbgems/mruby-toplevel-ext/mrblib/toplevel.rb:2: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument
```
2021-06-28 23:21:47 +09:00
John Bampton d55a74c418 feat(CI): check for trailing whitespace
Run on pull request only.
Use a shell script to check for trailing whitespace in all files.
Fail if trailing whitespace is found.
2021-02-13 16:37:46 +10:00
Seeker 14a92f9705 Add Hash#except [Ruby 3.0] 2020-12-27 16:33:12 -08:00
dearblue f0a64329b1 Prohibit array changes by "a"/"*" specifier of mrb_get_args()
The "a"/"*" specifier of the `mrb_get_args()` function will now return `const mrb_value *`.
This is because it is difficult for the caller to check if it is an array object and write-barrier if necessary.
And it requires calling `mrb_ary_modify()` on the unmodified array object, which is also difficult (this is similar to #5087).
2020-10-22 22:55:35 +09:00
Yukihiro "Matz" Matsumoto fc8fb41451 Small refactoring in hash_slice; ref #4926 2020-01-10 17:57:33 +09:00
KOBAYASHI Shuji ac213907d7 Remove unneeded dependency from mruby-hash-ext 2019-11-08 20:40:20 +09:00
KOBAYASHI Shuji ea2424d36d Drop test dependency from mruby-hash-ext to mruby-enumerator 2019-11-06 18:57:35 +09:00
Yukihiro "Matz" Matsumoto 57a0132b41 Add filter aliases for Enumerable and Hash. 2019-09-16 10:10:09 +09:00
Yukihiro "Matz" Matsumoto 610bcc88c2 Removed to_hash conversion method. 2018-11-19 12:08:28 +09:00
Yukihiro "Matz" Matsumoto 5bbcea9b3b Removed try_convert method from Array and Hash. 2018-11-19 12:08:28 +09:00
Yukihiro "Matz" Matsumoto 8ffd4e47fb Use mrb_undef_value for delete mark instead of shifting Hash entry table.
That means entry table should be compacted periodically by `sg_compact()`.
2018-09-26 23:09:48 +09:00
Yukihiro "Matz" Matsumoto 3820ef791f Small refactoring in mruby-hash-ext. 2018-09-20 09:07:24 +09:00
Yukihiro "Matz" Matsumoto 62e8e910b2 Reimplement Hash#compact! to conform the standard behavior.
`Hash#compact!` should return `nil` if the receiver does not change.
2018-08-06 16:40:19 +09:00
Yukihiro "Matz" Matsumoto ad17ba0e11 KeyError from Hash#fetch should inspect key.
To distinguish string keys and symbol keys.
2017-12-25 23:52:40 +09:00
Yukihiro "Matz" Matsumoto 421819dc2c Add Hash#slice [Ruby 2.5] 2017-12-25 23:43:37 +09:00
Yukihiro "Matz" Matsumoto df68a3345d assert_equal() takes result as the first argument 2017-12-25 15:39:45 +09:00
Yukihiro "Matz" Matsumoto ce916b99b8 Add Hash#to_proc; CRuby2.3 2017-10-18 10:18:43 +09:00
Yukihiro "Matz" Matsumoto 44f07045d1 Add Hash#fetch_values; CRuby2.3 2017-10-18 10:05:39 +09:00