Commit Graph

17700 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto f6edae0918 mruby-compiler: reduce unnecessary block scopes in dump_node
removed unnecessary block scopes in dump_node cases to reduce
indentation:
- NODE_SCOPE: removed scope variable, use macros directly
- NODE_HASH: removed block around hash pair iteration
- NODE_CLASS, NODE_MODULE, NODE_SCLASS: removed blocks around body dumps

improves code readability with cleaner indentation.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:27 +09:00
Yukihiro "Matz" Matsumoto 3e7078cef3 mruby-compiler: use direct member access instead of macros in codegen.c
replaced unnecessary macro usage with direct struct member access when
struct pointers are already available:
- return_n->args instead of RETURN_NODE_ARGS(return_n)
- yield_n->args instead of YIELD_NODE_ARGS(yield_n)
- for_n->var/iterable/body instead of FOR_NODE_VAR/ITERABLE/BODY(for_n)
- class_n->name/superclass/body instead of CLASS_NODE_* macros
- module_n->name/body instead of MODULE_NODE_NAME/BODY(module_n)
- sclass_n->obj/body instead of SCLASS_NODE_OBJ/BODY(sclass_n)
- hash->pairs instead of HASH_NODE_PAIRS(hash)
- call->method_name/safe_call instead of CALL_NODE_METHOD/SAFE(call)
- array->elements and an->elements instead of ARRAY_NODE_ELEMENTS macro
- splat->value instead of SPLAT_NODE_VALUE macro

improves code readability by removing unnecessary indirection.

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

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:26 +09:00
Yukihiro "Matz" Matsumoto 1ef60b6201 mruby-compiler: remove unused accessor macros from node.h
removed unused macros:
- STR_NODE_PTR, STR_NODE_LEN (unused string node accessors)
- ARGS_NODE_* series (9 macros for args node access)
- HEREDOC_NODE_NAME (unused heredoc accessor)
- MATCH_NODE_PATTERN (unused match accessor)

also fixed SDEF_NODE_OBJ to access correct field (obj instead of body).

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:26 +09:00
Yukihiro "Matz" Matsumoto f45b9ff946 mruby-compiler: remove unused string threshold constants
Removed STR_INLINE_THRESHOLD and STR_SMALL_THRESHOLD macros from node.h
as they are no longer referenced anywhere in the codebase. These appear
to be remnants from a previous string storage optimization strategy.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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