Commit bae7b5d8
bae7b5d85265Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
Merge pull request #347 from mame/pr/auto-unbox-poly-rhs-prim
fix(codegen): auto-unbox poly RHS into a primitive local slot
Details
- Commit
- bae7b5d85265
- Parent
- 8472d3b9acd7
- Merge parent
- c32df63587ee
spinel_codegen.rbmodifiedView file
@@ -28475,6 +28475,19 @@
2847528475
if vt == "poly" && rhs_t != "" && rhs_t != "poly"2847628476
val = box_value_to_poly(rhs_t, val)2847728477
end28478+
# Auto-unbox poly RHS into a primitive local slot. Common28479+
# case: `pixel0 = arr[i]` where arr is heterogeneous (poly28480+
# element type) and the dispatch arms all return int —28481+
# spinel types `arr[i]` as poly, but the local is concretely28482+
# int from a prior int-typed write. Reading .v.i preserves28483+
# the runtime int payload; non-int payloads fall to 028484+
# (matches `to_i` semantics for poly).28485+
if rhs_t == "poly" && (vt == "int" || vt == "bool")28486+
val = "(" + val + ").v.i"28487+
end28488+
if rhs_t == "poly" && vt == "float"28489+
val = "(" + val + ").v.f"28490+
end2847828491
emit(" " + vref + " = " + val + ";")2847928492
end2848028493
if rhs_t != "nil" || is_nullable_type(vt) == 0test/auto_unbox_poly_to_int_local.rbaddedView file
Loading diff…
test/auto_unbox_poly_to_int_local.rb.expectedaddedView file
Loading diff…