Commit 308afd30
308afd30fb1fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +1 added · ~2 modified
Description
fix(codegen): close three boxing/dispatch gaps in splat destructure
Three follow-up fixes to PR #116 (Gemini review on the splat- destructure PR):
-
box_value_to_polyhad no array-type cases — when a poly local target received a typed array (int_array, str_array, ptr_array, …) the boxer fell through tosp_box_intand the C call mis-boxed the array pointer as an integer. Mirror the existingbox_expr_to_polyarray branches. -
emit_multi_write_target's InstanceVariableTargetNode arm emittediv = valuewithout consulting the ivar's tracked type. When the ivar was poly and the source value was native (e.g. an int from a heterogeneous array literal RHS), the assignment was C-incompatible. Box viabox_value_to_polywhen the ivar slot is poly, mirroring the LocalVariableTargetNode arm. -
compile_multi_write_splat's runtime-slice branch keyed get/ slice on str_array / float_array / ptr_array only. A poly_array RHS (e.g.a, *b = func_returning_poly) fell through tosp_IntArray_get/sp_IntArray_sliceand gcc rejected the pointer-type mismatch. Add the poly_array case and a matchingsp_PolyArray_sliceruntime helper.
test/splat_destructure_poly.rb covers the leading / middle /
trailing splat shapes against a poly_array RHS so the runtime-slice
path stays under coverage.
Refs #116
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 308afd30fb1f
- Parent
- e955bc03f20c
lib/sp_runtime.hmodifiedView file
static void sp_PolyArray_push(sp_PolyArray *a, sp_RbVal v) { if (a->len >= a->cap) { a->cap = a->cap * 2 + 1; a->data = (sp_RbVal *)realloc(a->data, sizeof(sp_RbVal) * a->cap); } a->data[a->len++] = v; }static mrb_int sp_PolyArray_length(sp_PolyArray *a) { return a->len; }static sp_RbVal sp_PolyArray_get(sp_PolyArray *a, mrb_int i) { if (i < 0) i += a->len; return a->data[i]; }static sp_PolyArray *sp_PolyArray_slice(sp_PolyArray *a, mrb_int start, mrb_int len) { if (start < 0) start += a->len; if (start < 0) start = 0; sp_PolyArray *b = sp_PolyArray_new(); if (start >= a->len || len <= 0) return b; if (start + len > a->len) len = a->len - start; for (mrb_int i = 0; i < len; i++) sp_PolyArray_push(b, a->data[start + i]); return b; }static sp_PolyArray *sp_PolyArray_dup(sp_PolyArray *a) { sp_PolyArray *b = sp_PolyArray_new(); for (mrb_int i = 0; i < a->len; i++) sp_PolyArray_push(b, a->data[i]); return b; }static void sp_PolyArray_shuffle_bang(sp_PolyArray *a) { for (mrb_int i = a->len - 1; i > 0; i--) { mrb_int j = (mrb_int)(rand() % (i + 1)); sp_RbVal t = a->data[i]; a->data[i] = a->data[j]; a->data[j] = t; } }static sp_PolyArray *sp_PolyArray_shuffle(sp_PolyArray *a) { sp_PolyArray *b = sp_PolyArray_dup(a); sp_PolyArray_shuffle_bang(b); return b; }spinel_codegen.rbmodifiedView file
Loading diff…
test/splat_destructure_poly.rbaddedView file
Loading diff…