Commit a9ca40b3

a9ca40b38368Merged

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

Description

Merge pull request #162 from mame/pr/unbox-poly-int-array-literal

fix(codegen): unbox poly elements when emitting an IntArray literal

Details

Commit
a9ca40b38368
Parent
d3a530b4042d
Merge parent
98bf255871b4

spinel_codegen.rbmodifiedView file

@@ -20296,7 +20296,17 @@
2029620296 emit(" sp_IntArray *" + tmp + " = sp_IntArray_new();")
2029720297 k = 0
2029820298 while k < elems.length
20299- emit(" sp_IntArray_push(" + tmp + ", " + compile_expr(elems[k]) + ");")
20299+ ev = compile_expr(elems[k])
20300+ et = infer_type(elems[k])
20301+ # Unbox poly values when pushing into a (concrete) IntArray.
20302+ # An ArrayNode literal whose elements are poly (e.g.
20303+ # `[addr]` where addr's recorded type is sp_RbVal) needs the
20304+ # int payload extracted via `.v.i`. Without this, the C
20305+ # compiler rejects the push with "incompatible type".
20306+ if et == "poly"
20307+ ev = "(" + ev + ").v.i"
20308+ end
20309+ emit(" sp_IntArray_push(" + tmp + ", " + ev + ");")
2030020310 k = k + 1
2030120311 end
2030220312 tmp