Commit Graph

17729 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto f6eb2e7c8e mruby-task: use MRB_SYM() for method name symbols
Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:22 +09:00
Yukihiro "Matz" Matsumoto b6179bb0b4 mruby-set: add spec.summary
Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:22 +09:00
Yukihiro "Matz" Matsumoto 8ee1e8d184 full-core.gembox: exclude mruby-sleep from gembox
Since full-core.gembox includes mruby-task (which defines
MRB_USE_TASK_SCHEDULER), mruby-sleep's implementation becomes disabled
via conditional compilation. Exclude mruby-sleep from full-core.gembox
to avoid loading an effectively empty gem. mruby-task provides
task-aware sleep/usleep implementations instead.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:21 +09:00
Yukihiro "Matz" Matsumoto ee398ddcdc mruby-task: refactor sleep implementation to use microseconds
Rename sleep_ms_impl to sleep_us_impl as the base implementation,
providing true microsecond precision for usleep. sleep_ms_impl now
simply calls sleep_us_impl with converted values.

This ensures usleep provides proper microsecond granularity instead of
losing precision by converting to milliseconds.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:21 +09:00
Yukihiro "Matz" Matsumoto ef4a14996a mruby-task: add usleep method
Add usleep method that provides task-aware sleep behavior with
microsecond precision. This overrides mruby-sleep's usleep when both
gems are loaded.

The implementation converts microseconds to milliseconds and uses the
same sleep_ms_impl as sleep_ms, providing cooperative sleep within
tasks and signal-safe blocking sleep otherwise.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:21 +09:00
Yukihiro "Matz" Matsumoto c7e0312c65 mruby-task: fix sleep to work correctly with sigalrm timer
The sleep implementation now properly handles signal interruptions from
the sigalrm timer by using nanosleep with retry loop instead of usleep.

This commit also makes sleep override mruby-sleep's implementation when
both gems are loaded, providing task-aware sleep behavior.

Changes:
- replace usleep with nanosleep for signal-safe blocking sleep
- add retry loop to handle eintr interruptions
- use mrb_define_private_method_id for both sleep and sleep_ms
- add time.h and presym.h headers

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:21 +09:00
Yukihiro "Matz" Matsumoto f58051c48e mruby-task: fix context switching and sleep implementation
This commit fixes several critical issues in the task scheduler:

1. Context switching now properly saves and restores ci/cci pointers
   and sets prev links, following the fiber implementation pattern.
   This prevents crashes when tasks complete.

2. Sleep implementation now falls back to blocking sleep (usleep/Sleep)
   when not in task context, fixing standalone sleep calls.

3. Removed unused functions q_find_task and task_free to eliminate
   compiler warnings.

4. Added platform-specific headers for sleep functions on Unix/Windows.

5. Enabled HAL initialization which was previously commented out.

6. Added SA_RESTART flag to SIGALRM handler to prevent timer from
   interrupting IO syscalls, fixing mrbtest IO.popen failures.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:21 +09:00
Yukihiro "Matz" Matsumoto 47dfb771cf mruby-task: fix cooperative task yielding with Task.pass
this patch fixes several critical issues in the task scheduler:

1. vm integration for computed goto dispatch mode:
   - added task switching check in NEXT macro for computed goto
   - previous implementation only worked with switch dispatch mode
   - now Task.pass properly yields control to other tasks

2. task lifecycle tracking:
   - added 'started' flag to mrb_task structure
   - fixed first-run detection to avoid popping callinfo multiple times
   - vm overwrites context status during execution, making it unreliable

3. removed mrblib/task.rb:
   - empty Ruby method stubs were overriding C implementations
   - all task methods now properly implemented in C

4. cleaned up task scheduler loop:
   - proper task completion detection using switching flag
   - round-robin scheduling for tasks at same priority
   - clean scheduler exit when all tasks complete

tasks now cooperatively yield with Task.pass and complete cleanly.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:21 +09:00
Yukihiro "Matz" Matsumoto b7b06a0857 mruby-task: implement posix hal for timer and interrupt control
add hardware abstraction layer with posix implementation:
- setitimer: generates periodic sigalrm for tick-based scheduling
- signal handler: calls mrb_tick on each timer interrupt
- sigprocmask: enables/disables interrupts by blocking sigalrm
- usleep: idle cpu implementation for posix platforms

the hal is initialized during gem init and starts the periodic
timer automatically. non-posix platforms get stub implementations.

tick period is configurable via MRB_TICK_UNIT (default 4ms).

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:21 +09:00
Yukihiro "Matz" Matsumoto e3120cd7c0 mruby-task: implement ruby api for task management
implement task class methods:
- Task.new: creates task with block, optional name and priority
- Task.current: returns currently running task
- Task.list: returns array of all tasks in all queues
- Task.pass: yields to other tasks voluntarily
- Task.get: finds task by name

implement task instance methods:
- status: returns task status as symbol (:DORMANT, :READY, etc)
- name/name=: get/set task name
- priority/priority=: get/set priority with queue re-sorting
- suspend/resume: manual task suspension and resumption
- terminate: forcibly terminate task and wake joiners
- join: wait for task completion

the api provides full control over task lifecycle and scheduling
from ruby code while maintaining thread safety through irq protection.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:20 +09:00
Yukihiro "Matz" Matsumoto 9ea37745ac vm.c: integrate task scheduler with vm dispatch loop
modify END_DISPATCH macro to check for context switches after each
bytecode instruction. when switching flag is set or task has stopped,
return from mrb_vm_exec to yield control back to scheduler.

add TASK_STOP macro to mark task completion in OP_STOP instruction.
this allows scheduler to detect when tasks finish execution.

the integration enables cooperative preemption at bytecode granularity
while maintaining compatibility with non-task builds.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:20 +09:00
Yukihiro "Matz" Matsumoto 1b69b33a4e mruby-task: implement scheduler algorithm and sleep operations
implement core scheduling components:
- mrb_tick: tick handler for timeslice countdown and sleep wakeup
- mrb_tasks_run: main scheduler loop with context switching
- sleep operations: sleep_ms_impl, sleep, sleep_ms
- hal stub implementations for compilation (temporary)

the scheduler uses tick-based preemption with round-robin at same
priority. sleeping tasks wake when their tick count expires.
completed tasks move to dormant queue and wake any waiting joiners.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:20 +09:00
Yukihiro "Matz" Matsumoto edfaf4af99 mruby-task: implement queue management and task lifecycle
add priority queue operations:
- q_get_queue: select queue based on task status
- q_insert_task: priority-based insertion (lower number = higher priority)
- q_delete_task: remove task from queue
- q_find_task: search for task in all queues

add task lifecycle functions:
- task_alloc: allocate and zero-initialize task structure
- task_free: free task and associated context (stack + callinfo)
- task_init_context: initialize execution context similar to fiber
  * allocate vm stack with dynamic sizing based on irep->nregs
  * allocate callinfo stack
  * setup callinfo with proc and target class
  * set context status to MRB_TASK_CREATED

this completes phase 2 of the task scheduler implementation.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:20 +09:00
Yukihiro "Matz" Matsumoto a0655615c9 mruby-task: rename mrb_tcb to mrb_task for clarity
replace confusing "tcb" (task control block) terminology with clearer
"mrb_task" naming:
- struct mrb_tcb -> struct mrb_task
- update mrb_task_state to use mrb_task pointers
- rename internal functions to avoid naming conflicts:
  - mrb_task_new -> task_alloc
  - mrb_task_free (lifecycle) -> task_free
- update field names for clarity:
  - tcb_join -> join
  - task (ruby object) -> self
  - value (return value) -> result

this makes the code more readable and follows mruby naming conventions
like mrb_context, mrb_irep, etc.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:20 +09:00
Yukihiro "Matz" Matsumoto dda60ca719 mruby-task: add core data structures to mrb_state
extend mrb_fiber_state enum with task-specific states:
- MRB_TASK_CREATED: task context initialized
- MRB_TASK_STOPPED: task execution finished

add mrb_task_state structure to mrb_state:
- task queues array (dormant, ready, waiting, suspended)
- tick counter for scheduling
- wakeup_tick for sleep timing
- switching flag for context switches

remove duplicate mrb_task_state definition from task.h since it is
now defined in include/mruby.h. all changes guarded by
MRB_USE_TASK_SCHEDULER for zero overhead when disabled.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:20 +09:00
Yukihiro "Matz" Matsumoto ae0d7a0c16 mruby-task: add initial gem structure with api skeleton
create mruby-task gem directory structure with:
- mrbgem.rake: gem specification with task scheduler define
- include/task.h: tcb structure and core scheduler declarations
- src/task.c: implementation skeleton with empty method stubs
- mrblib/task.rb: ruby api documentation and task::stat class

all methods have empty bodies ready for implementation.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:20 +09:00
Yukihiro "Matz" Matsumoto 00667c5e09 Merge pull request #6638 from mruby/dependabot/github_actions/github/codeql-action-4 2025-10-08 23:54:30 +09:00
Yukihiro "Matz" Matsumoto 4982997b04 mruby-compiler: fix colon3 constant lookup; fix #6635, #6636
The bug was in codegen_colon3 which used genop_2(OP_OCLASS, sym)
treating OCLASS as BB format, but OCLASS is B format that only
loads ::Object without a symbol parameter. The fix uses the correct
two-instruction pattern: OCLASS to load Object class, then GETMCNST
to retrieve the constant from it.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:52:32 +09:00
dependabot[bot] 768ea3afbe build(deps): bump github/codeql-action from 3 to 4
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3 to 4.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: '4'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-10-08 14:01:47 +00:00
Yukihiro "Matz" Matsumoto 01091984e7 mruby-compiler: add explicit cast to fix c++ compilation warning
cast uint8_t node_type field to enum node_type to satisfy c++ stricter
type checking while maintaining memory efficiency of 1-byte storage.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-04 10:02:02 +09:00
Yukihiro "Matz" Matsumoto 29e5be08e1 tools/lrama: add missing newline at end of yacc.c template
posix requires text files to end with a newline character.
pre-commit hook detected the missing newline and this fixes it.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-04 07:56:37 +09:00
Yukihiro "Matz" Matsumoto 5bc3cd0abd mruby-compiler: update node comments from cons-style to struct-style
replace obsolete cons-style comments like /* (:begin prog...) */ with
modern struct-style comments like /* struct: begin_node(body) */ to
reflect current variable-sized node implementation.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:28 +09:00
Yukihiro "Matz" Matsumoto 6919e857a6 hash.c: initialize local variables to suppress warnings
initialize hash_code and eql variables to avoid uninitialized variable
warnings from compilers.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:28 +09:00
Yukihiro "Matz" Matsumoto 9156451652 mruby-compiler: fix c++ compilation error in node_hash case
add braces around node_hash case in dump_node() to fix variable
initialization crossing case labels error when compiling with c++.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:28 +09:00
Yukihiro "Matz" Matsumoto 2495cd3c52 mruby-compiler: simplify node allocation in parse.y with helper
introduce new_node() helper and NEW_NODE() macro to eliminate repetitive
allocation and header initialization pattern across 64 new_* functions.

before: each function required 2-3 lines for allocation:
  struct mrb_ast_xxx_node *n = (...)parser_palloc(p, sizeof(...));
  init_var_header(&n->header, p, NODE_XXX);

after: single line with type-safe macro:
  struct mrb_ast_xxx_node *n = NEW_NODE(xxx, NODE_XXX);

saves approximately 128 lines while maintaining readability and providing
central point for future allocation logic changes.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:28 +09:00
Yukihiro "Matz" Matsumoto 149dd03619 mruby-compiler: improve codegen.c comments to reflect current state
Remove migration-stage "Phase" and "Group" references from comments,
replacing them with descriptions of actual code organization.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:27 +09:00
Yukihiro "Matz" Matsumoto 209c81e464 mruby-compiler: improve node.h comments to reflect current state
replaced migration-related comments (Phase 1/2/3, Group 8-16) with
descriptive comments that explain the current structure organization.
these phase/group comments were artifacts from incremental development
and no longer serve a meaningful purpose in the production codebase.

updated comments to describe what each section contains:
- "Literal value nodes" instead of "Phase 1 Variable Node Structures"
- "Expression and operation nodes" instead of "Phase 2..."
- "Control flow and definition nodes" instead of "Phase 3..."
- removed "Group N:" prefixes and replaced with descriptive headers

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:27 +09:00
Yukihiro "Matz" Matsumoto f2957904aa mruby-compiler: remove unused mrb_ast_when_node structure
removed struct mrb_ast_when_node and when_node() casting macro which
were never actually used. NODE_CASE uses cons lists to represent
when clauses, not dedicated when_node structures. the structure
definition and macro were dead code left over from earlier design.

case/when implementation uses: cons(cons(conditions, body), next_when)
where each when clause is a cons cell in a list, not a typed node.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:27 +09:00
Yukihiro "Matz" Matsumoto ee80a2ef26 mruby-compiler: replace accessor macros with direct member access
replaced all *_NODE_* accessor macros (e.g., SYM_NODE_VALUE,
INT_NODE_VALUE, CALL_NODE_METHOD) with direct member access using
casting macros (e.g., sym_node(n)->symbol, int_node(n)->value,
call_node(n)->method_name). this eliminates an unnecessary abstraction
layer and improves code readability by making field access explicit.

the accessor macros simply wrapped cast_func(n)->field, providing no
real benefit. direct member access makes it clear what field is being
accessed and reduces macro indirection.

affected files:
- node.h: removed ~100 accessor macro definitions
- codegen.c: replaced 19 macro uses with direct access
- parse.y: replaced 152 macro uses with direct access

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