Commit Graph

17997 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 2f152823f3 mruby-bin-mirb: add tab completion support
implements context-aware tab completion for mirb supporting all readline
variants (GNU readline, libedit, linenoise) with graceful degradation
when no readline library is available.

completion features:
- method names on objects (e.g., "hello".re<Tab> completes to reverse, replace)
- local variables from compiler context
- global variables via Ruby introspection
- constants and class names
- Ruby keywords

architecture:
- core completion engine is library-agnostic
- thin adapters for readline/libedit and linenoise
- context detection based on cursor position analysis
- safe receiver evaluation with exception handling
- proper word break characters so "String.new" works correctly

implementation adds:
- mirb_completion.h: interface definitions and data structures
- mirb_completion.c: complete implementation (~670 lines)
- mirb.c: integration with setup/cleanup calls

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-11 18:09:05 +09:00
Yukihiro "Matz" Matsumoto 0aafb83374 mruby-bin-mirb: add MRUBY_MIRB_READLINE to control readline library selection
addresses #6626 where users building portable binaries need explicit control
over readline detection instead of auto-detection.

MRUBY_MIRB_READLINE values:
  auto (default) - auto-detect: try readline, then edit, then linenoise
  readline, gnu  - force GNU readline only
  edit, libedit  - force libedit only
  linenoise      - force linenoise only
  none, off, false, disabled - use plain input mode (no readline)

close #6626

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-11 18:09:05 +09:00
Yukihiro "Matz" Matsumoto 9aa6f28eab mirb: show method context for errors from previous code
runtime errors now distinguish between:
- errors in current input: show relative line number
- errors from previously defined methods: show method context

examples:
1> a.foo
line 1: undefined method 'a' for Object (NoMethodError)

1> def foo
2*   bar
3* end
1> foo
(mirb):in foo: undefined method 'bar' for Object (NoMethodError)

this provides better context since method name is more useful
than line number for errors in previously defined code

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-11 18:09:05 +09:00
Yukihiro "Matz" Matsumoto ac39b7d8ad mruby-bin-mirb: enhanced syntax error display
syntax errors now show:
- line:column format with relative line numbers (matching prompt)
- source line from user input
- caret indicator pointing to error position

example:
1> x = @@@
line 1:6: syntax error, unexpected invalid token
  x = @@@
        ^

multi-line example:
1> class Foo
2*   def bar
3*     x = @@@
line 3:6: syntax error, unexpected invalid token
      x = @@@
        ^

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-11 18:09:05 +09:00
Yukihiro "Matz" Matsumoto 5a3f0e2e0b mruby-bin-mirb: add line numbers to multi-line prompts
add minimal line number decoration to prompts to help track position
within multi-line code blocks. format is 'N>' for initial line and
'N*' for continuation lines. line counter resets after each complete
evaluation for clarity and minimal visual noise.

example:
1> def foo
2*   x = 1
3* end
 => :foo
1> 1 + 1
 => 2

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-11 18:09:05 +09:00
Yukihiro "Matz" Matsumoto 2f68c9ebae Merge pull request #6681 from khasinski/cosmopolitan-build-config 2025-12-10 12:30:24 +09:00
Chris Hasiński c10a9ec571 Add Cosmopolitan Libc build configuration
Add build configuration for Cosmopolitan Libc, enabling mruby to be
compiled as an "Actually Portable Executable" (APE) that runs natively
on multiple platforms from a single binary.

Supported platforms:
- Linux (x86_64, ARM64)
- macOS (x86_64, ARM64)
- Windows (x86_64)
- FreeBSD (x86_64)
- OpenBSD (x86_64)
- NetBSD (x86_64)

Included binaries:
- mruby.com   - mruby interpreter
- mrbc.com    - bytecode compiler
- mirb.com    - interactive Ruby shell
- mrdb.com    - debugger
- mruby-strip.com - debug info stripper

Usage:
  COSMO_ROOT=~/cosmo rake MRUBY_CONFIG=cosmopolitan

The cosmocc toolchain can be downloaded from https://cosmo.zip/pub/cosmocc/
2025-12-09 19:01:31 +01:00
Yukihiro "Matz" Matsumoto 3b476621fe Merge pull request #6680 from mruby/dependabot/bundler/yard-0.9.38 2025-12-09 10:34:22 +09:00
dependabot[bot] 5fb11dee54 build(deps): bump yard from 0.9.37 to 0.9.38
Bumps [yard](https://github.com/lsegal/yard) from 0.9.37 to 0.9.38.
- [Release notes](https://github.com/lsegal/yard/releases)
- [Changelog](https://github.com/lsegal/yard/blob/main/CHANGELOG.md)
- [Commits](https://github.com/lsegal/yard/compare/v0.9.37...v0.9.38)

---
updated-dependencies:
- dependency-name: yard
  dependency-version: 0.9.38
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-08 14:07:48 +00:00
Yukihiro "Matz" Matsumoto f1fc5c7057 Merge pull request #6593 from jbampton/readme-upgrade 2025-12-08 10:07:35 +09:00
Yukihiro "Matz" Matsumoto 2341b7ebf5 Merge pull request #6679 from jbampton/pre-commit-autoupdate 2025-12-08 10:06:02 +09:00
Yukihiro "Matz" Matsumoto 00cf74295e Merge pull request #6678 from jbampton/separate-gha-workflows 2025-12-08 10:05:48 +09:00
John Bampton dbca200bc7 Fix markdown-link-check ignore 2 URL patterns 2025-12-07 11:00:17 +10:00
John Bampton a2523c6745 pre-commit autoupdate; update node and prettier 2025-12-07 10:19:04 +10:00
John Bampton 0838ef7abd README: Add Contributors Avatars, Star History, Table of Contents
https://www.star-history.com/

https://contrib.rocks

Added some more 💄 to the README which showcases some great statistics.

Both tools are popular and a lot of projects use them.
2025-12-07 09:55:07 +10:00
John Bampton 9835bf8473 Put ls-lint and pre-commit in separate workflow files
Standardizes all workflows into separate files.

Minor clean up of workflow name and add a docs link
2025-12-07 09:50:27 +10:00
Yukihiro "Matz" Matsumoto c136a476ee Merge pull request #6677 from jbampton/pre-commit-color-always 2025-12-06 21:56:26 +09:00
John Bampton 58264bedee gha: run pre-commit with --color=always
Minor enhancement for the GHA CI.

refs https://github.com/apache/cloudstack/pull/11977
2025-12-05 23:21:58 +10:00
Yukihiro "Matz" Matsumoto 4dc234c7a2 AUTHORS: update entries [ci skip] 2025-12-02 23:25:09 +09:00
Yukihiro "Matz" Matsumoto 127ef7f406 TODO.md: update profiler/benchmarking entry
benchmarking tools (mruby-benchmark) have been implemented.
update entry to focus on remaining profiler features:
method call tracing, stack profiling, and detailed memory analysis.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-02 23:12:37 +09:00
Yukihiro "Matz" Matsumoto 2336534552 mruby-benchmark: add comprehensive test suite
add 24 test cases covering all benchmark functionality:
- Benchmark.measure and Benchmark.realtime
- Benchmark::Tms class and its methods (total, to_s, format)
- Benchmark.bm for formatted comparison reports
- Benchmark::Report class
- memory tracking with ObjectSpace integration
- consistency and realistic usage scenarios

suppress output during tests by temporarily setting $stdout to nil
for tests that call Benchmark.bm or Report#report to avoid printing
garbage during test execution.

all tests pass successfully.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-02 23:12:37 +09:00
Yukihiro "Matz" Matsumoto ef3a37b9b7 limitation.md: document current pattern matching limitations; close #6674
add pattern matching section to limitations.md clarifying that only
rightward assignment (expr => var) is currently supported, while
case/in syntax and other pattern types are not yet implemented.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-02 23:12:37 +09:00
Yukihiro "Matz" Matsumoto 2494a712dd vm.c: extract alias resolution logic to MRB_PROC_RESOLVE_ALIAS macro
reduce code duplication by introducing MRB_PROC_RESOLVE_ALIAS macro
to handle alias proc resolution in a consistent way across 5 locations.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-02 23:12:36 +09:00
Yukihiro "Matz" Matsumoto 13e2ce4249 mruby-benchmark: fix implementation for mruby environment
fix implementation to work correctly in mruby:
- use String#% instead of sprintf for formatting
- use $stdout directly for output instead of bare print/puts
- add nil check for $stdout to handle test environments
- use Object.const_defined? instead of defined? keyword
- create new Tms instance with label instead of instance_variable_set
- add dependencies: mruby-sprintf and mruby-io

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-02 23:12:36 +09:00
Yukihiro "Matz" Matsumoto 2f40f3d170 mruby-benchmark: add benchmarking gem
add initial implementation of mruby-benchmark gem providing:
- Benchmark.measure for detailed timing with Tms results
- Benchmark.realtime for simple wall-clock measurements
- Benchmark.bm for formatted comparison reports
- optional memory tracking via ObjectSpace integration

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-02 23:12:36 +09:00
Yukihiro "Matz" Matsumoto ea221a5562 TODO.md: add performance, tooling, and embedded features
add future work items:
- method inline caching improvements
- built-in profiler/benchmarking tools
- improved REPL (mirb) features
- configurable memory pools
- suspend/resume VM state
- CMake build support

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-02 23:12:36 +09:00
Yukihiro "Matz" Matsumoto ee3b7e0faf TODO.md: add pattern matching to future work
add full pattern matching implementation (case/in syntax, array/hash
patterns, guards, etc.) to the todo list for after mruby 3.4.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-02 23:12:36 +09:00
Yukihiro "Matz" Matsumoto 1fcf93e18e TODO.md: update version to 3.4
update "After mruby 3.1" to "After mruby 3.4" to reflect the current
version.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-02 23:12:36 +09:00
Yukihiro "Matz" Matsumoto e144962590 TODO.md: remove completed variable sized AST node item
variable sized AST node has been implemented, so remove it from the
todo list.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-02 23:12:36 +09:00
Yukihiro "Matz" Matsumoto 5af58bd7cc Merge pull request #6676 from mruby/dependabot/github_actions/super-linter/super-linter-8.3.0 2025-12-02 23:12:18 +09:00
dependabot[bot] b7b61fdbe5 build(deps): bump super-linter/super-linter from 8.2.1 to 8.3.0
Bumps [super-linter/super-linter](https://github.com/super-linter/super-linter) from 8.2.1 to 8.3.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.2.1...v8.3.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-02 14:01:29 +00:00
Yukihiro "Matz" Matsumoto 40644ad96c Merge pull request #6589 from jbampton/add-no-zip-hook 2025-12-02 08:34:39 +09:00
Yukihiro "Matz" Matsumoto ffd3252dd0 proc.c: fix Method#== for aliased methods and comparison bug; fix #6668
follow alias chains in mrb_proc_eql() to compare underlying procs,
making Method#== return true for aliased methods as in CRuby.

also fix typo where p1 was checked instead of p2 in CFUNC comparison.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-01 18:20:45 +09:00
Yukihiro "Matz" Matsumoto 29b3405283 bigint.c: handle in-place operation in mpz_mod_2exp()
when mpz_mod_2exp() is called with z == x (in-place operation), the
function was calling mpz_clear(ctx, z) which freed x's memory, then
attempting to access x->p[i] - reading freed memory. this caused
Barrett reduction to produce incorrect results in modular
exponentiation.

the fix checks if z == x and handles in-place modification by
adjusting the size and masking directly, without clearing. this is
similar to the memory leak fix for pool→heap transitions.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-01 18:20:44 +09:00
Yukihiro "Matz" Matsumoto a5e25393b8 mruby-bigint: fix memory leak in mpz_mod_2exp by clearing before reinit
mpz_mod_2exp() was reinitializing its output parameter without clearing
existing heap memory. When the parameter contained heap allocations from
pool->heap transitions in mpz_mul()->mpz_realloc(), reinitializing would
overwrite the pointer and leak memory. Added mpz_clear() before each
mpz_init() or mpz_init_heap() call to properly free existing heap memory.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-01 18:20:44 +09:00
Yukihiro "Matz" Matsumoto 5ed0cd4ecb bigint.c: increase karatsuba scratch allocation safety margin
the previous fixed safety margin of 8 limbs was insufficient for certain
edge cases involving deep recursion levels in karatsuba multiplication,
as discovered by oss-fuzz. changed to proportional margin (~12.5% plus
fixed overhead of 16) that scales with input size.

this prevents potential buffer overruns in deeply nested karatsuba
multiplications while maintaining efficiency for typical cases.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-01 18:20:44 +09:00
Yukihiro "Matz" Matsumoto 857de45036 mruby-time: normalize microseconds before converting to nanoseconds
when converting microseconds to nanoseconds, multiplying very large
usec values by 1000 can cause signed integer overflow. for example,
Time.at(0, 9999999999990768) would trigger ASAN runtime error.

fixed by normalizing microseconds >= 1000000 (or <= -1000000) to
seconds before the multiplication, preventing overflow while maintaining
correct time representation. this normalization converts excess
microseconds to seconds, leaving only the fractional part for
multiplication.

applied fix to both time_alloc() and mrb_time_at() functions.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-01 18:20:44 +09:00
Yukihiro "Matz" Matsumoto 78f9b5c52f string.c: simplify memcmp guard with ternary operator
refactored the NULL pointer guard in mrb_str_cmp() from an if-else
block to a more concise ternary operator. functionality remains the
same: avoids undefined behavior by skipping memcmp() when comparing
zero-length strings.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-01 18:20:43 +09:00
Yukihiro "Matz" Matsumoto 6122fdfee9 string.c: guard memcmp() call to avoid undefined behavior with NULL pointers
passing NULL pointers to memcmp() is undefined behavior per C standard,
even when size is 0. memcmp() is declared with nonnull attributes,
and ASAN can detect this violation.

in mrb_str_cmp(), when comparing two empty strings or when the minimum
length is 0, we now skip the memcmp() call and directly set retval to 0.
this avoids the undefined behavior while maintaining correct comparison
semantics.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-01 18:20:43 +09:00
Yukihiro "Matz" Matsumoto db3d754261 mruby-array-ext: use mrb_ensure() instead of direct throw.h calls
refactored five functions to use mrb_ensure() instead of MRB_TRY/MRB_CATCH:
- ary_subtract_internal(): body/ensure pattern for set cleanup
- ary_union_internal(): body/ensure pattern for set cleanup
- ary_intersection_internal(): body/ensure pattern for set cleanup
- ary_intersect_p(): body/ensure pattern for set cleanup
- ary_uniq_bang(): body/ensure pattern for set cleanup

each function now uses a context struct containing set pointer and other
necessary data, with separate body and ensure functions that guarantee
cleanup on exception. this allows array-ext to compile as pure C without
requiring C++ compiler when enable_cxx_exception is set.

added mruby-error dependency to access mrb_ensure(). changed include
from throw.h to error.h. fix #6667.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-01 18:20:42 +09:00
Yukihiro "Matz" Matsumoto 61437126cd Merge pull request #6673 from jbampton/fix-links-clean-up 2025-11-29 12:40:15 +09:00
John Bampton 8558ad40ec Adjust broken license links; clean up Markdown 2025-11-29 01:46:54 +10:00
John Bampton 8623215c69 Add pre-commit hook check-zip-file-is-not-committed
Zip files should not be allowed in the repository as they are hard to track and have security implications.
2025-11-28 23:58:42 +10:00
Yukihiro "Matz" Matsumoto 209ae86e77 Merge pull request #6670 from dearblue/vm 2025-11-28 21:50:55 +09:00
Yukihiro "Matz" Matsumoto 271428002a Merge pull request #6599 from jbampton/manual-hooks 2025-11-28 14:28:11 +09:00
John Bampton 88bc3c130f Merge branch 'master' into manual-hooks 2025-11-28 05:43:37 +10:00
Yukihiro "Matz" Matsumoto 9e95646f76 Merge pull request #6669 from mruby/dependabot/github_actions/actions/checkout-6 2025-11-24 23:56:13 +09:00
dearblue 50ecc1fd2c Arranging VM dispatch macros
Consolidate duplicate common code.
2025-11-23 14:45:22 +09:00
dependabot[bot] f05a284cab build(deps): bump actions/checkout from 5 to 6
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-21 14:01:22 +00:00
Yukihiro "Matz" Matsumoto 82180d040b codegen.c: fix regexp literal with encoding to pass nil for options; fix #6666
restore correct argument passing for Regexp.compile when encoding is
present but flags are not. regexp literals like /a/n should compile to
Regexp.compile("a", nil, "n") with 3 arguments, not
Regexp.compile("a", "n") with 2 arguments.

the bug was introduced during refactoring when the nil-insertion logic
for the options parameter was accidentally omitted. now properly inserts
OP_LOADNIL when flags are absent but encoding is present.

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-20 14:08:21 +09:00