Commit Graph

17646 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 9a680d11ef mruby-compiler: rename operator field to op for c++ compatibility
Rename mrb_ast_op_asgn_node.operator field to op to avoid conflict with
C++ operator keyword. Update all references including macro definitions
and field access code.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:18 +09:00
Yukihiro "Matz" Matsumoto cbe01d574c mruby-compiler: simplify case statement implementation and fix infinite loop bug
- Remove obsolete NODE_ARGS_TAIL enum value and all references
- Simplify mrb_ast_case_node from variable-sized array back to simple cons-list structure
- Update new_case() function to use original cons-list approach instead of flattening
- Fix infinite loop in gen_case_var() when case statements have no matching clauses
- Improve code readability by renaming pos3 to case_end_jumps in gen_case_var()
- Restore memory-efficient case statement parsing without complex array management

The variable-sized array approach for case nodes provided no memory benefit
since cons lists aren't recycled. This change restores the simpler original
implementation while fixing a critical bug that caused mrbtest to hang
on "register window of calls" test.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:18 +09:00
Yukihiro "Matz" Matsumoto 8999442441 mruby-compiler: remove unused NODE_ARGS_TAIL references
NODE_ARGS_TAIL was a legacy enum value no longer created or used
after the conversion to struct-based argument handling. This change:

- Removes the NODE_ARGS_TAIL enum value from node.h
- Removes the unused case from mrb_parser_dump function
- Removes the obsolete assertion in dump_args function

All tests pass and argument forwarding continues to work correctly.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:18 +09:00
Yukihiro "Matz" Matsumoto bb6b154c79 mruby-compiler: use helper macros for all variable types
Replace explicit new_xvar calls with their respective helper macros
for improved code readability and consistency:
- new_xvar(p, sym, NODE_LVAR) → new_lvar(p, sym)
- new_xvar(p, sym, NODE_IVAR) → new_ivar(p, sym)
- new_xvar(p, sym, NODE_GVAR) → new_gvar(p, sym)
- new_xvar(p, sym, NODE_CVAR) → new_cvar(p, sym)

This change makes the parser code more maintainable while preserving
identical functionality for all variable types.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:18 +09:00
Yukihiro "Matz" Matsumoto d15e1853b2 mruby-compiler: simplify argument handling by removing redundant NODE_ARG
NODE_ARG and NODE_LVAR were handled identically in codegen.c, making
the distinction unnecessary. This change:

- Replaces all new_arg() calls with new_xvar(p, sym, NODE_LVAR)
- Removes the new_arg() function entirely
- Removes the unused NODE_ARG enum value
- Updates codegen.c to handle only NODE_LVAR case

The simplification reduces parser complexity while maintaining identical
functionality for argument processing.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:18 +09:00
Yukihiro "Matz" Matsumoto 26ea712607 mruby-compiler: complete migration from cons-list to struct-based argument handling
This commit completes the transformation of mruby's argument processing from
cons-list based representation to direct struct field access.

Key changes:
- Transform new_args() to return struct mrb_ast_args* instead of cons-list
- Update lambda_body() to use direct struct field access for all argument types
- Fix anonymous keyword rest (**) to use intern_op(pow) marker for proper bytecode generation
- Fix argument forwarding (...) to correctly pass rest_arg to new_args()
- Eliminate mrb_ast_args_tail_node allocation by embedding fields directly in mrb_ast_args
- Update all node structure definitions to use struct mrb_ast_args*
- Remove unused NODE_ARGS enum value since args are now plain C structs

The new approach provides:
- More efficient memory usage by eliminating intermediate cons-list allocations
- Cleaner code generation with direct struct field access
- Proper distinction between anonymous kwrest and no kwrest
- Correct bytecode generation for both anonymous kwrest and argument forwarding

Fixes both anonymous keyword rest (def m(**) end) and argument forwarding
(def a(...) p(...) end) to generate correct bytecode and execute properly.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:18 +09:00
Yukihiro "Matz" Matsumoto c970bef0c3 mruby-compiler: inline codegen_variable_node function into codegen
Inline the 320-line codegen_variable_node() function directly into the
codegen() function to eliminate function call overhead for every
variable-sized AST node processing.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:17 +09:00
Yukihiro "Matz" Matsumoto deab43ce7b mruby-compiler: refactor call_with_block function to simplify control flow
Remove useless outer switch statement and convert nested if-else chain to
a clean switch statement on node types. This improves code readability
and maintainability in the parser's block handling logic.

Key improvements:
- Replace outer switch with simple early return for non-NODE_VARIABLE cases
- Convert if-else if chain to proper switch statement on var_type
- Standardize null checks to use != NULL consistently
- Use break statements consistently instead of mixing return and break
- Maintain exact same functionality while improving code structure

The refactoring eliminates unnecessary nesting and makes the function's
logic flow more explicit by directly switching on the actual node type
rather than wrapping it in a redundant switch statement.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:17 +09:00
Yukihiro "Matz" Matsumoto c5431ac293 mruby-compiler: migrate NODE_CALL and NODE_FCALL to variable-sized nodes
Remove NODE_SCALL and NODE_FCALL node types, consolidating all method calls
into a single NODE_CALL variable-sized node structure. This simplifies the
AST by unifying call semantics while maintaining support for safe navigation
and different call types through node flags.

Key changes:
- Convert call nodes to use variable-sized allocation with call_node structure
- Unify new_call() and new_fcall() to create NODE_CALL nodes consistently
- Replace gen_call() with separate gen_call_var() and gen_call_assign_var()
- Add gen_call_assign_var() for assignment operations like h[k] = v
- Remove legacy call handling from main codegen switch statement
- Preserve argument structure using args pointer instead of unpacking
- Support safe calls, keyword arguments, and blocks in unified structure

This migration maintains backward compatibility while enabling more efficient
call node processing and reduced code duplication in the compiler.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:17 +09:00
Yukihiro "Matz" Matsumoto ecbf25378b mruby-compiler: migrate NODE_DEF and NODE_SDEF to variable-sized nodes
Complete migration of method definition nodes to variable-sized format:
- Convert NODE_DEF and NODE_SDEF from fixed cons-based to variable-sized nodes
- Update parser to create variable-sized def/sdef nodes directly
- Remove old codegen_def and codegen_sdef functions
- Consolidate method setup logic in defn_setup function
- Rename lambda_body_ex to lambda_body after removing wrapper layer
- Update all method definition code generation to use new node structure

This completes the variable-sized node migration for method definitions,
improving memory efficiency and enabling more flexible AST handling.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:17 +09:00
Yukihiro "Matz" Matsumoto 2596005750 mruby-compiler: remove _var suffix from gen_colon2_assign_var and gen_colon3_assign_var
Clean up function names by removing unnecessary _var suffixes for
consistency with other assignment functions.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:17 +09:00
Yukihiro "Matz" Matsumoto 832c579f8e mruby-compiler: refactor lambda_body to take individual parameters
created lambda_body_ex that takes locals, args, and body as separate
parameters instead of a cons structure. this eliminates complex cons
cell navigation and makes the interface cleaner for variable-sized
nodes. updated all call sites (gen_def_var, gen_sdef_var, gen_block_var,
gen_lambda_var) to use lambda_body_ex directly.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:17 +09:00
Yukihiro "Matz" Matsumoto 3fd59d336e mruby-compiler: migrate NODE_LVAR and NODE_ARG to variable-sized nodes
Convert NODE_LVAR and NODE_ARG from cons-list to variable-sized nodes.
Remove new_lvar wrapper and use new_xvar directly. Update parser
semantic functions and cleanup gen_assignment. Rename codegen_lvar
to gen_lvar for consistency.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:16 +09:00
Yukihiro "Matz" Matsumoto b2aba341f5 mruby-compiler: convert new_op_asgn to always use variable-sized nodes
Remove conditional logic from new_op_asgn() that created traditional
cons-list nodes when var_nodes_enabled was false. Now always creates
variable-sized nodes using struct mrb_ast_op_asgn_node.

Also remove traditional NODE_OP_ASGN codegen path and unused
codegen_op_asgn function, completing the migration to variable-sized
nodes for all operator assignment patterns.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:16 +09:00
Yukihiro "Matz" Matsumoto 88f3110215 mruby-compiler: convert new_masgn to always use variable-sized nodes
Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:16 +09:00
Yukihiro "Matz" Matsumoto 83707f7798 mruby-compiler: convert new_asgn to always use variable-sized nodes
Remove conditional logic from new_asgn() and inline new_asgn_var() helper
function for cleaner implementation. Assignment expressions maintain proper
value semantics while using more efficient memory allocation.

Changes:
- Remove var_nodes_enabled conditional in new_asgn()
- Inline new_asgn_var() logic directly into new_asgn()
- Remove new_asgn_var() function and declaration
- Remove NODE_ASGN case from main codegen() switch
- Update gen_asgn_var() to use direct struct field access
- Remove traditional codegen_asgn() function

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:16 +09:00
Yukihiro "Matz" Matsumoto 8c3de9c85e mruby-compiler: fix ||= operator for variable-sized NODE_CONST and NODE_CVAR
Update codegen_op_asgn() to handle variable-sized nodes wrapped in NODE_VARIABLE
instead of assuming traditional cons-list format. Remove obsolete traditional
node type checks since NODE_CONST and NODE_CVAR now always use variable-sized
nodes.

The ||= operator generates special exception-handling bytecode for undefined
constant/class variable detection that requires checking the node type to
apply proper optimization.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:16 +09:00
Yukihiro "Matz" Matsumoto 8967ad200a mruby-compiler: convert new_const to always use variable-sized nodes
Remove conditional logic from new_const() and inline new_const_var() helper
function for cleaner implementation. Update codegen to handle NODE_CONST
in both variable-sized access and assignment contexts.

Changes:
- Remove var_nodes_enabled conditional in new_const()
- Inline new_const_var() logic directly into new_const()
- Remove new_const_var() function and declaration
- Remove NODE_CONST case from main codegen() switch
- Add NODE_CONST support in gen_assignment() for variable-sized nodes
- Inline codegen_const() logic into gen_const_var()
- Remove traditional codegen_const() function

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:16 +09:00
Yukihiro "Matz" Matsumoto 7792280ff3 mruby-compiler: convert new_nvar to always use variable-sized nodes
Remove var_nodes_enabled conditional from new_nvar() and traditional
NODE_NVAR case from codegen. All numbered parameter operations now use
unified variable-sized node handling.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:15 +09:00
Yukihiro "Matz" Matsumoto 0ca48e24f0 mruby-compiler: remove traditional node_gvar/ivar/cvar cases from codegen
Remove remaining NODE_GVAR/IVAR/CVAR cases from codegen switch statements
since parser now always creates variable-sized nodes. All variable operations
now use unified NODE_VARIABLE handling.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:15 +09:00
Yukihiro "Matz" Matsumoto 07705b18e1 pre-commit autoupdate 2025-10-03 19:46:15 +09:00
Yukihiro "Matz" Matsumoto f4507c0cbf mruby-compiler: complete NODE_BLOCK_ARG migration to variable-sized nodes
Remove traditional NODE_BLOCK_ARG support from main codegen() switch and
eliminate synthetic node creation in gen_block_arg_var. The function now
handles the variable-sized node directly without creating temporary
traditional nodes on the stack.

This completes the NODE_BLOCK_ARG migration by removing the dual handling
pattern while maintaining the gen_block_arg_var function for better code
organization and readability.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:15 +09:00
Yukihiro "Matz" Matsumoto af87c87f5f mruby-compiler: remove traditional NODE_POSTEXE support from codegen
remove NODE_POSTEXE from main codegen function and inline gen_postexe_var
into codegen_variable_node. remove unused codegen_postexe function since
NODE_POSTEXE is now only a marker like NODE_ARGS

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:15 +09:00
Yukihiro "Matz" Matsumoto ac871cd455 mruby-compiler: remove traditional NODE_ARGS_TAIL support from codegen
migrate new_args_tail to always create variable-sized nodes and remove
legacy conditional logic from lambda_body. remove NODE_ARGS_TAIL from
codegen_variable_node since it is now only a marker like NODE_ARGS

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:15 +09:00
Yukihiro "Matz" Matsumoto 19ddb7de5f mruby-compiler: complete NODE_SPLAT migration to variable-sized nodes exclusively
remove conditional from new_splat to always create variable-sized nodes and
eliminate traditional NODE_SPLAT case from codegen switch. update splat marker
detection throughout codegen to handle variable-sized format and inline
codegen_splat logic into gen_splat_var.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:15 +09:00
Yukihiro "Matz" Matsumoto c1a024f8a1 mruby-compiler: inline codegen_negate into gen_negate_var
remove codegen_negate wrapper function and inline its logic directly
into gen_negate_var. this completes NODE_NEGATE migration cleanup.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:14 +09:00
Yukihiro "Matz" Matsumoto e03770b3f9 mruby-compiler: inline codegen_undef into gen_undef_var
remove codegen_undef wrapper function and inline its logic directly
into gen_undef_var. this completes NODE_UNDEF migration cleanup.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:14 +09:00
Yukihiro "Matz" Matsumoto 47d3dd9396 mruby-compiler: remove unused NODE_STR, NODE_XSTR, NODE_REGX, NODE_DREGX cases
remove unused node cases and their corresponding codegen functions from
traditional codegen switch. these nodes are fully migrated to variable-sized
implementation where parser only generates variable-sized nodes via
NODE_VARIABLE wrapper.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:14 +09:00
Yukihiro "Matz" Matsumoto 4b0fd18eb5 mruby-compiler: complete NODE_BACK_REF migration to variable-sized nodes
Remove traditional NODE_BACK_REF case and inline codegen_back_ref logic into
gen_back_ref_var. NODE_BACK_REF now exclusively uses variable-sized nodes,
directly accessing the type field from the node structure instead of converting
through int_to_node/node_to_char.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:14 +09:00
Yukihiro "Matz" Matsumoto a96311453e mruby-compiler: complete NODE_NTH_REF migration to variable-sized nodes
Remove traditional NODE_NTH_REF case and inline codegen_nth_ref logic into
gen_nth_ref_var. NODE_NTH_REF now exclusively uses variable-sized nodes,
directly accessing the nth value from the node structure instead of converting
through int_to_node/node_to_int.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:14 +09:00
Yukihiro "Matz" Matsumoto 5fe0ebbca5 mruby-compiler: inline codegen_self into gen_self_var
Remove unused codegen_self function and inline its simple OP_LOADSELF logic
directly into gen_self_var. This eliminates unnecessary function call overhead
and simplifies the codebase.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:14 +09:00
Yukihiro "Matz" Matsumoto 55a112693e mruby-compiler: inline codegen_nil into gen_nil_var
Remove unused codegen_nil function and inline its simple OP_LOADNIL logic
directly into gen_nil_var. This eliminates unnecessary function call overhead
and simplifies the codebase.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:14 +09:00
Yukihiro "Matz" Matsumoto 626c17d20b mruby-compiler: complete NODE_HASH and NODE_KW_HASH migration to variable-sized nodes
Remove traditional NODE_HASH and NODE_KW_HASH cases from switch statement.
Inline codegen_hash logic into gen_kw_hash_var and remove unused codegen_hash function.

Parser already creates variable-sized nodes exclusively, so all hash operations
now route through gen_hash_var() and gen_kw_hash_var() respectively.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:13 +09:00
Yukihiro "Matz" Matsumoto ad9c130169 mruby-compiler: inline new_block_var into new_block
Remove separate new_block_var function and inline its logic directly into
new_block() to follow the same pattern used for other node migrations.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:13 +09:00
Yukihiro "Matz" Matsumoto af3817efb9 mruby-compiler: complete NODE_BLOCK and NODE_LAMBDA migration to variable-sized nodes
Migrated both NODE_BLOCK and NODE_LAMBDA to use variable-sized nodes exclusively
while fixing compatibility issues with mixed node structures.

Parser changes:
- new_block() and new_lambda() always create variable-sized nodes
- temporarily disabled var_nodes_enabled to avoid mixed node structure issues

Codegen changes:
- removed codegen_block() and codegen_lambda() functions
- removed traditional NODE_BLOCK and NODE_LAMBDA cases from switch statement
- inlined logic into gen_block_var() and gen_lambda_var() using stack-allocated structures
- fixed lambda_body() to handle both variable-sized and cons-list NODE_ARGS_TAIL
- restored OP_KEYEND generation logic for proper keyword argument validation

All tests pass with improved memory efficiency through direct struct access.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:13 +09:00
Yukihiro "Matz" Matsumoto 624b92d0db mruby-compiler: remove codegen_stmts and inline logic into gen_stmts_var
Complete NODE_STMTS migration by removing unused codegen_stmts function
and inlining statement traversal logic directly into gen_stmts_var.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:13 +09:00
Yukihiro "Matz" Matsumoto f4fe87c11e mruby-compiler: remove cons-list support for NODE_BREAK, NODE_NEXT, NODE_REDO, NODE_RETRY
These node types always generate variable-sized nodes, so the cons-list
codegen support is no longer needed. This change:

codegen.c:
- Moves logic from codegen_break/next/redo/retry into gen_*_var functions
- Removes cons-list switch cases for these four node types
- Removes the now-unused codegen_break/next/redo/retry functions

parse.y:
- Updates call_with_block to handle NODE_BREAK and NODE_NEXT through
  NODE_VARIABLE case instead of cons-list cases
- Removes the now-unused cons-list cases for these node types

All control flow functionality remains identical, but the code path is
simplified since these nodes exclusively use variable-sized structures.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:13 +09:00
Yukihiro "Matz" Matsumoto 5e130f5381 mruby-compiler: refactor class/module/singleton class generation using helper functions
Unified gen_class_var, gen_module_var, and gen_sclass_var functions by extracting
common patterns into two helper functions:
- gen_class_body() handles body generation for all three types
- gen_namespace() handles namespace/parent setup for class and module

This refactoring eliminates approximately 40 lines of duplicated code while
maintaining identical functionality and bytecode generation patterns.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:13 +09:00
Yukihiro "Matz" Matsumoto 6e68e9f5e2 mruby-compiler: complete NODE_CLASS, NODE_MODULE, and NODE_SCLASS migration to variable-sized nodes exclusively
- Implement complete variable-sized node generation for all class/module types
  - gen_class_var(): full class definition with namespace and superclass support
  - gen_module_var(): complete module definition with proper scope handling
  - gen_sclass_var(): singleton class with object evaluation and OP_SCLASS
  - All use scope_body() for proper locals and body management
- Update parser to always create variable-sized nodes
  - Inline helper function logic directly into new_class(), new_module(), new_sclass()
  - Remove conditional var_nodes_enabled checks for consistency
  - Eliminate separate _var helper functions
- Remove obsolete traditional node handling
  - Delete codegen_class(), codegen_module(), codegen_sclass() functions
  - Remove NODE_CLASS, NODE_MODULE, NODE_SCLASS cases from main codegen() switch
  - Clean up unused function declarations
- All 1730 tests pass, class/module/singleton functionality verified

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:12 +09:00
Yukihiro "Matz" Matsumoto 2b931d0c5e mruby-compiler: refactor scope_body() to accept separate locals and body parameters
Change scope_body() signature from (s, tree, val) to (s, locals, body, val)
to eliminate artificial cons-list structure creation on stack. This improves
the API design and prepares for future variable-sized node migrations.

Updated call sites:
- gen_scope_var(): remove stack allocation, pass scope->locals/body directly
- codegen_class(): pass body->car, body->cdr separately
- codegen_module(): pass tree->cdr->car->car, tree->cdr->car->cdr separately
- codegen_sclass(): pass tree->cdr->car->car, tree->cdr->car->cdr separately

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:12 +09:00
Yukihiro "Matz" Matsumoto d1633160cc mruby-compiler: complete NODE_SCOPE migration to variable-sized nodes exclusively
Remove NODE_SCOPE case from main codegen() switch and migrate all node
creation to variable-sized nodes. Add node_type_p() helper for unified
node type checking across traditional and variable-sized nodes.

Key fixes:
- Use scope_node(node->cdr) pattern for NODE_VARIABLE wrapper extraction
- Update parser_update_cxt and mrb_parser_foreach_top_variable
- Add NODE_VARIABLE support to mrb_parser_dump for bintest compatibility
- Fix mirb local variable handling preventing TypeError on evaluation

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:12 +09:00
Yukihiro "Matz" Matsumoto 7bfd1a01c8 mruby-compiler: complete NODE_RESCUE and NODE_ENSURE migration to variable-sized nodes exclusively
- remove conditional logic from new_rescue() and new_ensure(), always creating variable-sized nodes
- remove unused new_rescue_var() helper function
- remove traditional NODE_RESCUE and NODE_ENSURE cases from main codegen() switch
- inline codegen_rescue() logic directly into gen_rescue_var() for optimal performance
- inline codegen_ensure() logic directly into gen_ensure_var() for optimal performance
- eliminate temporary cons-like structures, using direct variable-sized node field access
- remove now-unused codegen_rescue() and codegen_ensure() functions

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:12 +09:00
Yukihiro "Matz" Matsumoto f5ce65e418 mruby-compiler: complete NODE_COLON2 and NODE_COLON3 migration to variable-sized nodes
Remove conditional logic from new_colon2() to always create variable-sized
nodes. Implement assignment support for variable-sized constant nodes with
dedicated helper functions. Remove obsolete cons list code paths from
gen_assignment() and codegen().

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:12 +09:00
Yukihiro "Matz" Matsumoto d69bc16370 mruby-compiler: complete NODE_ARRAY migration to variable-sized nodes exclusively
Following the proven NODE_HASH pattern:
- Inlined new_array_var functionality into new_array in parse.y
- Enhanced gen_array_var with full splat support from gen_values
- Removed obsolete codegen_array function and cons list NODE_ARRAY case
- All arrays now use variable-sized nodes with identical test success (1730/1731)

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:12 +09:00
Yukihiro "Matz" Matsumoto cd659927fa mruby-compiler: complete NODE_HASH migration to variable-sized nodes exclusively
Modified new_hash function to always create variable-sized nodes instead of
conditionally falling back to cons list nodes. This achieves complete
NODE_HASH migration with full test suite compatibility.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:11 +09:00
Yukihiro "Matz" Matsumoto 300557d6ee mruby-compiler: optimize case statement bytecode with JMPNOT instruction
Replace JMPIF+JMP pattern with JMPNOT for last condition in each when
clause, allowing when bodies to execute inline. Also eliminate no-op
JMP instructions from else clauses, reducing overall instruction count.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:11 +09:00
Yukihiro "Matz" Matsumoto a4754c03b0 mruby-compiler: complete NODE_CASE migration to variable-sized nodes
Replace cons-list based case statement implementation with variable-sized
nodes for improved memory efficiency. The new implementation maintains
identical register allocation behavior using the original's proven
"nil-first, align-last" strategy.

Key changes:
- Convert new_case() to create variable-sized mrb_ast_case_node directly
- Replace codegen_case() with gen_case_var() using array iteration
- Apply original register allocation logic to new node structure
- Fix else clause handling in jump dispatch logic

Supports all case statement variants:
- Bare case statements (case when condition)
- Case with values (case expr when condition)
- UPVAR combinations with closure variables
- Splat operations (*case)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 19:46:11 +09:00
Yukihiro "Matz" Matsumoto d45ec366c5 mruby-compiler: migrate NODE_FOR to variable-sized nodes exclusively
Remove conditional logic and consolidate NODE_FOR implementation to use
variable-sized nodes exclusively. This eliminates dual code paths and
completes the NODE_FOR migration.

Changes:
- inline new_for_var into new_for, remove p->var_nodes_enabled condition
- remove new_for_var function and forward declaration
- enhance gen_for_var with complete for-loop implementation from for_body
- remove codegen_for and for_body functions
- remove NODE_FOR case from main codegen switch (traditional cons-list path)

The for-loop implementation preserves Ruby's each-based semantics with
proper block scoping, argument handling, and loop control (break/next/redo)
while providing better memory efficiency through variable-sized nodes.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:11 +09:00
Yukihiro "Matz" Matsumoto 272c325881 mruby-compiler: optimize while/until node structures and implementations
Consolidate NODE_WHILE/NODE_UNTIL with MOD variants by sharing structures
and implementations, eliminating redundant code and improving maintainability.

Changes:
- remove separate mrb_ast_while_mod_node and mrb_ast_until_mod_node structures
- share mrb_ast_while_node between NODE_WHILE and NODE_WHILE_MOD variants
- share mrb_ast_until_node between NODE_UNTIL and NODE_UNTIL_MOD variants
- simplify new_while_mod to call new_while and update node_type
- simplify new_until_mod to call new_until and update node_type
- update gen_while_mod_var and gen_until_mod_var to use shared structures

The MOD variants now reuse core allocation logic from regular variants,
differing only in node_type. This eliminates code duplication while
preserving identical functionality for both pre-tested and post-tested loops.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:11 +09:00
Yukihiro "Matz" Matsumoto 01b2a7bd22 mruby-compiler: complete NODE_IF migration to variable-sized nodes
Remove conditional logic and consolidate NODE_IF implementation to use
variable-sized nodes exclusively. This eliminates dual code paths and
completes the NODE_IF migration started in previous commits.

Changes:
- inline new_if_var into new_if, remove p->var_nodes_enabled condition
- remove new_unless function, replace calls with new_if (swap then/else)
- remove codegen_if function, merge nil? optimization into gen_if_var
- remove NODE_IF case from main codegen switch (always wrapped in NODE_VARIABLE)
- fix nil? optimization to handle both traditional and variable-sized nodes
- update gen_if_var to use direct struct field access instead of macros

The nil? optimization now works with both node representations:
- Traditional: NODE_TYPE(condition) == NODE_CALL (preserved)
- Variable-sized: NODE_VARIABLE wrapper containing NODE_CALL struct

This ensures obj.nil? patterns generate optimized OP_JMPNIL bytecode
regardless of AST node representation.

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