496 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 919cbd8fea mruby-compiler: allow compound statement in tLPAREN_ARG
Change the grammar rule for tLPAREN_ARG from accepting only a
single stmt to accepting compstmt. This allows compound
statements with semicolons inside parenthesized arguments when
the parenthesis is preceded by a space, e.g., `p (f1; f2)`.

This matches the behavior of CRuby 3.3+.

Fixes #6766.

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-30 07:06:30 +09:00
Paweł Świątkowski 13d9d770fc Correctly handle empty hash as default named argument
```
def func(arg: {})
  p arg
end
```

This used to work in earlier mruby versions, but broke somewhere recently.
2026-03-18 08:53:20 +01:00
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 b07518e85c parse.y: implement &nil in formal parameters
`&nil` is recently introduced in CRuby to explicitly declare that
a method does not accept a block. When a block is passed,
ArgumentError "no block accepted" is raised. This is analogous to
`**nil` for keyword arguments.

The noblock flag is encoded in bit 23 of OP_ENTER's aspec operand
(24=n1:m5:o5:r1:m5:k5:d1:b1), avoiding the need for a new opcode.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-19 16:54:17 +09:00
Yukihiro "Matz" Matsumoto dcd77f1efd mruby-compiler: replace MRB_SYM_2() with MRB_SYM() macros
The _2 suffix variants accept an mrb_state* parameter that is
always ignored with presym enabled. Replace all uses in codegen.c,
parse.y, and y.tab.c with the standard macros. The _2 macro
definitions are kept in presym headers for backward compatibility.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-19 14:14:40 +09:00
Yukihiro "Matz" Matsumoto f78334b3bf parse.y: allow trailing comma in method definition parameters
Co-authored-by: Claude <noreply@anthropic.com>
2026-01-27 15:20:22 +09:00
Chris Hasiński 1e932dd161 Fix parse error with required kwargs and omitted parens
When defining a method with a required keyword argument without
parentheses, mruby incorrectly parsed the next line as the default
value:

    def foo arg:
      123
    end

Was parsed as: def foo(arg: 123); end  (optional kwarg, empty body)
Should be:     def foo(arg:); 123; end (required kwarg, body returns 123)

The fix sets EXPR_ARG lexer state after parsing f_label, making
newlines significant. This prevents the parser from consuming
expressions across line boundaries as default values for keyword
arguments.

Also fixes a pre-existing bug in f_label where tNUMPARAM (type <num>)
was implicitly assigned to $$ (type <id>) without conversion. Now
explicitly uses intern_numparam() to convert numbered parameters to
symbols.

Fixes https://github.com/mruby/mruby/issues/6268
2026-01-08 00:50:55 +01:00
Yukihiro "Matz" Matsumoto 510ebd738d mruby-compiler: terminate parsing early after too many errors
When parsing malformed input with many syntax errors (e.g., via eval
with a long garbage string), the parser would continue until the end
of input, causing long execution times.

Add an early termination check in the lexer that returns EOF once
the error count exceeds 10 (same as error_buffer size). This prevents
DoS from inputs like eval("garbage" * 1000).

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-31 09:11:44 +09:00
Yukihiro "Matz" Matsumoto 225cdaa16a mruby-compiler: eliminate bison shift-reduce conflict for 'in'
Add precedence declarations to resolve the ambiguity between:
- One-line pattern match: `arg in pattern`
- Case/in clause: `case expr; in pattern; end`

When seeing `arg in`, the parser should shift to parse `arg in pattern`
as a complete expression (matching CRuby behavior), not reduce `arg`
to start a case clause.

Changes:
- Add keyword_in to %nonassoc precedence declarations
- Add %prec tLOWEST to the plain `arg` reduction rule

This eliminates all bison shift-reduce conflicts (was 2, now 0).

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-29 17:56:54 +09:00
Yukihiro "Matz" Matsumoto a91ffcfe0d mruby-compiler: fix as-pattern parsing with symbol values
Remove non-standard `symbol tASSOC p_as` rule from hash pattern
elements. This rule conflicted with the as-pattern rule and caused
`:foo => x` to be incorrectly parsed as a hash pattern instead of
an as-pattern.

CRuby only supports label syntax (foo:) for hash pattern keys,
not hashrocket syntax (:foo =>). This change aligns mruby with
CRuby behavior and reduces bison shift-reduce conflicts from 2 to 1.

Before: `case :foo; in :foo => x; end` raised NoMethodError
After:  `case :foo; in :foo => x; end` binds x to :foo

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-29 13:42:19 +09:00
Yukihiro "Matz" Matsumoto 4fc81e8ea0 mruby-compiler: fix crash in pattern matching with string literal
The p_value grammar rule passed raw tSTRING token (a (len . str) cons
cell) directly to new_pat_value() without wrapping it as a proper AST
node. When codegen processed this malformed node, it read the length
field as the node type, causing misinterpretation and crash.

Wrap tSTRING with new_str(p, list1($1)) to create a proper NODE_STR,
consistent with how the primary:string rule handles strings.

Found by ClusterFuzz (oss-fuzz/mruby_fuzzer).

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-29 13:34:13 +09:00
Yukihiro "Matz" Matsumoto e06ec699a4 mruby-compiler: rename get_node_type to node_type
Resolve static function name collision between parse.y and codegen.c
for amalgamation support.

- parse.y: rename get_node_type() to node_type() (keeps validation)
- codegen.c: replace with node_type() macro (NULL-safe via NODE_TYPE)
- node.h: rename VAR_NODE_TYPE() to NODE_TYPE()

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-23 12:27:12 +09:00
Yukihiro "Matz" Matsumoto 613b03ac18 mruby-compiler: add no_return_value context flag for script optimization
when running scripts via mruby -e or file, return values are unused.
this adds a no_return_value flag to skip generating unnecessary code.

for parallel assignment like a,b = 1,2:
- before: 18 bytes, 5 registers, creates temporary array
- after: 5 bytes, 3 registers, direct register assignment, no RETURN

the flag is set only for the main program, not for libraries loaded
with -r option. eval() and mirb continue returning values correctly.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-21 17:26:49 +09:00
Yukihiro "Matz" Matsumoto 7e28e68dca string.c: add mrb_utf8_to_buf() to consolidate UTF-8 encoding
Extract duplicated UTF-8 codepoint-to-bytes encoding into a shared
function in src/string.c. Update all gems to use it:

- mruby-sprintf: %c specifier
- mruby-io: putc
- mruby-string-ext: Integer#chr
- mruby-pack: pack("U")
- mruby-compiler: Unicode escapes in parser

Also use existing mrb_utf8len() in io.c for character length detection.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-18 16:30:03 +09:00
Yukihiro "Matz" Matsumoto 6c4d98be8b mruby-compiler: implement find pattern matching
add support for find patterns in case/in expressions:
- [*pre, elem, *post] - find elem anywhere in array
- [*, elem, *] - anonymous rest (discarded)
- [*pre, a, b, *post] - multiple middle elements

implementation includes:
- grammar rules for find patterns with p_args, p_rest in parse.y
- NODE_PAT_FIND codegen with iterative search loop
- pre/post variable binding via range slicing
- p_const rule to prevent conflict with array literals

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-18 16:27:26 +09:00
Yukihiro "Matz" Matsumoto e76ce24860 mruby-compiler: add one-line pattern matching
add support for one-line pattern matching syntax:
- 'expr in pattern' returns true/false
- 'expr => pattern' raises NoMatchingPatternError on mismatch

add NODE_MATCH_PAT node type for both forms, distinguished by
raise_on_fail flag. grammar rules placed at expr level to avoid
conflict with rescue clause's exception variable syntax.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-18 16:27:26 +09:00
Yukihiro "Matz" Matsumoto e8096bf745 mruby-compiler: add brace-less hash pattern support
Add support for brace-less hash patterns at top level of case/in.
`in a: x, b: y` is now equivalent to `in {a: x, b: y}`.
`in a:, b:` shorthand now works with newlines (CRuby compatible).

Changes:
- Add EXPR_VALUE to IS_LABEL_POSSIBLE() to recognize labels after `in`
- Add brace-less hash pattern rules to p_expr
- Change p_hash_elem to use p_as instead of p_expr to avoid recursion
- Add in_kwarg flag to parser state for pattern matching context
- Set in_kwarg in lexer when keyword_in is returned
- Use EXPR_ARG after tLABEL_TAG when in_kwarg is set (makes newlines significant)

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-18 16:27:26 +09:00
Yukihiro "Matz" Matsumoto 1de6340f1b mruby-compiler: add pin operator to pattern matching
Add pin operator `^var` that matches against existing variable values
instead of creating new bindings. Also add bracket-less array pattern
syntax at top level: `in 1, 2, x` is equivalent to `in [1, 2, x]`.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-18 16:27:26 +09:00
Yukihiro "Matz" Matsumoto 21472638b9 mruby-compiler: implement hash pattern matching
Add support for hash patterns in pattern matching expressions:
- {key:} shorthand binds to variable with same name
- {key: pattern} matches key against pattern
- {**rest} captures remaining keys
- {**nil} requires exact match (no extra keys)
- {**} ignores extra keys without capturing

Parser adds new grammar rules (p_hash, p_hash_body, p_hash_elems,
p_hash_elem, p_kwrest) and new_pat_hash() constructor.

Codegen generates code to call deconstruct_keys on the target hash,
then iterates through key-pattern pairs to match each key's value.

Adds Hash#deconstruct_keys method that returns self for pattern matching.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-18 16:27:26 +09:00
Yukihiro "Matz" Matsumoto ec67fd9587 mruby-compiler: implement array pattern matching
add support for array destructuring patterns in case/in expressions:
- [a, b, c] - fixed length match
- [first, *rest] - head + rest
- [*init, last] - init + tail
- [first, *middle, last] - head + middle + tail
- [1, x, 3] - mixed value and variable patterns
- [first, *, last] - anonymous rest (discarded)

implementation includes:
- grammar rules for p_array, p_array_body, p_rest in parse.y
- NODE_PAT_ARRAY codegen with deconstruct call and length checks
- rest variable binding via range slicing (arr[pre..-(post+1)])
- Array#deconstruct method (returns self)

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-18 16:27:26 +09:00
Yukihiro "Matz" Matsumoto e61d71aa29 mruby-compiler: add dump_node() support for pattern matching nodes
Add cases to dump_node() for all pattern matching AST node types:
NODE_CASE_MATCH, NODE_IN, NODE_PAT_VALUE, NODE_PAT_VAR, NODE_PAT_PIN,
NODE_PAT_AS, NODE_PAT_ALT, NODE_PAT_ARRAY, NODE_PAT_HASH.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-18 16:27:25 +09:00
Yukihiro "Matz" Matsumoto 07ac110ddd mruby-compiler: add guard clauses to pattern matching
Add support for if/unless guards in case/in pattern matching:

  case value
  in x if x > 0 then :positive
  in x unless x == 0 then :non_zero
  end

Uses modifier_if/modifier_unless tokens since guards appear after
an expression. Disable peephole optimization for pattern variable
binding to prevent gen_move() from being optimized away when failed
guard jumps target the binding instruction.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-18 16:27:25 +09:00
Yukihiro "Matz" Matsumoto dadfac678d mruby-compiler: add pattern matching (case/in) support
Implement Phase 1 of Ruby pattern matching:
- value patterns (literals, constants, nil/true/false)
- variable patterns (binds matched value)
- alternative patterns (pat1 | pat2)
- as patterns (pattern => var)

Pattern matching uses === operator for value comparison,
allowing type checking with class patterns (e.g., in Integer).

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-18 16:27:25 +09:00
Yukihiro "Matz" Matsumoto cc622f718c mruby-compiler: fix super with keyword arguments; fix #6659
allocate ** keyword dictionary register when methods have keyword
arguments (parse.y new_args_tail), broken in commit 26ea71260 during
cons-list to struct migration. reconstruct keyword hash after KEYEND
from extracted keyword local variables so super can access keyword
values. encode block parameter flag in ainfo bit 13 and generate
LOADNIL for block register in codegen_zsuper when parent has keywords
but no block parameter.

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-08 17:37:56 +09:00
Yukihiro "Matz" Matsumoto 8455c41a74 mruby-compiler: combine variable declaration with initialization 2025-10-27 08:24:07 +09:00
Yukihiro "Matz" Matsumoto 3e10aaf6c1 mruby-compiler: add stmts_push helper to fix incorrect push usage
added stmts_push(p, stmts, stmt) helper function to properly push
statements to NODE_STMTS nodes by accessing the internal stmts field
(a cons list). this avoids ugly casts and prevents bugs.

fixed incorrect usage in:
- top_stmts rule (line 2081): was calling push($1, ...) directly on
  NODE_STMTS instead of pushing to $1->stmts
- bodystmt rule (line 2114): same issue when handling else without
  rescue
- stmts rule (line 2146): simplified to use new helper for consistency

the push macro works on cons lists, not NODE_STMTS variable nodes.
the new helper encapsulates the cast and provides type-safe access.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-16 18:01:04 +09:00
Yukihiro "Matz" Matsumoto 5bc3cd0abd mruby-compiler: update node comments from cons-style to struct-style
replace obsolete cons-style comments like /* (:begin prog...) */ with
modern struct-style comments like /* struct: begin_node(body) */ to
reflect current variable-sized node implementation.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:28 +09:00
Yukihiro "Matz" Matsumoto 9156451652 mruby-compiler: fix c++ compilation error in node_hash case
add braces around node_hash case in dump_node() to fix variable
initialization crossing case labels error when compiling with c++.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:28 +09:00
Yukihiro "Matz" Matsumoto 2495cd3c52 mruby-compiler: simplify node allocation in parse.y with helper
introduce new_node() helper and NEW_NODE() macro to eliminate repetitive
allocation and header initialization pattern across 64 new_* functions.

before: each function required 2-3 lines for allocation:
  struct mrb_ast_xxx_node *n = (...)parser_palloc(p, sizeof(...));
  init_var_header(&n->header, p, NODE_XXX);

after: single line with type-safe macro:
  struct mrb_ast_xxx_node *n = NEW_NODE(xxx, NODE_XXX);

saves approximately 128 lines while maintaining readability and providing
central point for future allocation logic changes.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:28 +09:00
Yukihiro "Matz" Matsumoto ee80a2ef26 mruby-compiler: replace accessor macros with direct member access
replaced all *_NODE_* accessor macros (e.g., SYM_NODE_VALUE,
INT_NODE_VALUE, CALL_NODE_METHOD) with direct member access using
casting macros (e.g., sym_node(n)->symbol, int_node(n)->value,
call_node(n)->method_name). this eliminates an unnecessary abstraction
layer and improves code readability by making field access explicit.

the accessor macros simply wrapped cast_func(n)->field, providing no
real benefit. direct member access makes it clear what field is being
accessed and reduces macro indirection.

affected files:
- node.h: removed ~100 accessor macro definitions
- codegen.c: replaced 19 macro uses with direct access
- parse.y: replaced 152 macro uses with direct access

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:27 +09:00
Yukihiro "Matz" Matsumoto f6edae0918 mruby-compiler: reduce unnecessary block scopes in dump_node
removed unnecessary block scopes in dump_node cases to reduce
indentation:
- NODE_SCOPE: removed scope variable, use macros directly
- NODE_HASH: removed block around hash pair iteration
- NODE_CLASS, NODE_MODULE, NODE_SCLASS: removed blocks around body dumps

improves code readability with cleaner indentation.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:27 +09:00
Yukihiro "Matz" Matsumoto 5339a915df mruby-compiler: improve yield node dump to use callargs formatter
changed NODE_YIELD dump from dump_recur to dump_callargs for consistent
argument display format. added null check to handle yield without args.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:26 +09:00
Yukihiro "Matz" Matsumoto 6c923dc12c mruby-compiler: eliminate NODE_STR wrapper in NODE_DSYM implementation
Refactored NODE_DSYM to use unified structure directly instead of wrapping
NODE_STR. This eliminates unnecessary allocation and simplifies the AST.

Changes:
- new_dsym() now creates NODE_DSYM directly with mrb_ast_str_node structure
- Parser calls new_dsym(p, n) instead of new_dsym(p, new_str(p, n))
- codegen_dsym() uses gen_string() for proper string generation
- NODE_DSYM dump uses dump_str() for consistent string list handling
- Removed redundant mrb_ast_dsym_node struct definition

This maintains identical functionality while reducing memory overhead
and architectural complexity, with proper string handling to prevent
mrbtest crashes.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:26 +09:00
Yukihiro "Matz" Matsumoto 492ccefa25 mruby-compiler: unify loop node dump cases to reduce duplication
Consolidated NODE_WHILE, NODE_UNTIL, NODE_WHILE_MOD, and NODE_UNTIL_MOD
dump cases using a shared dump_loop_node label. All four loop constructs
have identical structure (condition + body) and only differ in their
node type names.

Uses fall-through for the last case (NODE_UNTIL_MOD) to avoid unnecessary
goto. This eliminates code duplication (28 lines -> 12 lines) while
maintaining the same clear output format for each loop type.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:26 +09:00
Yukihiro "Matz" Matsumoto 75e2bb1ee0 mruby-compiler: improve dynamic symbol dump to show node structure
Enhanced NODE_DSYM dump to use dump_node() instead of dump_str() for
the symbol's content list. Dynamic symbols (:"#{expr}") contain node
lists that may include complex interpolated expressions, not just simple
strings, so they need full node dumping to properly display their structure.

This provides much better visibility into interpolated symbol content
and makes debugging dynamic symbols more effective.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:26 +09:00
Yukihiro "Matz" Matsumoto 4cb9e9f553 mruby-compiler: improve hash dump to display double-splat operator
Enhanced NODE_HASH dump to detect and display the double-splat operator
(**) in a readable format. When a hash contains **other_hash syntax,
the parser represents ** as MRB_OPSYM(pow). Instead of dumping this
complex operator node, now displays a clean "**" for better readability.

This makes hash dumps with splat operations much easier to understand
and debug.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:26 +09:00
Yukihiro "Matz" Matsumoto 29e70c10ba mruby-compiler: improve for-loop variable dump with labeled sections
Enhanced NODE_FOR dump to properly handle the cons-list structure of
FOR_NODE_VAR with clear section labels. The structure contains:
- car: cons-list of pre-splat variables
- cdr->car: splat varnode (not a cons-list)
- cdr->cdr->car: cons-list of post-splat variables

Added "splat var:" and "post var:" labels to distinguish sections
and simplified the dump logic for better readability.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:25 +09:00
Yukihiro "Matz" Matsumoto 791f631191 mruby-compiler: add NODE_MARG for parameter destructuring
Implement NODE_MARG as a dedicated node type for parameter destructuring
to separate it architecturally from general multiple assignment (NODE_MASGN).
This resolves crashes when dumping parameter destructuring nodes and
improves code organization.

Key changes:
- Add NODE_MARG to node type enum
- Create new_marg() function for parameter destructuring
- Consolidate new_masgn() and new_marg() using shared helper
- Fix parameter context checks in lambda_body() to use NODE_MARG only
- Enable shared dumping logic for both NODE_MASGN and NODE_MARG
- Optimize memory management with immediate RHS cleanup
- Combine gen_assignment() cases for code deduplication

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 19:46:25 +09:00
Yukihiro "Matz" Matsumoto eae2501ff1 mruby-compiler: fix NODE_CASE dump to properly handle when clauses
The NODE_CASE dump was treating the case body as a single varnode,
but it's actually a cons-list structure containing when clauses.
Changed to iterate through the cons-list similar to rescue clauses,
allowing proper display of when conditions and bodies.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:25 +09:00
Yukihiro "Matz" Matsumoto 759c1b1eff mruby-compiler: refactor NODE_MASGN structure and fix parameter destructuring
Refactored NODE_MASGN from single lhs field to separate pre/rest/post
fields for cleaner multiple assignment handling. Fixed segfault when
compiling methods with destructured parameters by properly handling
parameter destructuring in lambda_body function.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:25 +09:00
Yukihiro "Matz" Matsumoto 7fd10e65ce mruby-compiler: fix NODE_SUPER/NODE_ZSUPER dump segfault
Fixed copy-paste error where NODE_SUPER and NODE_ZSUPER cases in
dump_node incorrectly used CALL_NODE_ARGS macro instead of
SUPER_NODE_ARGS, causing segmentation faults when parser dump
tried to access invalid memory addresses.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:25 +09:00
Yukihiro "Matz" Matsumoto 1dcf59b372 mruby-compiler: migrate NODE_ENSURE dump to variable-sized nodes
Replace direct cons-list access (tree->car, tree->cdr->cdr) with
proper accessor macros (ENSURE_NODE_BODY, ENSURE_NODE_ENSURE_CLAUSE)
to support variable-sized node structures. Adds null checks for
improved safety and follows the same pattern as other migrated nodes.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:25 +09:00
Yukihiro "Matz" Matsumoto 6f5d2d19cb mruby-compiler: add NODE_NVAR support to parser dump
Add support for dumping NODE_NVAR nodes in dump_node function.
NODE_NVAR represents numbered variables and displays the variable
number for debugging AST structures.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:24 +09:00
Yukihiro "Matz" Matsumoto af4df6d75d mruby-compiler: fix NODE_HEREDOC parser dump crash
Replace dump_recur() with dump_str() in NODE_HEREDOC case to properly
handle cons-lists of string representations instead of AST nodes.
This fixes segmentation faults when dumping heredoc AST nodes.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:24 +09:00
Yukihiro "Matz" Matsumoto 29a305e6f7 mruby-compiler: rename mrb_parser_dump to dump_node for consistency
Renamed the internal implementation from mrb_parser_dump() to dump_node()
to follow the naming convention of other dump functions (dump_prefix,
dump_str, dump_recur). Added a public wrapper mrb_parser_dump() that
calls dump_node() to maintain API compatibility.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:24 +09:00
Yukihiro "Matz" Matsumoto 553b1aa3f8 mruby-compiler: enable str_dump for better string representation in parser dump
Move str_dump function from commented section to active code and update
dump_str to use proper string dumping with escape sequence handling.
Remove obsolete commented str_dump implementation.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:24 +09:00
Yukihiro "Matz" Matsumoto e73212c57f mruby-compiler: implement NODE_WORDS and NODE_SYMBOLS parser dump with cons list handling
Add proper traversal of cons list structure with (0 . 0) separators
for word arrays (%w[]) and symbol arrays (%i[]). Includes safety
checks for pointer validation and length bounds.

Note: Crashes still occur during testing, indicating the issue may
be in accessor macros or data structure alignment.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:24 +09:00
Yukihiro "Matz" Matsumoto a29afe7fe7 mruby-compiler: remove unused NODE_MATCH node type and related code
Remove NODE_MATCH enum value, structure definition, accessor macro,
parser dump case, codegen case, and gen_match_var function. This
node type was never actually used in the parser.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:23 +09:00
Yukihiro "Matz" Matsumoto a8222fbab9 mruby-compiler: improve NODE_REGX parser dump to use dump_str
Replace manual pattern parsing with dump_str to properly handle both
simple and dynamic regex patterns. This provides consistent output
format for literal strings and interpolated expressions.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:23 +09:00
Yukihiro "Matz" Matsumoto 7d72da2842 mruby-compiler: remove old NODE_REGX and consolidate with NODE_DREGX
Remove the original NODE_REGX node type and related infrastructure,
then rename NODE_DREGX to NODE_REGX to consolidate regex handling
under a single node type.

Changes based on git diff:
- Remove original mrb_ast_regx_node structure with pattern fields
- Remove gen_regx_var() function handling literal regex patterns
- Remove NODE_REGX case from codegen and parser dump
- Rename NODE_DREGX to NODE_REGX for dynamic regex expressions
- Update all related functions and structure references

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:23 +09:00