Commit Graph

18343 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto c679c2762d symbol.c: ROM method table for Symbol class (6 methods)
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 16:30:49 +09:00
Yukihiro "Matz" Matsumoto c5470958c7 range.c: ROM method table for Range class (15 methods)
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 16:30:47 +09:00
Yukihiro "Matz" Matsumoto 1b20096c31 object.c: ROM method tables for NilClass/TrueClass/FalseClass (16 methods)
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 16:30:45 +09:00
Yukihiro "Matz" Matsumoto 8fdd5757e3 class.c: ROM method tables for BasicObject/Module/Class (49 methods)
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 16:30:43 +09:00
Yukihiro "Matz" Matsumoto cdbc18cf76 kernel.c: ROM method table for Kernel module (27 methods)
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 16:30:41 +09:00
Yukihiro "Matz" Matsumoto 63f462ef1f numeric.c: ROM method tables for Numeric/Integer/Float (63 methods)
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 16:30:38 +09:00
Yukihiro "Matz" Matsumoto 7f74ba248f hash.c: ROM method table for Hash class (36 methods)
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 16:30:37 +09:00
Yukihiro "Matz" Matsumoto 3b44a7001b array.c: ROM method table for Array class (36 methods)
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 16:30:35 +09:00
Yukihiro "Matz" Matsumoto 96da40605f class.c, string.c: ROM method table for String class
Move String's 46 method definitions from runtime
mrb_define_method_id() calls to a static ROM method table
sorted at init time. mrb_mt_init_rom() sorts the parallel
vals/keys arrays by presym ID and sets the readonly flag.

Expose mt_tbl and related types in internal.h so ROM tables
can be defined in individual source files.

When MRB_NO_PRESYM is defined, falls back to traditional
runtime method registration.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 16:12:56 +09:00
Yukihiro "Matz" Matsumoto 1e0f9b76c3 class.c: add chained method table infrastructure for ROM support
Add next pointer and readonly flag to mt_tbl struct to support
chained ROM method table layers. mt_get() walks the chain,
mt_copy() shares ROM layers, mt_free() and mrb_gc_mark_mt() skip
readonly layers. COW in mrb_define_method_raw() creates a mutable
top layer when the existing table is readonly. mt_flatten() merges
all layers for the rare remove_method case.

No ROM tables exist yet -- all tables have next==NULL and no
readonly flag, so behavior is identical to the previous code.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 15:53:18 +09:00
Yukihiro "Matz" Matsumoto e49479feaa mlc_config.json: ignore iso.org links in markdown-link-check
iso.org blocks automated HTTP requests with 403 Forbidden.
Also update the ISO 30170 URLs to current format in README.md
and CONTRIBUTING.md.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 15:41:55 +09:00
Yukihiro "Matz" Matsumoto 9910444212 etc.c: inline special float values in word boxing rotation encoding
Encode 0.0, -0.0, +Inf, -Inf, and NaN as small sentinel constants
with the float tag pattern, avoiding heap allocation for these common
special values.  All NaN bit patterns are normalized to a single
canonical NaN.  The 5 obscure floats near 2^(-255) whose rotation
encoding would collide with a sentinel are heap-allocated instead.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 15:41:55 +09:00
Yukihiro "Matz" Matsumoto b6148c893f boxing_word.h: lossless float encoding using rotation
Replace lossy 2-bit truncation with rotation-based encoding for
64-bit word boxing with float64. The new scheme uses
rotl64(float_bits - ADDEND, 3) to embed floats inline with full
52-bit mantissa precision. Floats with exponents outside [-255,+256]
(0.0, NaN, Inf, very small/large values) fall back to heap-allocated
RFloat.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 15:41:55 +09:00
Yukihiro "Matz" Matsumoto 4e63489d1a hash.c: add __pat_values() for pattern matching optimization
Add Hash#__pat_values(keys) that returns an array of values if all
keys exist, or false if any key is missing. This replaces per-key
key?() + []() calls (2N hash lookups) with a single method call
(N hash lookups). The compiler generates __pat_values() followed by
array indexing to extract each value for pattern matching.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 15:41:55 +09:00
Yukihiro "Matz" Matsumoto 5f429e151a mruby-compiler: extract gen_pat_keys_ary() helper for hash pattern codegen
Extract the keys-to-array loop (load keys + OP_ARRAY) into
gen_pat_keys_ary() helper. The pattern appeared in both
deconstruct_keys argument and __except argument generation.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 15:41:55 +09:00
Yukihiro "Matz" Matsumoto 8b080a53cd mruby-compiler: extract gen_pat_key() helper for hash pattern codegen
Reduce code duplication by extracting the key-loading pattern
(NODE_SYM check + OP_LOADSYM/codegen) into gen_pat_key() helper.
The pattern appeared 4 times in NODE_PAT_HASH codegen.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 15:41:55 +09:00
Yukihiro "Matz" Matsumoto a60ee2164e mruby-compiler: refactor deconstruct_keys argument in hash pattern
Simplify deconstruct_keys argument logic from 3 branches to 2:
- pass nil when rest pattern is present or no keys (all keys needed)
- pass keys array only for partial match without rest
This avoids building keys array twice when **rest is present.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 15:41:55 +09:00
Yukihiro "Matz" Matsumoto d98d62ee35 hash.c: change __except to take array argument
mrb_get_args(mrb, "*", ...) internally allocates an array when
arguments are on the stack, so passing keys as direct arguments
did not actually avoid allocation. Change __except to take a
single array argument instead, which is simpler and GC-safe.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-18 15:41:54 +09:00
Yukihiro "Matz" Matsumoto 0209e8d6fd Merge pull request #6719 from mruby/dependabot/github_actions/super-linter/super-linter-8.5.0
build(deps): bump super-linter/super-linter from 8.4.0 to 8.5.0
2026-02-17 16:04:01 +09:00
dependabot[bot] f88d8e3edf build(deps): bump super-linter/super-linter from 8.4.0 to 8.5.0
Bumps [super-linter/super-linter](https://github.com/super-linter/super-linter) from 8.4.0 to 8.5.0.
- [Release notes](https://github.com/super-linter/super-linter/releases)
- [Changelog](https://github.com/super-linter/super-linter/blob/main/CHANGELOG.md)
- [Commits](https://github.com/super-linter/super-linter/compare/v8.4.0...v8.5.0)

---
updated-dependencies:
- dependency-name: super-linter/super-linter
  dependency-version: 8.5.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-16 15:58:59 +00:00
Yukihiro "Matz" Matsumoto 488aa8630b mruby-compiler: handle __except with CALL_MAXARGS fallback
When a hash pattern has 15 or more keys, pack them into an array
before calling __except via OP_SEND with CALL_MAXARGS, since the
OP_SEND instruction can only encode up to 14 direct arguments.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-16 18:42:49 +09:00
Yukihiro "Matz" Matsumoto 1b14a3f72a hash.c: add __except method for pattern matching **rest
Add Hash#__except that returns a new hash excluding specified keys,
used by the compiler for **rest capture in hash patterns. Takes keys
as direct arguments to avoid array allocation. The compiler passes
matched key symbols directly on the stack via OP_SEND.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-16 18:16:27 +09:00
Yukihiro "Matz" Matsumoto 9b66ec82c4 mruby-compiler: fix hash pattern matching for CRuby compatibility
Add key existence check using key?() before value access, so that
missing keys correctly fail to match (e.g. {b: 1} no longer matches
{a: nil} pattern). Implement **nil and empty {} exact match via
hash.size == num_keys check. Fix **rest to properly exclude matched
keys using dup + __delete instead of copying the entire hash.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-16 17:33:41 +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 75738a350a mruby-bigint: fix memory leak in mrb_bint_lcm()
mpz_abs() internally allocates via mpz_init_heap(), so
pre-allocating abs_x/abs_y with mpz_init_temp() leaked the
original allocations. let mpz_abs() handle allocation directly.

also use divide-first formula (abs_x/gcd)*abs_y to reduce
intermediate product size, and add bint_norm() for the result.

reported by OSS-Fuzz (clusterfuzz-testcase-6501272051318784).

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-16 16:34:21 +09:00
Yukihiro "Matz" Matsumoto 070bef24ab mruby-numeric-ext: fix integer overflow in Integer#lcm
check for overflow using mrb_int_mul_overflow() in the LCM
computation to avoid undefined behavior when the result exceeds
mrb_int range. raises RangeError instead.

reported by OSS-Fuzz (clusterfuzz-testcase-6501272051318784).

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-16 16:34:20 +09:00
Yukihiro "Matz" Matsumoto 7f6f2a85fc Merge pull request #6718 from eunos-1128/readme/homebrew-conda-installation
Add installation instructions for conda and Homebrew
2026-02-16 16:15:58 +09:00
UENO, M. c9295c4dae Update README.md 2026-02-14 12:44:58 +09:00
UENO, M. ce348d3bd5 Improve mruby installation instructions
Updated installation instructions for mruby to include compilation options.
2026-02-14 12:36:51 +09:00
UENO, M. 6da887a99a Update README.md
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2026-02-14 12:12:54 +09:00
UENO, M. 9ab05a9f3b Update mruby installation instructions in README
Added installation options for Homebrew and Conda.
2026-02-14 12:05:53 +09:00
Yukihiro "Matz" Matsumoto 12bc2cfaa1 mruby-io: reorder struct mrb_io to keep fd at offset 0
move fd, fd2, pid fields before the bitfield flags while keeping
the pointer field last. this preserves the 24-byte struct size
(same as 3.4.0) while restoring fd to offset 0 (same as 3.3.0).

some external gems (e.g. mruby-polarssl) pass struct mrb_io
pointers directly to libraries like mbedtls that expect an int fd
at offset 0. the 3.4.0 reorder moved bitfield flags to offset 0,
causing these gems to read garbage instead of the file descriptor.

fixes #6713

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-14 12:05:20 +09:00
Yukihiro "Matz" Matsumoto cac1c99c6c pre-commit.yml: remove duplicate --color=always argument
The prek-action already passes --color=always internally,
so passing it again via extra-args causes a CLI error.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-14 10:23:34 +09:00
Yukihiro "Matz" Matsumoto 6d04ae695d Merge pull request #6717 from hasumikin/fix/Task-critical-section
Fix mruby-task: wrapping by critical section and setting initial task receiver to top_self
2026-02-14 10:09:43 +09:00
HASUMI Hitoshi 40d6e2e9a4 Update mrbgems/mruby-task/src/task.c
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-13 14:34:34 +09:00
HASUMI Hitoshi ee610cdbb6 Set initial task receiver to top_self for stability
The current implementation of `task_init_context` inheriting a receiver from the parent task is unstable and causes critical faults, especially on microcontrollers.

- It leads to a HardFault on devices like Raspberry Pi Pico 2 by accessing a potentially NULL `mrb->c->ci`.
- Even when `mrb->c->ci` is not NULL, this incomplete context copy causes other memory errors (SEGV).

This patch reverts to the safer, previous behavior, that I implemented in picoruby/picoruby, of always initializing a new task's receiver to `top_self`, ensuring predictable and
robust operation.
The issue was likely masked on POSIX systems due to the unpredictable nature of undefined behavior.
2026-02-13 13:59:48 +09:00
HASUMI Hitoshi cfcd86fd9b Fix mrb_task_run to prevent returning unexpectedly
Old code:

```c
t = q_ready_;

/* No task ready - check if all tasks are done */
if (!t) {
  /* If there are tasks waiting or suspended, idle */
  if (q_waiting_ || q_suspended_) {
    mrb_hal_task_idle_cpu(mrb);
    continue;
```

IRQ possibly happens between `t = q_ready_;` and `if (q_waiting_ || q_suspended_) {` and, for example, a waiting task may move to the ready queue.
As a result, the infinite loop in mrb_task_run unexpectedly breaks in spite of not all the task is dormant.
This patch fixes the issue above by setting the `exitting` condition with a critical section.
2026-02-13 13:34:54 +09:00
Yukihiro "Matz" Matsumoto 0bc0700fa4 gc.c: fix RVALUE_zero initializer warning after gcnext removal
the second NULL in the initializer was for the removed gcnext field,
causing "makes integer from pointer" warning on the tt bitfield.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-12 13:39:38 +09:00
Yukihiro "Matz" Matsumoto 31fea1709f gc.c: replace gcnext gray linked list with fixed-size gray stack
remove per-object gcnext pointer from MRB_OBJECT_HEADER, saving one
word (8 bytes on 64-bit) per object slot. the gray list for tri-color
marking is replaced by a fixed-size stack (MRB_GRAY_STACK_SIZE=1024)
in mrb_gc. when the stack overflows, a linear heap rescan recovers
gray objects.

object slot size: 48 -> 40 bytes (16.7% reduction on 64-bit).
benchmarks show up to 12% RSS reduction on object-heavy workloads
with neutral performance impact.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-12 13:38:21 +09:00
Yukihiro "Matz" Matsumoto 5d3aab8b22 mruby-time: fix integer overflow in timegm() year calculation
OUTINT macro checked ayear > INT_MAX, but timegm() later computes
tm_year + TM_YEAR_BASE (1900), which overflows when tm_year is near
INT_MAX. Tighten the upper bound to INT_MAX - TM_YEAR_BASE.

Found by ClusterFuzz.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-11 23:21:05 +09:00
Yukihiro "Matz" Matsumoto 5970e3508e class.c: skip keyword argument hash duplication in mrb_get_args()
Same reasoning as the vm.c change - the keyword hash arriving at
C functions via mrb_get_args() is always freshly constructed at the
call site, so duplication is unnecessary.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-10 23:01:11 +09:00
Yukihiro "Matz" Matsumoto 914d64ef0c vm.c: skip keyword argument hash duplication in OP_ENTER
The keyword argument hash passed to a method is always freshly
constructed at the call site - either by hash_new_from_regs() in
OP_SEND for inline keyword pairs, or by OP_HASH/OP_HASHCAT for
compiler-generated keyword arguments (including the **h splat case
which creates OP_HASH(0)+OP_HASHCAT). Since no caller retains a
reference to this hash, the mrb_hash_dup() was redundant.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-10 23:01:03 +09:00
Yukihiro "Matz" Matsumoto c06a11912c mruby-bin-mirb: fix uninitialized editor struct causing bintest failures
Zero-initialize the mirb_editor struct to prevent highlight.enabled
from containing garbage values when stdin is not a tty (e.g. in
bintest). Without this, ANSI color codes could be emitted in
non-interactive mode, breaking output string matching in tests.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-10 15:14:53 +09:00
Yukihiro "Matz" Matsumoto b3b8c0176f load.c: fix off-by-one in bounds check for symbol names
Same issue as the pool string fix: the bounds check for
symbol names only validated snl bytes, but the binary
format includes a null terminator. The source pointer
advances by snl+1, so the check must account for it.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-10 14:56:25 +09:00
Yukihiro "Matz" Matsumoto f80f1cd27d load.c: fix off-by-one in bounds check for pool strings
The bounds check for IREP_TT_STR pool data only validated
pool_data_len bytes, but the binary format includes a null
terminator after the string content. Both memcpy and the
source pointer advance by pool_data_len+1, so the check
must account for the extra byte.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-10 14:56:12 +09:00
Yukihiro "Matz" Matsumoto 564995a91a update documentation and Makefile for prek migration
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-10 14:45:22 +09:00
Yukihiro "Matz" Matsumoto 638a18dfe7 replace pre-commit with prek
prek is a faster, Rust-based drop-in replacement for pre-commit.
It reads the same .pre-commit-config.yaml with no changes needed.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-10 11:14:53 +09:00
Yukihiro "Matz" Matsumoto 4617263030 mruby-compiler: fix JMPNOT-to-MATCHERR rewriting in pattern match codegen
The MATCHERR optimization replaced JMPNOT (BS, 4 bytes) with
MATCHERR (B, 2 bytes) and rewound s->pc by 2. When pattern
alternation (e.g. a|B) dispatched a success jump to s->pc before
the optimization, the rewind shifted subsequent instructions and
the jump landed in the middle of the next instruction, causing
out-of-bounds access at runtime.

Replace JMPNOT in-place with MATCHERR+NOP+NOP to keep the same
4-byte size, so s->pc does not change and jump targets stay valid.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-10 11:12:27 +09:00
Yukihiro "Matz" Matsumoto 6afff1c3eb string.c: fix integer overflow in str_check_length()
Reject MRB_INT_MAX length strings to prevent signed integer overflow
when adding 1 for the null terminator in str_init_normal_capa() and
resize_capa().

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-10 11:12:27 +09:00
Yukihiro "Matz" Matsumoto b287c12e48 mruby-compiler: raise error for pin operator with undefined variable
CRuby raises SyntaxError for `^a` in pattern matching when `a` is
not a local variable. Previously mruby silently generated an
unconditional fail jump, which also led to bytecode corruption
when combined with alternation patterns.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-10 11:12:27 +09:00