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