Commit Graph

17684 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 1cb8d73ede mruby-compiler: optimize splat of literal arrays in args/literals
- Skip no-op splats of empty array literals (`*[]` / zarray) in
  call argument generation and array literal codegen.
- Inline non-empty literal splat arrays without inner splats
  (e.g. `*[a,b]`) as regular positional args/elements, avoiding
  building a temporary array and ARYCAT.

This removes unnecessary `LOADNIL` + `ARRAY 0` + `ARYCAT` sequences
(e.g. `mruby -ve 'p *[]'`) and reduces temporary allocations while
preserving semantics and evaluation order. Falls back to the generic
path when nested splats are present or counts exceed fixed-arity.

No behavior change intended; only codegen improvements.

Co-authored-by: Codex <codex@openai.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 a49e4db4b6 mruby-compiler: rename gen_*_var functions to codegen_*
Now that all cons-list based codegen_* functions have been removed,
rename the gen_*_var functions to use the consistent codegen_* prefix.
This affects 70 functions and improves code clarity by establishing
a single naming convention for all code generation functions.

- gen_scope_var renamed to codegen_scope_node to avoid conflict with codegen_scope type
- All other gen_*_var functions renamed to codegen_* (removing _var suffix)
- Updated all function calls throughout codegen.c

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 40f6e5b8f5 mruby-compiler: remove unused mrb_ast_method_node structure and related code
Remove mrb_ast_method_node structure definition, accessor macro,
and field accessor macro. This structure had no corresponding
node type enum and was never used in the parser or codegen.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:23 +09:00
Yukihiro "Matz" Matsumoto cdd94afa3a mruby-compiler: remove unused NODE_TO_ARY node type and related code
Remove NODE_TO_ARY enum value, structure definition, accessor macro,
and field accessor macro. This node type was never used in the parser
or codegen, despite having complete supporting infrastructure.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:23 +09:00
Yukihiro "Matz" Matsumoto 33562e0895 mruby-compiler: remove unused NODE_SVALUE node type and related code
Remove NODE_SVALUE enum value, structure definition, accessor macro,
and accessor function. This node type was never used in the parser
or codegen, despite having supporting infrastructure.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:23 +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
Yukihiro "Matz" Matsumoto dc67cb795f mruby-compiler: inline codegen_regx into gen_regx_var to eliminate cons list
Remove the last cons list dependency in codegen.c by inlining codegen_regx()
directly into gen_regx_var(). This eliminates the need to create temporary
cons list structures and directly accesses regex pattern, flags, and
encoding from the variable-sized node structure.

Changes:
- Inline codegen_regx() logic into gen_regx_var()
- Remove codegen_regx() function entirely
- Access regex data directly from mrb_ast_regx_node fields
- Eliminate temporary cons list node creation

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:22 +09:00
Yukihiro "Matz" Matsumoto fc7e177190 mruby-compiler: fix indentation and remove duplicate code in dump_args
Reduce indentation levels by 1 throughout dump_args() for better
formatting consistency and remove duplicated post_mandatory_args
section that was incorrectly placed after keyword_args processing.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:22 +09:00
Yukihiro "Matz" Matsumoto 5cb1214aca mruby-compiler: refactor dump_prefix to use extracted line numbers
Refactor dump_prefix() to extract line numbers from variable-sized node
headers instead of attempting to retrieve them from node parameters.
Also fix potential segmentation fault in get_node_type() by adding
defensive pointer validation.

Key changes:
- Update dump_prefix() signature to accept lineno parameter directly
- Extract line number once at start of mrb_parser_dump() from node header
- Update all helper functions (dump_locals, dump_cpath, dump_args, etc.)
- Systematically update all dump_prefix calls throughout parser dump code
- Add pointer validation in get_node_type() to prevent invalid memory access

This provides accurate line number information in debug output and
eliminates potential crashes from corrupted pointers.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:22 +09:00
Yukihiro "Matz" Matsumoto 39cf3038c6 mruby-compiler: remove redundant fields from call node structure
Remove argc, has_kwargs, has_block, and reserved fields from
mrb_ast_call_node since this information can be determined from the
callargs structure at runtime. Simplify new_call() and call_with_block()
functions to eliminate field analysis during parsing.

Add callargs_empty() helper function to check for empty arguments and
update gen_if_var() to use it instead of accessing removed argc field.

This change reduces memory usage per call node while maintaining full
functionality through runtime analysis of the callargs structure.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:22 +09:00
Yukihiro "Matz" Matsumoto b3d501e98c mruby-compiler: remove unused NODE_CALLARGS node type
Remove NODE_CALLARGS enum value and parser dump case which are no longer
used in the codebase. The struct mrb_ast_callargs exists and is actively
used by new_callargs(), but it doesn't have a mrb_ast_var_header and is
never assigned the NODE_CALLARGS node type.

This cleanup removes dead code from the enum node_type and eliminates
an unreachable parser dump case, since no nodes are ever created with
NODE_CALLARGS type.

The callargs functionality remains fully intact - only the unused enum
value and unreachable dump case are removed.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:22 +09:00
Yukihiro "Matz" Matsumoto 0c25c0d95f mruby-compiler: refactor gen_string to use single loop
Eliminate code duplication in gen_string by using a single loop with
a first-element flag instead of separate first element processing.

The previous structure had ~20 lines of duplicated string literal and
expression processing logic. The refactored version uses a unified loop
that handles concatenation only for non-first elements, reducing code
duplication and improving maintainability.

Functionality remains identical - all string interpolation, regex
patterns, and heredoc processing work correctly.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:22 +09:00
Yukihiro "Matz" Matsumoto fdfdedaa4f mruby-compiler: rename codegen_cons_list_string() to gen_string()
Rename the overly long and poorly descriptive codegen_cons_list_string()
function to gen_string() which is more concise and follows the existing
naming convention where gen_ prefix indicates code generation functions.

This function generates string bytecode from cons-list structures
containing mixed string literals and expressions for interpolation,
used in string interpolation, regex patterns, and heredocs.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:21 +09:00
Yukihiro "Matz" Matsumoto 821b989b33 mruby-compiler: update mrb_parser_dump for variable-sized nodes
Modernize the parser dump functionality to support the post-NODE_VARIABLE
hybrid AST architecture with both variable-sized nodes and traditional
cons-list nodes.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:21 +09:00
Yukihiro "Matz" Matsumoto 6a3e26cf7a mruby-compiler: remove NODE_VARIABLE wrapper and modernize AST handling
This removes the NODE_VARIABLE enum and associated wrapper system, updating
the parser and codegen to work directly with variable-sized AST nodes.

Key changes:
- Removed NODE_VARIABLE from node.h enum
- Updated parser functions to handle direct variable-sized nodes
- Fixed codegen() main dispatch to detect variable-sized nodes directly
- Added helper functions for node type detection and header access
- Updated all parser and codegen functions to work with modern AST structure

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:21 +09:00
Yukihiro "Matz" Matsumoto 9a1a0dac54 mruby-compiler: standardize mrb_ast_var_header field name from hdr to header
Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:21 +09:00
Yukihiro "Matz" Matsumoto c30debb1f3 mruby-compiler: remove unused reserved and flags fields from mrb_ast_var_header
Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:21 +09:00
Yukihiro "Matz" Matsumoto e14bc98124 mruby-compiler: remove unused enum mrb_ast_size_class and related code
Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:21 +09:00
Yukihiro "Matz" Matsumoto 2058f7e703 mruby-compiler: remove mrb_ast_head_node and restore SET_LINENO functionality
Remove mrb_ast_head_node structure and cons_head() function while maintaining
accurate line number tracking for debugging. Replace cons_head() calls with
cons() calls but preserve NODE_VARIABLE wrapper as requested.

Key changes:
- Remove mrb_ast_head_node struct and head() macro from node.h
- Remove cons_head_gen() function and cons_head() macro from parse.y
- Update SET_LINENO macro to work with variable-sized nodes:
  SET_LINENO(c,n) (((struct mrb_ast_var_header*)(c)->cdr)->lineno = (n))
- Restore all 11 SET_LINENO calls in grammar rules to maintain accurate
  line number reporting for error messages and debugging
- Convert list1/list2/list3 and all new_*() function calls to use cons()
  instead of cons_head() while keeping NODE_VARIABLE wrapper intact

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 19:46:21 +09:00
Yukihiro "Matz" Matsumoto 72e2b8e384 mruby-compiler: update codegen to use variable node headers for debug info
Updates codegen() function to retrieve filename and line number information
directly from variable-sized node headers instead of assuming traditional
head nodes. Removes dead code for traditional cons-list nodes since all
nodes are now variable-sized.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:20 +09:00
Yukihiro "Matz" Matsumoto 76745161c5 mruby-compiler: remove var_nodes_enabled and use_variable_nodes flags
Eliminates gradual rollout feature flags that controlled variable-sized AST
nodes. Variable-sized nodes are now the default and only behavior, completing
the AST unification and simplification process.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:20 +09:00
Yukihiro "Matz" Matsumoto 511a5d13d3 mruby-compiler: remove unused NODE_KW_HASH node type
Eliminates NODE_KW_HASH enum, mrb_ast_kw_hash_node struct, gen_kw_hash_var
function, and related macros. All keyword hash functionality now unified
under NODE_HASH, completing the AST simplification.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:20 +09:00
Yukihiro "Matz" Matsumoto e871b2052c mruby-compiler: eliminate new_kw_hash function and unify hash creation
Removes the new_kw_hash function entirely and replaces all calls with
new_hash, eliminating the distinction between keyword hashes and regular
hashes in the parser. Updates codegen to handle keyword arguments directly
without intermediate cdr references.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:20 +09:00
Yukihiro "Matz" Matsumoto f993f9ac46 mruby-compiler: remove size class infrastructure and simplify node allocation
This commit eliminates the unused variable node recycling system and
size class categorization that was never utilized in practice:

- Removed size_to_class() and size_class_limit() functions
- Eliminated SIZE_CLASS_* enum and related infrastructure
- Updated init_var_header() to remove size_class parameter
- Simplified all node allocation functions to use direct parser_palloc() calls
- Replaced complex size calculations with simple sizeof() expressions
- Removed hardcoded SIZE_CLASS_MEDIUM references from new_array/new_hash/new_case

This reduces parser_state struct size by 88 bytes and simplifies allocation
logic from conditional branching to direct function calls, while maintaining
identical functionality since nodes go directly to codegen without recycling.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:20 +09:00
Yukihiro "Matz" Matsumoto d15c0271d6 mruby-compiler: remove unused variable node recycling mechanism
Remove var_free_lists, var_alloc_counts, and var_total_allocated fields
from parser_state struct as they were never used since all nodes go
directly to codegen. Replace parser_alloc_var() wrapper with direct
parser_palloc() calls throughout the codebase, reducing parser memory
footprint by 88 bytes.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:20 +09:00
Yukihiro "Matz" Matsumoto f0395a1cf7 mruby-compiler: simplify mrb_ast_hash_node from flat array to cons list
Following the same pattern as the case node upgrade (e0f07c9), this
change eliminates the complex flat array packing approach for hash nodes
in favor of simple cons-list storage. The flat array packing provided
no memory benefit since cons lists aren't recycled, while adding
unnecessary complexity to both allocation and traversal logic.

Changes:
- Simplified mrb_ast_hash_node structure from variable-sized flexible
  array to fixed-size structure with cons-list pointer
- Reduced new_hash() from complex 30+ line allocation to simple 4-line
  pattern matching array node implementation
- Updated gen_hash_var() to use cons-list iteration instead of
  interleaved array access (pairs[i*2] for key, pairs[i*2+1] for value)
- Removed HASH_NODE_LEN macro as length tracking is no longer needed
- Maintains identical functionality while reducing code complexity

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:19 +09:00
Yukihiro "Matz" Matsumoto f50936e8bd mruby-compiler: simplify mrb_ast_array_node from flat array to cons list
Replace complex flat array packing with simple cons-list storage to reduce
memory overhead and code complexity. This continues the compiler simplification
work by reverting array nodes to the original memory-efficient approach.

- Remove len/flags fields from mrb_ast_array_node structure
- Eliminate complex two-pass processing (count + copy) in new_array()
- Replace array indexing with cons-list iteration in gen_array_var()
- Reduce parser code from 30+ lines to 4 lines for array creation
- Maintain full functionality with zero test regressions

Following the same successful pattern used for mrb_ast_case_node upgrade,
this change proves that flat array packing provides no memory benefit
since cons lists aren't recycled, while adding unnecessary complexity.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:19 +09:00
Yukihiro "Matz" Matsumoto 4a04f7d4eb mruby-compiler: eliminate NODE_KW_REST_ARGS and use direct symbol markers
Replace NODE_KW_REST_ARGS wrapper nodes with direct ** symbol markers to
reduce memory overhead and simplify code structure. This continues the
compiler simplification work by unifying keyword rest arguments with
other node types while maintaining full functionality.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:19 +09:00
Yukihiro "Matz" Matsumoto 3437c33cf8 mruby-compiler: simplify NODE_KW_ARG to direct cons structure
Replace NODE_KW_ARG wrapper with direct (key . value) cons structure,
eliminating unnecessary memory overhead and access indirection.

Changes:
- Remove NODE_KW_ARG node type from enum
- Modify new_kw_arg() to return direct cons instead of wrapped structure
- Update codegen.c to use simplified access patterns (k->car->car, k->car->cdr)
- Fix new_args_tail() to handle simplified keyword argument structure
- Remove NODE_KW_ARG case from parser dump function

This reduces memory usage from 3 cons cells to 1 per keyword argument
while maintaining full functionality and following mruby's design priority
of memory efficiency over complexity.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:19 +09:00
Yukihiro "Matz" Matsumoto 4f3abb8068 mruby-compiler: simplify callargs to use direct pointer casting
Replace variable-sized NODE_VARIABLE wrapper with fixed-size struct
allocation, following the same pattern as new_args(). This eliminates
the need for NODE_VARIABLE checking and uses direct casting instead.

Changes:
- Remove mrb_ast_var_header from callargs struct
- Use parser_palloc instead of parser_alloc_var for fixed-size allocation
- Update all access points to use direct casting: (struct mrb_ast_callargs*)
- Remove unnecessary backward compatibility code for newly introduced NODE_CALLARGS

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:19 +09:00
Yukihiro "Matz" Matsumoto 8a88734e49 mruby-compiler: add default case to assignable switch statement
Add default case to the switch statement in assignable function to silence C++
compiler warnings about unhandled enumeration values. The default case documents
that other node types don't need special handling in this context.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:19 +09:00
Yukihiro "Matz" Matsumoto 95c7414a1f mruby-compiler: rename class parameters to size_class for c++ compatibility
Rename all 'class' parameter and variable names to 'size_class' to avoid
conflict with C++ class keyword. This affects function parameters in
size_class_limit, parser_alloc_var, parser_free_var, and init_var_header,
as well as local variables in all new_* node creation functions.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:18 +09:00
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