Commit e96344d8

e96344d85616Merged

Yusuke Endoh <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(codegen): dispatch [] on poly recv that's a PtrArray

emit_poly_builtin_dispatch already handled IntArray, FloatArray, StrArray, and SymArray for [] and length on poly recv, but PtrArray was deferred — comments said the element type is class- specific (sp_ *) and a uniform poly result needed sp_box_obj which lacks a cls_id at this point.

Cast sp_PtrArray_get's void* result to mrb_int and emit it as the per-tag rhs (or wrap with sp_box_obj(..., 0) when the overall result needs to stay poly). The neutral cls_id of 0 loses concrete-class dispatch on the poly result, but callers that immediately do obj.reset-style dispatch get back the pointer they need.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
e96344d85616
Parent
c64c82b343ed

spinel_codegen.rbmodifiedView file

@@ -19056,9 +19056,12 @@
1905619056 yc = "(sp_sym)sp_IntArray_get((sp_IntArray *)" + recv_tmp + ".v.p, " + a0 + ")"
1905719057 emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_SYM_ARRAY) " + result_tmp + " = sp_box_sym(" + yc + ");")
1905819058 end
19059- # PtrArray's element type is class-specific (sp_<C> *) so a
19060- # uniform poly result needs sp_box_obj — but we don't have a
19061- # cls_id here. Defer (the issue notes this is more involved).
19059+ # PtrArray dispatch — get returns a void* which we cast to
19060+ # mrb_int when the receiver is poly. Callers that immediately
19061+ # do `<obj>.reset`-style dispatch expect a pointer back.
19062+ pc = "(mrb_int)sp_PtrArray_get((sp_PtrArray *)" + recv_tmp + ".v.p, " + a0 + ")"
19063+ prhs = is_poly_ret == 1 ? "sp_box_obj((void *)" + pc + ", 0)" : pc
19064+ emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_PTR_ARRAY) " + result_tmp + " = " + prhs + ";")
1906219065 end
1906319066 # `length` / `size` — every built-in array exposes its own
1906419067 # `_length` helper (sym_array shares IntArray's). PtrArray is