Commit d1954cab

d1954cab98d6Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified

Description

Merge pull request #263 from mame/pr/poly-array-slot-sized-default

fix(codegen): poly_array slot consumes sized-empty default via PolyArray

Details

Commit
d1954cab98d6
Parent
58a4b5bfd49e
Merge parent
b126003a2465

spinel_codegen.rbmodifiedView file

@@ -15049,16 +15049,23 @@
1504915049 if iv_ctor != ""
1505015050 @needs_gc = 1
1505115051 emit_raw(" " + self_arrow + ivar + " = " + iv_ctor + ";")
15052- elsif is_ptr_array_type(ivt) == 1 && is_sized_empty_array_default(expr_id_iv) == 1
15052+ elsif (ivt == "poly_array" || is_ptr_array_type(ivt) == 1) && is_sized_empty_array_default(expr_id_iv) == 1
1505315053 # `@arr = [nil] * N` with @arr already widened to
15054- # ptr_array via writer-scan. The default `*` codegen
15055- # produces an sp_IntArray that mismatches the slot
15056- # type; emit a sized PtrArray of NULLs inline.
15054+ # poly_array (or ptr_array) via writer-scan. The
15055+ # default `*` codegen produces an sp_IntArray that
15056+ # mismatches the slot type; emit a sized PolyArray
15057+ # of sp_box_nil() (or PtrArray of NULLs) inline.
1505715058 @needs_gc = 1
1505815059 cnt_e_iv = compile_arg0(expr_id_iv)
1505915060 tmp_iv = new_temp
15060- emit_raw(" sp_PtrArray *" + tmp_iv + " = sp_PtrArray_new();")
15061- emit_raw(" { mrb_int _n = " + cnt_e_iv + "; for (mrb_int _i = 0; _i < _n; _i++) sp_PtrArray_push(" + tmp_iv + ", NULL); }")
15061+ if ivt == "poly_array"
15062+ @needs_rb_value = 1
15063+ emit_raw(" sp_PolyArray *" + tmp_iv + " = sp_PolyArray_new();")
15064+ emit_raw(" { mrb_int _n = " + cnt_e_iv + "; for (mrb_int _i = 0; _i < _n; _i++) sp_PolyArray_push(" + tmp_iv + ", sp_box_nil()); }")
15065+ else
15066+ emit_raw(" sp_PtrArray *" + tmp_iv + " = sp_PtrArray_new();")
15067+ emit_raw(" { mrb_int _n = " + cnt_e_iv + "; for (mrb_int _i = 0; _i < _n; _i++) sp_PtrArray_push(" + tmp_iv + ", NULL); }")
15068+ end
1506215069 emit_raw(" " + self_arrow + ivar + " = " + tmp_iv + ";")
1506315070 elsif ivt == "poly_array" && @nd_type[expr_id_iv] == "ArrayNode"
1506415071 # Non-empty array literal `[a, b, ...]` going into a
@@ -24756,17 +24763,24 @@
2475624763 return
2475724764 end
2475824765 end
24759- # `@arr = [nil] * N` where @arr is a ptr_array slot. The
24760- # default `*` codegen produces an sp_IntArray, which mismatches
24761- # the slot type and corrupts later sp_PtrArray_set calls. Emit
24762- # a sized PtrArray pre-filled with NULLs inline so the slot
24766+ # `@arr = [nil] * N` where @arr is a poly_array (or ptr_array)
24767+ # slot. The default `*` codegen produces an sp_IntArray, which
24768+ # mismatches the slot type and corrupts later
24769+ # `sp_PolyArray_set(@arr, ...)` calls. Emit a sized PolyArray
24770+ # of sp_box_nil() (or PtrArray of NULLs) inline so the slot
2476324771 # holds the matching storage.
24764- if is_ptr_array_type(ivt) == 1 && is_sized_empty_array_default(expr_id) == 1
24772+ if (ivt == "poly_array" || is_ptr_array_type(ivt) == 1) && is_sized_empty_array_default(expr_id) == 1
2476524773 @needs_gc = 1
2476624774 cnt_e = compile_arg0(expr_id)
2476724775 tmp_arr = new_temp
24768- emit(" sp_PtrArray *" + tmp_arr + " = sp_PtrArray_new();")
24769- emit(" { mrb_int _n = " + cnt_e + "; for (mrb_int _i = 0; _i < _n; _i++) sp_PtrArray_push(" + tmp_arr + ", NULL); }")
24776+ if ivt == "poly_array"
24777+ @needs_rb_value = 1
24778+ emit(" sp_PolyArray *" + tmp_arr + " = sp_PolyArray_new();")
24779+ emit(" { mrb_int _n = " + cnt_e + "; for (mrb_int _i = 0; _i < _n; _i++) sp_PolyArray_push(" + tmp_arr + ", sp_box_nil()); }")
24780+ else
24781+ emit(" sp_PtrArray *" + tmp_arr + " = sp_PtrArray_new();")
24782+ emit(" { mrb_int _n = " + cnt_e + "; for (mrb_int _i = 0; _i < _n; _i++) sp_PtrArray_push(" + tmp_arr + ", NULL); }")
24783+ end
2477024784 emit(" " + self_arrow + sanitize_ivar(iname) + " = " + tmp_arr + ";")
2477124785 return
2477224786 end