Commit 10e800f2
10e800f23460Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
codegen: add TY_PROC boxing and TY_POLY.call dispatch
emit_boxed was missing TY_PROC -> sp_box_proc, causing crashes when a proc is pushed into a poly array.
emit_call was missing a dispatch path for TY_POLY receiver + "call" method. Add: unbox the poly value to sp_Proc * and invoke sp_proc_call.
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 10e800f23460
- Parent
- a62a1ad58dfa
src/codegen.cmodifiedView file
@@ -3507,6 +3507,21 @@
35073507
}35083508
}35093509
3510+
/* poly_val.call — the poly value is a proc; unbox then call. */3511+
if (recv >= 0 && comp_ntype(c, recv) == TY_POLY &&3512+
(!strcmp(name, "call") || !strcmp(name, "()"))) {3513+
int t = ++g_tmp;3514+
emit_indent(g_pre, g_indent);3515+
buf_printf(g_pre, "sp_RbVal _t%d = ", t); emit_expr(c, recv, g_pre); buf_puts(g_pre, ";\n");3516+
buf_printf(b, "sp_proc_call((sp_Proc *)_t%d.v.p, (mrb_int[16]){", t);3517+
for (int k = 0; k < argc; k++) {3518+
if (k) buf_puts(b, ", ");3519+
if (proc_slot_is_ptr(comp_ntype(c, argv[k]))) { buf_puts(b, "(mrb_int)(uintptr_t)("); emit_expr(c, argv[k], b); buf_puts(b, ")"); }3520+
else emit_expr(c, argv[k], b);3521+
}3522+
buf_puts(b, "})");3523+
return;3524+
}35103525
/* <proc>.call(args) / .() / [] -> sp_proc_call with the mrb_int[] ABI.35113526
(A `&block`-param `.call` is handled earlier by the inline path, whose35123527
receiver name matches g_block_param_name; this is the escaped-value case.) */@@ -13795,6 +13810,7 @@
1379513810
case TY_SYMBOL: fn = "sp_box_sym"; break;1379613811
case TY_RANGE: fn = "sp_box_range"; break;1379713812
case TY_TIME: fn = "sp_box_time"; break;13813+
case TY_PROC: fn = "sp_box_proc"; break;1379813814
case TY_INT_ARRAY: fn = "sp_box_int_array"; break;1379913815
case TY_FLOAT_ARRAY: fn = "sp_box_float_array"; break;1380013816
case TY_STR_ARRAY: fn = "sp_box_str_array"; break;