Commit ea2b009a
ea2b009adb16Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 5 files · +4 added · ~1 modified
Description
Merge pull request #382 from mame/pr/each-poly-recv-multi-arity
fix(codegen): destructure poly RHS for multi-write and auto-splat poly recv each block
Details
- Commit
- ea2b009adb16
- Parent
- 3ee4eed9c742
- Merge parent
- cf6b313fb6e8
spinel_codegen.rbmodifiedView file
@@ -5187,6 +5187,15 @@
51875187
if rt == "poly_array"51885188
return "poly"51895189
end5190+
if rt == "poly"5191+
# RHS evaluates to sp_RbVal (e.g. `@h[k][i]` where @h is a5192+
# poly_poly_hash whose values are poly_arrays of inner poly5193+
# elements). Mirror compile_multi_write's `val_t_local == "poly"`5194+
# arm: unbox to sp_PolyArray * at runtime, fetch each slot via5195+
# sp_PolyArray_get returning sp_RbVal, so each target slot is5196+
# typed `poly` and stays boxed for downstream poly dispatch.5197+
return "poly"5198+
end51905199
"int"51915200
end51925201
@@ -36417,12 +36426,36 @@
3641736426
emit(" else if (" + poly_tmp + ".cls_id == SP_BUILTIN_PTR_ARRAY) " + val_tmp + " = sp_box_obj(sp_PtrArray_get((sp_PtrArray *)" + poly_tmp + ".v.p, " + idx_tmp + "), 0);")3641836427
emit(" else if (" + poly_tmp + ".cls_id == SP_BUILTIN_POLY_ARRAY) " + val_tmp + " = sp_PolyArray_get((sp_PolyArray *)" + poly_tmp + ".v.p, " + idx_tmp + ");")3641936428
if has_bp == 136420-
emit(" sp_RbVal lv_" + bp1 + " = " + val_tmp + ";")36429+
if bp2 != ""36430+
# Multi-param block over a poly receiver: CRuby auto-splats36431+
# when the yielded element is itself an Array. Mirror that:36432+
# if the runtime element is a typed array, distribute its36433+
# first two slots across bp1/bp2; otherwise bp1 takes the36434+
# whole element and bp2 stays nil.36435+
emit(" sp_RbVal lv_" + bp1 + " = sp_box_nil();")36436+
emit(" sp_RbVal lv_" + bp2 + " = sp_box_nil();")36437+
emit(" if (" + val_tmp + ".tag == SP_TAG_OBJ && " + val_tmp + ".cls_id == SP_BUILTIN_POLY_ARRAY) {")36438+
emit(" sp_PolyArray *_pa = (sp_PolyArray *)" + val_tmp + ".v.p;")36439+
emit(" if (sp_PolyArray_length(_pa) > 0) lv_" + bp1 + " = sp_PolyArray_get(_pa, 0);")36440+
emit(" if (sp_PolyArray_length(_pa) > 1) lv_" + bp2 + " = sp_PolyArray_get(_pa, 1);")36441+
emit(" } else if (" + val_tmp + ".tag == SP_TAG_OBJ && " + val_tmp + ".cls_id == SP_BUILTIN_INT_ARRAY) {")36442+
emit(" sp_IntArray *_ia = (sp_IntArray *)" + val_tmp + ".v.p;")36443+
emit(" if (sp_IntArray_length(_ia) > 0) lv_" + bp1 + " = sp_box_int(sp_IntArray_get(_ia, 0));")36444+
emit(" if (sp_IntArray_length(_ia) > 1) lv_" + bp2 + " = sp_box_int(sp_IntArray_get(_ia, 1));")36445+
emit(" } else {")36446+
emit(" lv_" + bp1 + " = " + val_tmp + ";")36447+
emit(" }")36448+
else36449+
emit(" sp_RbVal lv_" + bp1 + " = " + val_tmp + ";")36450+
end3642136451
end3642236452
@indent = @indent + 23642336453
push_scope3642436454
if has_bp == 13642536455
declare_var(bp1, "poly")36456+
if bp2 != ""36457+
declare_var(bp2, "poly")36458+
end3642636459
end3642736460
redo_label = push_redo_label3642836461
emit_redo_label(redo_label)test/each_poly_recv_block_auto_splat.rbaddedView file
Loading diff…
test/each_poly_recv_block_auto_splat.rb.expectedaddedView file
Loading diff…
test/multi_write_from_poly_recv.rbaddedView file
Loading diff…
test/multi_write_from_poly_recv.rb.expectedaddedView file
Loading diff…