mruby-compiler: add no_return_value context flag for script optimization

when running scripts via mruby -e or file, return values are unused.
this adds a no_return_value flag to skip generating unnecessary code.

for parallel assignment like a,b = 1,2:
- before: 18 bytes, 5 registers, creates temporary array
- after: 5 bytes, 3 registers, direct register assignment, no RETURN

the flag is set only for the main program, not for libraries loaded
with -r option. eval() and mirb continue returning values correctly.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-12-21 09:16:34 +09:00
parent fb5d966a45
commit 613b03ac18
5 changed files with 3848 additions and 3895 deletions
+2
View File
@@ -33,6 +33,7 @@ typedef struct mrb_ccontext {
mrb_bool keep_lv:1;
mrb_bool no_optimize:1;
mrb_bool no_ext_ops:1;
mrb_bool no_return_value:1;
const struct RProc *upper;
size_t parser_nerr;
@@ -125,6 +126,7 @@ struct mrb_parser_state {
mrb_bool no_optimize:1;
mrb_bool capture_errors:1;
mrb_bool no_ext_ops:1;
mrb_bool no_return_value:1;
const struct RProc *upper;
struct mrb_parser_message error_buffer[10];
struct mrb_parser_message warn_buffer[10];