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 end
28478+ # Auto-unbox poly RHS into a primitive local slot. Common
28479+ # case: `pixel0 = arr[i]` where arr is heterogeneous (poly
28480+ # element type) and the dispatch arms all return int —
28481+ # spinel types `arr[i]` as poly, but the local is concretely
28482+ # int from a prior int-typed write. Reading .v.i preserves
28483+ # the runtime int payload; non-int payloads fall to 0
28484+ # (matches `to_i` semantics for poly).
28485+ if rhs_t == "poly" && (vt == "int" || vt == "bool")
28486+ val = "(" + val + ").v.i"
28487+ end
28488+ if rhs_t == "poly" && vt == "float"
28489+ val = "(" + val + ").v.f"
28490+ end
2847828491 emit(" " + vref + " = " + val + ";")
2847928492 end
2848028493 if rhs_t != "nil" || is_nullable_type(vt) == 0