Commit Graph

18614 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 78658d67e1 vm.c: extract OP_GETIDX, OP_GETIDX0, OP_SETIDX, OP_DIV into static helpers
Phase 2 of opcode handler extraction. these opcodes use
L_SEND_SYM/L_SENDB_SYM fallback for generic method dispatch when
the fast path (Array/Hash/String/Integer/Float) does not apply.
add VM_SEND_SYM and VM_SENDB_SYM return codes. move TYPES2 macro
to file scope for use by vm_op_div.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:22 +09:00
Yukihiro "Matz" Matsumoto 95bfa86160 vm.c: extract OP_ENTER, OP_ARGARY, OP_BLKPUSH into static helpers
extract the three largest self-contained opcode handlers from the
mrb_vm_exec() dispatch loop into static functions. add
__attribute__((flatten)) to mrb_vm_exec() so that the compiler
inlines them back, producing identical binary output while keeping
the source clean.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:22 +09:00
Yukihiro "Matz" Matsumoto 5148062516 mruby-env: add README.md
Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:21 +09:00
Yukihiro "Matz" Matsumoto 3272955bf1 mruby-env: add ENV object for environment variable access
ENV is a plain Object with singleton methods and Enumerable,
matching CRuby's behavior. C methods wrap getenv/setenv/unsetenv
with platform support for POSIX, macOS, and Windows.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:21 +09:00
Yukihiro "Matz" Matsumoto 3d53864991 fp_uscale.c: add shortest representation for Float#to_s
Use uscale-based shortest() to compute the minimal decimal string
that uniquely identifies each double. This guarantees perfect
round-trip (parse(to_s(x)) == x) while keeping output concise
(e.g. 0.1 prints as "0.1", not "0.10000000000000001").

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:21 +09:00
Yukihiro "Matz" Matsumoto 9ff1aa9d55 fp_uscale.c: replace fmt_fp.c and readfloat.c with uscale algorithm
Replace separate float formatting (fmt_fp.c) and parsing (readfloat.c)
implementations with a unified fp_uscale.c using 128-bit unrounded
scaling. Both mrb_format_float() and mrb_read_float() now share a
single pow10 table and uscale() primitive for decimal/binary conversion.

This fixes subnormal parsing accuracy (old code returned 0.0 for the
smallest subnormals) and corrects %.2f rounding for values like
12345.125. Table size grows from ~5KB to ~11KB in .rodata.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:21 +09:00
Yukihiro "Matz" Matsumoto 50bc8c6136 vm.c: replace constant cache generation counter with direct invalidation
Remove the per-entry generation field and per-state generation
counter. Invalidation now clears entries directly, removing one
comparison from every OP_GETCONST hot path.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:21 +09:00
Yukihiro "Matz" Matsumoto d0d2c3072c class.c: use 2-way set-associative method cache
Right-shift class pointer by 4 before hashing to remove
always-zero alignment bits, improving hash distribution.
Organize 256 cache entries as 128 sets x 2 ways to reduce
conflict misses when multiple methods share a hash bucket.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:21 +09:00
Yukihiro "Matz" Matsumoto 7675601b92 vm.c: add constant lookup cache with generation counter
Cache OP_GETCONST results in a global direct-mapped cache (64 entries)
keyed by (irep, sym). Invalidate all entries via a generation counter
bumped on mrb_const_set(), mrb_const_remove(), and
mrb_define_const_id(). ~10% faster on constant-heavy code; disabled
with MRB_NO_CONST_CACHE.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:20 +09:00
Yukihiro "Matz" Matsumoto b2d935b6d3 Merge pull request #6803 from saeki-mototsune/fix_psp_build_config 2026-04-23 19:24:10 +09:00
Yukihiro "Matz" Matsumoto 36dd668f73 Merge pull request #6799 from dearblue/mrb_state 2026-04-23 19:20:43 +09:00
Yukihiro "Matz" Matsumoto 8996152365 Merge pull request #6786 from dearblue/sysfail 2026-04-23 19:15:38 +09:00
Yukihiro "Matz" Matsumoto 7365ed526b Merge pull request #6785 from khasinski/cfunc-proc-aspec 2026-04-23 19:11:35 +09:00
Yukihiro "Matz" Matsumoto 7a14bad5ea Merge pull request #6777 from dearblue/array-combination.4 2026-04-23 18:59:05 +09:00
Yukihiro "Matz" Matsumoto bfc1f37b91 Merge pull request #6775 from dearblue/array-combination.2 2026-04-23 18:56:46 +09:00
Yukihiro "Matz" Matsumoto 7eab8302b0 Merge pull request #6774 from dearblue/array-combination.1 2026-04-23 18:49:28 +09:00
Yukihiro "Matz" Matsumoto 05f7236586 Merge pull request #6805 from mruby/dependabot/github_actions/github-actions-dependencies-f3e34333ea 2026-04-23 16:01:46 +09:00
Yukihiro "Matz" Matsumoto d359182b47 Merge pull request #6804 from mruby/dependabot/bundler/bundler-dependencies-39953ac9c0 2026-04-23 15:52:01 +09:00
dependabot[bot] ccd661b429 build(deps): bump github/codeql-action
Bumps the github-actions-dependencies group with 1 update: [github/codeql-action](https://github.com/github/codeql-action).


Updates `github/codeql-action` from 4.35.1 to 4.35.2
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v4.35.1...v4.35.2)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 4.35.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-actions-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-22 14:54:14 +00:00
dependabot[bot] aea5d584f0 build(deps): bump rake in the bundler-dependencies group
Bumps the bundler-dependencies group with 1 update: [rake](https://github.com/ruby/rake).


Updates `rake` from 13.3.1 to 13.4.1
- [Release notes](https://github.com/ruby/rake/releases)
- [Changelog](https://github.com/ruby/rake/blob/master/History.rdoc)
- [Commits](https://github.com/ruby/rake/compare/v13.3.1...v13.4.1)

---
updated-dependencies:
- dependency-name: rake
  dependency-version: 13.4.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: bundler-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-21 14:53:28 +00:00
SaekiMototsune 08b6d2ecd0 Disable some gems on build_config for playstationportable 2026-04-21 18:50:14 +09:00
Yukihiro "Matz" Matsumoto f469e7567a Merge pull request #6801 from mruby/dependabot/github_actions/github-actions-dependencies-9527efa922 2026-04-21 08:34:06 +09:00
dependabot[bot] 86940418c7 build(deps): bump the github-actions-dependencies group with 2 updates
Bumps the github-actions-dependencies group with 2 updates: [actions/cache](https://github.com/actions/cache) and [j178/prek-action](https://github.com/j178/prek-action).


Updates `actions/cache` from 5.0.4 to 5.0.5
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/668228422ae6a00e4ad889ee87cd7109ec5666a7...27d5ce7f107fe9357f9df03efb73ab90386fccae)

Updates `j178/prek-action` from 2.0.1 to 2.0.2
- [Release notes](https://github.com/j178/prek-action/releases)
- [Commits](https://github.com/j178/prek-action/compare/53276d8b0d10f8b6672aa85b4588c6921d0370cc...cbc2f23eb5539cf20d82d1aabd0d0ecbcc56f4e3)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-version: 5.0.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-actions-dependencies
- dependency-name: j178/prek-action
  dependency-version: 2.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-actions-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-20 17:20:54 +00:00
Yukihiro "Matz" Matsumoto 7546d53a3a Merge pull request #6800 from mruby/stable 2026-04-20 18:54:55 +09:00
mimaki 831da26b90 Update version and release date. (mruby 4.0.0 (2026-04-20)) 4.0.0 2026-04-20 17:43:06 +09:00
dearblue 0d00743a5f Define the typedef for mrb_state earlier
This improves consistency with other definitions.
2026-04-19 21:17:18 +09:00
Yukihiro "Matz" Matsumoto 0112fe6659 Merge pull request #6796 from mruby/dependabot/pre_commit/pre-commit-hooks-be5b5e25f5 2026-04-18 08:29:15 +09:00
Yukihiro "Matz" Matsumoto 605ef4919b Merge pull request #6797 from mruby/dependabot/github_actions/github-actions-dependencies-fd00acb19b 2026-04-18 08:28:56 +09:00
Yukihiro "Matz" Matsumoto e1ed206cae Merge pull request #6798 from mruby/dependabot/bundler/yard-0.9.42 2026-04-18 08:28:31 +09:00
Yukihiro "Matz" Matsumoto 82b91d15c5 Merge pull request #6794 from mattn/fix/readfloat-18-digits 2026-04-18 08:27:58 +09:00
dependabot[bot] f80f825bcf build(deps): bump yard from 0.9.38 to 0.9.42
Bumps [yard](https://yardoc.org) from 0.9.38 to 0.9.42.

---
updated-dependencies:
- dependency-name: yard
  dependency-version: 0.9.42
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-17 22:33:28 +00:00
dependabot[bot] eb51c63196 build(deps): bump github/codeql-action
Bumps the github-actions-dependencies group with 1 update: [github/codeql-action](https://github.com/github/codeql-action).


Updates `github/codeql-action` from 4 to 4.35.1
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v4...v4.35.1)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 4.35.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-actions-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-17 14:53:59 +00:00
dependabot[bot] c2145c8642 build(deps): bump https://github.com/rubocop/rubocop
Bumps the pre-commit-hooks group with 1 update: [https://github.com/rubocop/rubocop](https://github.com/rubocop/rubocop).


Updates `https://github.com/rubocop/rubocop` from v1.86.0 to 1.86.1
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.86.0...v1.86.1)

---
updated-dependencies:
- dependency-name: https://github.com/rubocop/rubocop
  dependency-version: 1.86.1
  dependency-type: direct:production
  dependency-group: pre-commit-hooks
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-16 14:57:37 +00:00
Yasuhiro Matsumoto b82f1c2ec0 readfloat.c: keep one extra fraction digit (17 -> 18)
18 decimal digits still fit in uint64_t (max ~1.8e19), so we can hold
one more digit of precision without overflow risk.
2026-04-16 17:13:17 +09:00
Yukihiro "Matz" Matsumoto a6a92bf95b Merge pull request #6793 from mattn/fix/readfloat-correctly-rounded 2026-04-16 17:09:10 +09:00
Yasuhiro Matsumoto 10c9e83128 readfloat.c: correctly round fraction via division by exact 10^n
The previous code computed `frac_part * pow10_negative[n]`, where
pow10_negative[n] is already a rounded approximation of 10^-n (since
10^-n is not exactly representable in binary). The multiplication then
adds another rounding step, leaving up to ~1 ulp of error.

Dividing `frac_part` by `pow10_positive[n]` is exact for n <= 22 (the
range where 10^n fits exactly in a double), so the division is the
only rounding and the result is correctly rounded. For example,
"0.3".to_f now matches the 0.3 literal's bit pattern (and libc strtod).
2026-04-16 14:47:14 +09:00
Yukihiro "Matz" Matsumoto 2f5a24ed9b Merge pull request #6792 from mruby/fix/host-cxx-build-dir 2026-04-15 15:34:09 +09:00
Yukihiro "Matz" Matsumoto 984f23a94e Merge pull request #6788 from mruby/dependabot/github_actions/github-actions-dependencies-d2d9db5a03 2026-04-15 09:49:36 +09:00
Yukihiro "Matz" Matsumoto 2575735152 Merge pull request #6791 from mruby/fix/bigint-cxx-compat 2026-04-15 09:33:59 +09:00
Yukihiro "Matz" Matsumoto eb87d59941 Merge pull request #6790 from mruby/fix/mrb-mt-entry-cxx-compat 2026-04-15 09:33:23 +09:00
Yukihiro "Matz" Matsumoto 8b44a52176 host-cxx: use distinct build directory from host-debug
build_config/host-cxx.rb defaulted to MRuby::Build.new (no name),
which is equivalent to MRuby::Build.new('host'), so it shared
build/host/ with build_config/host-debug.rb.

The two configs produce ABI-incompatible object files (C linkage
vs. C++-mangled).  Switching between configs without a clean step
silently mixes stale objects, leading to confusing undefined
reference errors at link time.

Name the C++ build 'host-cxx' so it gets its own build/host-cxx/
directory.  No external paths reference build/host/ in a way that
this change would break.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-15 09:30:33 +09:00
Yukihiro "Matz" Matsumoto 617a55b775 mruby-bigint: avoid C99 compound literal in MPZ_CTX_INIT
MPZ_CTX_INIT used a compound literal with designated initializers:

  mpz_ctx_t ctx##_struct = ((mpz_ctx_t){.mrb = ..., .pool = ...});

Both features are C99-only, and are not accepted by legacy C++
compilers (notably gcc 4.x) when mruby is pulled into a C++
translation unit via the -cxx.cxx wrapper.

Replace with plain member assignment so the macro expands to code
that is valid under C89/C++98 as well.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-15 09:01:19 +09:00
Yukihiro "Matz" Matsumoto a33ccd67b1 class.h: avoid C99 designated initializers in MRB_MT_ENTRY
Older C++ compilers (notably gcc 4.x) do not support C99 struct field
designators (.func = ...) even as an extension, which blocks building
mruby when it is included from a C++ translation unit under such
toolchains.

Reorder union mrb_mt_ptr so that mrb_func_t is the first member, and
switch MRB_MT_ENTRY to positional aggregate initialization.  Both are
compatible with pre-C99 / pre-C++20 compilers.

Fixes #6789

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-15 07:31:11 +09:00
dependabot[bot] c43eba8979 build(deps): bump softprops/action-gh-release
Bumps the github-actions-dependencies group with 1 update: [softprops/action-gh-release](https://github.com/softprops/action-gh-release).


Updates `softprops/action-gh-release` from 2 to 2.6.1
- [Release notes](https://github.com/softprops/action-gh-release/releases)
- [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md)
- [Commits](https://github.com/softprops/action-gh-release/compare/v2...v3)

---
updated-dependencies:
- dependency-name: softprops/action-gh-release
  dependency-version: 2.6.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-actions-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-13 16:11:02 +00:00
dearblue 6c06b4cd9d Early conversion of mesg to a string object in mrb_sys_fail()
`mrb_class_get_id()` may call the `#const_missing` method.
Therefore, if the `mesg` string originates from a string object, it may reference an invalid address.

And since `errno` might also change during the call to `#const_missing`, save this as well beforehand.

Also, while `mrb_class_defined_id()` does not currently call the `#const_defined?` method, it is unclear whether this will remain the case in the future.
2026-04-13 23:26:15 +09:00
Chris Hasiński a6283dbdf3 Clear existing aspec bits before setting new ones in mrb_proc_set_cfunc_aspec 2026-04-13 13:40:35 +02:00
Chris Hasiński 55f0228bf8 Store compressed aspec on cfunc RProc for correct arity/parameters
Compress the 24-bit aspec into 13 free flag bits on RProc (bits 0-6
and 14-19) when wrapping cfunc methods. Field widths: req/opt 3 bits
(max 7), post/key 2 bits (max 3), rest/kdict/block 1 bit each. Values
exceeding the compressed range are clamped and rest is forced to 1.

This enables Proc#arity and Proc#parameters to return correct results
for cfunc-backed Procs (e.g. from Method#to_proc) with zero memory
overhead -- no struct change needed.

Closes #6764
2026-04-13 13:11:27 +02:00
mimaki 65eb1df5a3 Update version to 4.0.0RC4. 4.0.0-rc4 2026-04-13 18:54:26 +09:00
mimaki 3b483db61d Merge branch 'master' into stable 2026-04-13 18:51:16 +09:00
Yukihiro "Matz" Matsumoto d65f7a9c5a Merge pull request #6784 from mruby/fix/news-security-updates 2026-04-13 09:01:38 +09:00