Commit 58a4b5bf
58a4b5bfd49eMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #262 from mame/pr/poly-array-slot-array-literal
fix(codegen): poly_array slot consumes ArrayNode literal via PolyArray
Details
- Commit
- 58a4b5bfd49e
- Parent
- b5eafce33982
- Merge parent
- 94c29ab5b72f
spinel_codegen.rbmodifiedView file
@@ -15060,6 +15060,27 @@
1506015060
emit_raw(" sp_PtrArray *" + tmp_iv + " = sp_PtrArray_new();")1506115061
emit_raw(" { mrb_int _n = " + cnt_e_iv + "; for (mrb_int _i = 0; _i < _n; _i++) sp_PtrArray_push(" + tmp_iv + ", NULL); }")1506215062
emit_raw(" " + self_arrow + ivar + " = " + tmp_iv + ";")15063+
elsif ivt == "poly_array" && @nd_type[expr_id_iv] == "ArrayNode"15064+
# Non-empty array literal `[a, b, ...]` going into a15065+
# poly_array slot. compile_array_literal infers a typed15066+
# storage (ptr_array of one class for homogeneous obj15067+
# literals, etc.) — emit a fresh PolyArray with each15068+
# element boxed instead.15069+
@needs_gc = 115070+
@needs_rb_value = 115071+
tmp_iv = new_temp15072+
emit_raw(" sp_PolyArray *" + tmp_iv + " = sp_PolyArray_new();")15073+
elems_iv = parse_id_list(@nd_elements[expr_id_iv])15074+
ek = 015075+
while ek < elems_iv.length15076+
eid = elems_iv[ek]15077+
et = infer_type(eid)15078+
ev = compile_expr(eid)15079+
ebox = et == "poly" ? ev : box_value_to_poly(et, ev)15080+
emit_raw(" sp_PolyArray_push(" + tmp_iv + ", " + ebox + ");")15081+
ek = ek + 115082+
end15083+
emit_raw(" " + self_arrow + ivar + " = " + tmp_iv + ";")1506315084
else1506415085
# Issue #130: same poly-slot boxing as the general1506515086
# InstanceVariableWriteNode emit path (compile_expr branch).@@ -24749,6 +24770,30 @@
2474924770
emit(" " + self_arrow + sanitize_ivar(iname) + " = " + tmp_arr + ";")2475024771
return2475124772
end24773+
# Non-empty array literal `[a, b, ...]` going into a poly_array24774+
# slot. compile_array_literal infers a typed array (ptr_array of24775+
# one class for homogeneous obj literals, etc.) and emits the24776+
# corresponding storage — but the slot was widened to poly_array,24777+
# so a typed-array-pointer assignment would fail the C compile.24778+
# Emit a fresh PolyArray with each element boxed to sp_RbVal.24779+
if ivt == "poly_array" && @nd_type[expr_id] == "ArrayNode"24780+
@needs_gc = 124781+
@needs_rb_value = 124782+
tmp_arr = new_temp24783+
emit(" sp_PolyArray *" + tmp_arr + " = sp_PolyArray_new();")24784+
elems_pa = parse_id_list(@nd_elements[expr_id])24785+
ek = 024786+
while ek < elems_pa.length24787+
eid = elems_pa[ek]24788+
et = infer_type(eid)24789+
ev = compile_expr(eid)24790+
ebox = et == "poly" ? ev : box_value_to_poly(et, ev)24791+
emit(" sp_PolyArray_push(" + tmp_arr + ", " + ebox + ");")24792+
ek = ek + 124793+
end24794+
emit(" " + self_arrow + sanitize_ivar(iname) + " = " + tmp_arr + ";")24795+
return24796+
end2475224797
# Issue #130: poly slot — every concrete-typed RHS must be boxed2475324798
# to sp_RbVal. Without the box, C compiler sees `sp_RbVal = mrb_int`2475424799
# (or const char *, etc.) and either rejects the assignment ortest/poly_array_slot_literal.rbaddedView file
Loading diff…