Commit Graph

17616 Commits

Author SHA1 Message Date
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
Yukihiro "Matz" Matsumoto a11a3f2fe6 mruby-compiler: implement NODE_BIGINT for optimal integer handling
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>
2025-10-03 19:46:11 +09:00
Yukihiro "Matz" Matsumoto 7f5904ea94 mruby-bigint: normalize mrb_bint_new_str return value
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>
2025-10-03 19:46:10 +09:00
Yukihiro "Matz" Matsumoto 931c41aa94 mruby-compiler: clean up void_expr_error for variable-sized nodes only
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>
2025-10-03 19:46:10 +09:00
Yukihiro "Matz" Matsumoto c6af438500 mruby-compiler: simplify false_always to handle only variable-sized nodes
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>
2025-10-03 19:46:10 +09:00
Yukihiro "Matz" Matsumoto 4931570f0c mruby-compiler: convert new_nil and new_self to always use variable-sized nodes
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>
2025-10-03 19:46:10 +09:00
Yukihiro "Matz" Matsumoto b5a4b3a7a7 mruby-compiler: convert new_and and new_or to always use variable-sized nodes
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>
2025-10-03 19:46:10 +09:00
Yukihiro "Matz" Matsumoto b325ad991b mruby-compiler: complete NODE_ALIAS codegen cleanup
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>
2025-10-03 19:46:10 +09:00
Yukihiro "Matz" Matsumoto e0e3c14a69 mruby-compiler: convert new_float to always use variable-sized nodes
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>
2025-10-03 19:46:09 +09:00
Yukihiro "Matz" Matsumoto 47857cea30 mruby-compiler: convert new_return to always use variable-sized nodes
- 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>
2025-10-03 19:46:09 +09:00
Yukihiro "Matz" Matsumoto 2000ef7820 mruby-compiler: convert new_yield to always use variable-sized nodes
- 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>
2025-10-03 19:46:09 +09:00
Yukihiro "Matz" Matsumoto e02bb13d00 mruby-compiler: convert NODE_SUPER and NODE_ZSUPER to always use variable-sized nodes
- 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>
2025-10-03 19:46:09 +09:00
Yukihiro "Matz" Matsumoto 81311671c5 mruby-compiler: convert new_dot2 and new_dot3 to always use variable-sized nodes
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>
2025-10-03 19:46:09 +09:00
Yukihiro "Matz" Matsumoto d239fcde48 mruby-compiler: convert new_sym to always use variable-sized nodes
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>
2025-10-03 19:46:09 +09:00
Yukihiro "Matz" Matsumoto e19d13f093 mruby-compiler: convert new_true and new_false to always use variable-sized nodes
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>
2025-10-03 19:46:09 +09:00
Yukihiro "Matz" Matsumoto 4dafdc72fc mruby-compiler: revert new_call function to always use traditional cons-list nodes
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>
2025-10-03 19:46:08 +09:00
Yukihiro "Matz" Matsumoto 87de799cd5 mruby-compiler: convert node_heredoc to variable-sized nodes and cleanup
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>
2025-10-03 19:46:08 +09:00
Yukihiro "Matz" Matsumoto 1e52b3d421 mruby-compiler: convert dynamic symbols to always use variable-sized nodes
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>
2025-10-03 19:46:08 +09:00
Yukihiro "Matz" Matsumoto 62a16c7a04 mruby-compiler: remove traditional word/symbol array codegen paths
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>
2025-10-03 19:46:08 +09:00
Yukihiro "Matz" Matsumoto c9583bfd4b mruby-compiler: introduce helper functions for string representation cons creation
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>
2025-10-03 19:46:08 +09:00
Yukihiro "Matz" Matsumoto 8034f71a5e mruby-compiler: replace NODE_LITERAL_DELIM with (0 . 0) pattern
NODE_LITERAL_DELIM was only used as a marker in literal arrays.
Replace it with a (0 . 0) pattern which cannot conflict with
empty strings (which would be (0 . ptr) with non-NULL ptr).
This allows removing NODE_LITERAL_DELIM from the node type enum.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:08 +09:00
Yukihiro "Matz" Matsumoto 5447e2005c mruby-compiler: remove unused NODE_DREGX_ONCE node type
NODE_DREGX_ONCE was defined but never used in the codebase. No creation
functions, no codegen cases, and no parser rules reference this node type.

Removed:
- NODE_DREGX_ONCE enum value
- struct mrb_ast_dregx_once_node definition
- dregx_once_node() macro
- DREGX_ONCE_NODE_LIST() and DREGX_ONCE_NODE_OPTIONS() macros

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:07 +09:00
Yukihiro "Matz" Matsumoto 815bac77fb mruby-compiler: rename NODE_DSTR/NODE_DXSTR to NODE_STR/NODE_XSTR
Rename NODE_DSTR to NODE_STR and NODE_DXSTR to NODE_XSTR to reflect
that all strings now use dynamic (cons list) representation. Also
rename all associated functions for consistency:

- gen_dstr_var() -> gen_str_var()
- gen_dxstr_var() -> gen_xstr_var()
- codegen_heredoc_dstr() -> codegen_heredoc_str()
- codegen_dxstr() -> codegen_xstr()

The "D" prefix is no longer meaningful since all strings use the
variable-sized cons list format ((len . ptr) (-1 . node)...).

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:07 +09:00
Yukihiro "Matz" Matsumoto 5f43603c52 mruby-compiler: remove obsolete NODE_STR and NODE_XSTR node types
Remove NODE_STR and NODE_XSTR enum values and all associated code as these
traditional node types are no longer used with the new cons list string
representation. The compiler now exclusively uses the cons list format
((len . str) (-1 . node)...) for all string types.

- remove NODE_STR and NODE_XSTR from node_type enum in node.h
- remove NODE_STR and NODE_XSTR cases from codegen.c switch statements
- remove NODE_STR and NODE_XSTR cases from parse.y codedump functions
- remove unused codegen_str(), codegen_xstr(), and gen_xstr_var() functions
- update codegen_dregx() to use cons list string handling instead of
  checking for obsolete NODE_STR
- preserve str_dump() function wrapped in #if 0 for future codedump updates
- update comment in node.h to reflect current node types

NODE_DSTR remains available for dynamic string interpolation. All string
functionality continues to work via the cons list representation and
variable-sized node implementations.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:07 +09:00
Yukihiro "Matz" Matsumoto 6ad00d2e6e mruby-compiler: refactor string representation to cons list format and fix interpolation
- change AST string representation from traditional node list to cons list
  format where elements are either (len . str) for literals or (-1 . node)
  for expressions
- implement codegen_cons_list_string() to handle new string format across
  all string types (heredoc, dstr, xstr, dxstr, literal arrays)
- fix heredoc interpolation producing garbage by wrapping expressions as
  (-1 . node) in parse.y heredoc_body rule instead of pushing directly
- fix backtick commands not executing in NOVAL mode by modifying
  gen_dxstr_var and codegen_xstr to always generate OP_SSEND calls
- update gen_literal_array() to properly handle cons list format with
  NODE_LITERAL_DELIM separators for %w[] and %i[] arrays
- refactor all dstr/dxstr/dregx variable node generators to use new format
- both simple `cmd` and dynamic `cmd #{var}` backticks now execute
  correctly even when result is discarded
- all mrbtest cases now pass (1730/1731)

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:07 +09:00
Yukihiro "Matz" Matsumoto 90c9525fd7 mruby-compiler: refactor lexer to always return cons lists, move variable node generation to grammar actions
Previously the lexer dynamically called new_regx() and new_str() functions
which created different node types based on the var_nodes_enabled flag,
causing complexity in grammar actions and requiring dynamic dispatch handling.

This change simplifies the architecture by:
- Making lexer always return traditional cons structures:
  - tREGEXP: (NODE_REGX . (pattern . (flags . encoding)))
  - tSTRING: (NODE_STR . (string . length))
- Moving variable node generation to grammar actions where it belongs
- Simplifying new_dregx() to always receive traditional cons structures
- Updating mrb_ast_dregx_node to store the whole regx structure

This eliminates dynamic dispatch complexity and centralizes variable node
creation in grammar actions, making the code flow cleaner and more predictable.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:07 +09:00
Yukihiro "Matz" Matsumoto ff7c94429b mruby-compiler: remove traditional node generation from new_nth_ref
Remove if (!p->var_nodes_enabled) branch from new_nth_ref function
to use variable-sized nodes exclusively for numbered regex references.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:07 +09:00
Yukihiro "Matz" Matsumoto 8335b7a0a2 mruby-compiler: remove traditional node generation from new_back_ref
Remove if (!p->var_nodes_enabled) branch from new_back_ref function
to use variable-sized nodes exclusively for regex backreferences.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:06 +09:00
Yukihiro "Matz" Matsumoto 90436a4078 mruby-compiler: remove traditional node generation from new_dxstr
Remove if (!p->var_nodes_enabled) branch from new_dxstr function
to use variable-sized nodes exclusively for dynamic execution strings.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:06 +09:00
Yukihiro "Matz" Matsumoto 914f817e1c mruby-compiler: update new_undef and new_negate to remove traditional node paths
- Modified new_undef to accept node *syms list instead of single mrb_sym
- Simplified gen_undef_var to directly pass symbol list
- Removed traditional node generation path from new_negate
- Both functions now use variable-sized nodes exclusively

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:06 +09:00
Yukihiro "Matz" Matsumoto 259a388cbe mruby-compiler: fix new_undef function to handle symbol lists properly
- Update new_undef function signature to accept node list instead of single symbol
- Fix grammar rule to properly construct undef nodes from symbol lists
- Simplify gen_undef_var function to directly pass symbol list to codegen
- Support multiple symbols in single undef statement (e.g., undef foo, bar)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 19:46:06 +09:00