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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
- 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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>
Replace dual integer parsing paths with two-tier system:
- NODE_INT stores int32_t values directly for common case
- NODE_BIGINT stores string representation for overflow values
- Custom read_int32() function provides locale-independent parsing
- Remove unused readint() function from codegen
This eliminates confusing dual code paths while maintaining performance
for the majority of integer literals that fit in 32-bit range.
Co-authored-by: Claude <noreply@anthropic.com>
Fix mrb_bint_new_str to normalize bigint objects to regular integers
when possible. This ensures consistent object types for values that
fit in mrb_int range, fixing comparison failures in tests.
Co-authored-by: Claude <noreply@anthropic.com>
Remove obsolete cons-list node cases since control flow nodes (break,
return, next, redo, retry) and logical operators (and, or) are now
always created as variable-sized nodes. Move and/or handling to inner
switch with proper struct field access.
Co-authored-by: Claude <noreply@anthropic.com>
Remove obsolete cons-list node cases and simplify structure to direct
conditional since only NODE_VARIABLE wrapper needs to be handled after
variable-sized node migration.
Co-authored-by: Claude <noreply@anthropic.com>
Remove conditional var_nodes_enabled logic from new_nil and new_self functions.
These functions now directly create variable-sized AST nodes using proper
size classes and memory allocation. Remove helper functions new_nil_var and
new_self_var as they are no longer needed.
Also update codegen to handle the new variable-sized node structure:
- Add NODE_VARIABLE handling to gen_assignment function
- Fix self-method call detection in call generation
- Update assignment generation to properly handle variable-sized nil nodes
Co-authored-by: Claude <noreply@anthropic.com>
Remove conditional var_nodes_enabled logic from new_and and new_or functions.
These functions now directly create variable-sized AST nodes using proper
size classes and memory allocation. Also remove unused codegen_and and
codegen_or functions as all code generation now goes through the variable-sized
node handlers gen_and_var and gen_or_var with proper short-circuit evaluation.
Co-authored-by: Claude <noreply@anthropic.com>
Removed traditional NODE_ALIAS case from main codegen() switch and
inlined codegen_alias() logic directly into gen_alias_var(). This
eliminates the hybrid approach that created temporary stack structures
and provides direct access to variable-sized node fields.
Co-authored-by: Claude <noreply@anthropic.com>
Updated new_float() to always create variable-sized nodes and removed
the conditional logic. Also updated codegen_negate() to handle
NODE_VARIABLE wrapper containing NODE_FLOAT for negative float literals.
Co-authored-by: Claude <noreply@anthropic.com>
- Remove conditional var_nodes_enabled logic from new_return
- Delete unused new_return_var function and forward declaration
- Move NODE_RETURN handling to NODE_VARIABLE branch in call_with_block
- Remove traditional NODE_RETURN case from main codegen function
- Inline codegen_return logic directly into gen_return_var
This completes the modernization of return node handling to exclusively
use variable-sized nodes throughout the compiler pipeline.
Co-authored-by: Claude <noreply@anthropic.com>
- Remove conditional var_nodes_enabled logic from new_yield
- Delete unused new_yield_var function and forward declaration
- Move NODE_YIELD handling to NODE_VARIABLE branch in call_with_block
- Remove traditional NODE_YIELD case from main codegen function
- Inline codegen_yield logic directly into gen_yield_var
This completes the modernization of yield node handling to exclusively
use variable-sized nodes throughout the compiler pipeline.
Co-authored-by: Claude <noreply@anthropic.com>
- update NODE_ZSUPER to use mrb_ast_super_node instead of empty mrb_ast_zsuper_node
- convert new_super and new_zsuper to always create variable-sized nodes
- update call_with_block to handle NODE_SUPER/NODE_ZSUPER wrapped in NODE_VARIABLE
- inline codegen_super and codegen_zsuper into their gen_*_var functions
- remove traditional NODE_SUPER and NODE_ZSUPER cases from codegen
Co-authored-by: Claude <noreply@anthropic.com>
Remove var_nodes_enabled conditions from new_dot2 and new_dot3 functions
and inline variable-sized node creation logic directly. Clean up obsolete
codegen paths by removing case NODE_DOT2 and NODE_DOT3 from traditional
codegen() and removing unused codegen_dot2 and codegen_dot3 functions.
Update gen_dot2_var and gen_dot3_var to use proper DOT2/DOT3_NODE macros
and generate OP_RANGE_INC/EXC instructions directly.
Co-authored-by: Claude <noreply@anthropic.com>
Remove var_nodes_enabled condition from new_sym function and inline
new_sym_var directly. Clean up obsolete codegen paths by removing
case NODE_SYM from traditional codegen() and inlining codegen_sym
into variable-sized node handler. Remove unused new_sym_original
helper function.
Co-authored-by: Claude <noreply@anthropic.com>
Complete the conversion of boolean literal nodes by:
1. Convert new_true to always use variable-sized nodes and inline new_true_var
directly into the function, eliminating function call overhead
2. Remove obsolete NODE_TRUE case from traditional codegen() and inline
codegen_true function into gen_true_var for cleaner code
3. Apply the same optimizations to new_false - inline new_false_var and
remove obsolete NODE_FALSE case and codegen_false function
4. Clean up unused functions and forward declarations
Both true and false literals now always use the variable-sized node path
with direct OP_LOADT/OP_LOADF instruction generation, eliminating
conditional branching and function call overhead.
Co-authored-by: Claude <noreply@anthropic.com>
Temporarily revert new_call to avoid issues with assignment to method calls
like self[idx] = value causing "unknown lhs" errors. The function now always
uses traditional cons-list NODE_CALL/NODE_SCALL nodes instead of variable-sized
nodes to maintain compatibility with existing assignment codegen.
Co-authored-by: Claude <noreply@anthropic.com>
This completes the conversion of NODE_HEREDOC from traditional cons-list
nodes to variable-sized nodes by:
1. Modified new_heredoc to always use variable-sized nodes with embedded
parser_heredoc_info struct and updated function signature to return
info pointer via output parameter
2. Fixed parsing_heredoc_info to handle NODE_VARIABLE wrapper detection
and return address of embedded struct
3. Updated gen_heredoc_var to use embedded info structure for codegen
4. Removed obsolete NODE_HEREDOC case and codegen_heredoc function from
traditional codegen path
5. Replaced codegen_heredoc_str wrapper with direct codegen_cons_list_string
calls for cleaner semantic naming
Co-authored-by: Claude <noreply@anthropic.com>
Remove var_nodes_enabled condition from new_dsym function, completing the
transition to variable-sized nodes for dynamic symbol processing.
Fix gen_dsym_var function to properly extract the dsym node using the
dsym_node() macro and simplify the codegen pattern to match traditional
codegen_dsym behavior.
Remove unused codegen_dsym function and its corresponding NODE_DSYM case
from the main codegen switch, cleaning up dead traditional codegen paths.
Co-authored-by: Claude <noreply@anthropic.com>
Remove unused codegen_words and codegen_symbols functions along with their
corresponding cases in the main codegen switch. These became dead code
after converting new_words and new_symbols to always use variable-sized nodes.
Also remove var_nodes_enabled conditions from new_words and new_symbols,
completing the transition to always using variable-sized nodes for word and
symbol arrays.
Co-authored-by: Claude <noreply@anthropic.com>
Add helper functions to simplify string representation creation in cons format:
- new_str_rep(p, str, len): creates cons(length, string_ptr)
- new_str_tok(p): creates string representation from current token
- new_str_empty(p): creates empty string representation
This reduces code duplication and improves readability by replacing
verbose patterns like cons(int_to_node(toklen(p)), (node*)strndup(...))
with cleaner helper function calls.
Co-authored-by: Claude <noreply@anthropic.com>