added parentheses to to_enum call where the return value is used,
explicitly specifying :each for readability.
Co-authored-by: Claude <noreply@anthropic.com>
added parentheses to to_enum call where the return value is used,
explicitly specifying :each for readability.
Co-authored-by: Claude <noreply@anthropic.com>
added parentheses to all `to_enum` and `super` calls where the return
value is used (returned, assigned, or passed to another method). this
makes the code style consistent with the guideline that method calls
should use parentheses when their return values are consumed.
changes:
- return to_enum :symbol -> return to_enum(:symbol)
- return to_enum :symbol, arg -> return to_enum(:symbol, arg)
- super message, name -> super(message, name)
affected files: 10error.rb, array.rb, enum.rb, hash.rb, kernel.rb,
numeric.rb, range.rb
Co-authored-by: Claude <noreply@anthropic.com>
fixed a bug where tab completion on complex expressions like "d.new(1).a"
would corrupt local variables, causing them to become nil.
the root cause was that evaluating complex receiver expressions during tab
completion ran mrb_vm_run() without proper stack management (stack_keep)
and environment adjustment that mirb's main REPL loop performs. this
corrupted the local variable storage.
the fix restricts tab completion to only evaluate simple receiver
expressions (variable/constant names without operators or method calls).
complex expressions are skipped for completion. this means:
- works: d.<tab> completes methods of variable d
- works: String.<tab> completes methods of constant String
- skipped: d.new(1).<tab> provides no completion
this is a reasonable trade-off that prevents the corruption bug while
still supporting the most common completion scenarios.
also updated mirb_eval_receiver() to use the compiler context for proper
local variable resolution, with argument order matching mrb_parse_string.
Co-authored-by: Claude <noreply@anthropic.com>
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>
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>
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>
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>
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>
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/
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>
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>
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>
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>
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>
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>
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>