Commit 22c47646
22c47646304aMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
codegen(promote): emit builtin-array bound-method adapters with the poly ABI
The <int_array>.method(:[]) / :[]= / :push trampolines were emitted
with the legacy mrb_int ABI, but under promote a bound method is invoked
through the poly ABI (sp_RbVal self/args/return). Calling the mrb_int
adapter through the poly cast scrambled args and return.
Emit the adapters with sp_RbVal parameters/return under promote, unboxing the index/value with sp_poly_to_i / sp_poly_to_s and boxing the result.
Fixes a regression from "invoke bound methods through the poly ABI" (builtin_array_method_capture under promote).
Default test 992/0/0 and optcarrot checksum 59662 unchanged.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 22c47646304a
- Parent
- e6f13226c1e0
src/codegen_call.cmodifiedView file
bam_done[ki][oi] = 1; const char *cast = (ki == 0) ? "" : "(mrb_int)(uintptr_t)"; const char *uncast = (ki == 0) ? "" : "(const char *)(uintptr_t)"; if (oi == 0) { if (g_promote_mode) { /* promote: bound methods are invoked through the poly ABI, so the adapter takes/returns sp_RbVal (boxing the int/string element). */ const char *boxret = (ki == 0) ? "sp_box_int_or_nil" : "sp_box_str"; const char *unbox = (ki == 0) ? "sp_poly_to_i" : "sp_poly_to_s"; const char *boxarr = (ki == 0) ? "sp_box_int_array" : "sp_box_str_array"; if (oi == 0) { buf_printf(&g_proc_protos, "static sp_RbVal _bam_%sArray_get(void *a, sp_RbVal i);\n", bk); buf_printf(&g_procs, "static sp_RbVal _bam_%sArray_get(void *a, sp_RbVal i) {\n" " return %s(sp_%sArray_get((sp_%sArray *)a, sp_poly_to_i(i)));\n}\n", bk, boxret, bk, bk); } else if (oi == 1) { buf_printf(&g_proc_protos, "static sp_RbVal _bam_%sArray_set(void *a, sp_RbVal i, sp_RbVal v);\n", bk); buf_printf(&g_procs, "static sp_RbVal _bam_%sArray_set(void *a, sp_RbVal i, sp_RbVal v) {\n" " sp_%sArray_set((sp_%sArray *)a, sp_poly_to_i(i), %s(v));\n return v;\n}\n", bk, bk, bk, unbox); } else { buf_printf(&g_proc_protos, "static sp_RbVal _bam_%sArray_push(void *a, sp_RbVal v);\n", bk); buf_printf(&g_procs, "static sp_RbVal _bam_%sArray_push(void *a, sp_RbVal v) {\n" " sp_%sArray_push((sp_%sArray *)a, %s(v));\n return %s(a);\n}\n", bk, bk, bk, unbox, boxarr); } } else if (oi == 0) { buf_printf(&g_proc_protos, "static mrb_int _bam_%sArray_get(void *a, mrb_int i);\n", bk); buf_printf(&g_procs, "static mrb_int _bam_%sArray_get(void *a, mrb_int i) {\n" " return %ssp_%sArray_get((sp_%sArray *)a, i);\n}\n", bk, cast, bk, bk);