Commit b54d68dc
b54d68dc38b1Merged
Dmitry Bochkarev <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
feat: add Proc .call dispatch for poly and proc-typed receivers
Two missing code paths caused .call on a Proc to silently no-op:
-
emit_poly_builtin_dispatch (sp_RbVal receivers): added cls_id == SP_BUILTIN_PROC guard casting through sp_proc_call.
-
compile_dot_call_expr (sp_Proc * receivers): added general fallback for non-local-variable proc receivers (ivars, etc.). Previously only LocalVariableReadNode proc receivers fired.
Details
- Commit
- b54d68dc38b1
- Parent
- 3dc5bee4e5da
spinel_codegen.rbmodifiedView file
@@ -13059,6 +13059,15 @@
1305913059
return "sp_proc_call(" + compile_expr(recv) + ", (mrb_int[]){" + ca_anon + "})"1306013060
end1306113061
end13062+
rt = infer_type(recv)13063+
if rt == "proc"13064+
ca = compile_call_args(nid)13065+
if ca == ""13066+
ca = "0"13067+
end13068+
rc = compile_expr_gc_rooted(recv)13069+
return "sp_proc_call(" + rc + ", (mrb_int[]){" + ca + "})"13070+
end1306213071
""1306313072
end1306413073
@@ -18677,6 +18686,15 @@
1867718686
polyrhs = is_poly_ret == 1 ? "sp_box_int(" + polyc + ")" : polyc1867818687
emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_POLY_ARRAY) " + result_tmp + " = " + polyrhs + ";")1867918688
end18689+
if mname == "call"18690+
ca = (arg_compiled.length > 0) ? arg_compiled.join(", ") : ""18691+
if ca == ""18692+
ca = "0"18693+
end18694+
pc = "sp_proc_call((sp_Proc *)" + recv_tmp + ".v.p, (mrb_int[]){" + ca + "})"18695+
prhs = is_poly_ret == 1 ? "sp_box_int(" + pc + ")" : pc18696+
emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_PROC) " + result_tmp + " = " + prhs + ";")18697+
end1868018698
end1868118699
1868218700
# Try to compile str[i] <op> "c" as direct char comparisontest/poly_proc_call.rbaddedView file
Loading diff…
test/poly_proc_call.rb.expectedaddedView file
Loading diff…