Commit 05dfa811

05dfa8119de5Merged

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

Description

Merge pull request #371 from mame/pr/intarray-slice-assign-from-intarray

fix(codegen): infer + lower <X>_ptr_array.first/.last element type

Details

Commit
05dfa8119de5
Parent
42a0875551e3
Merge parent
02462f86b48d

spinel_codegen.rbmodifiedView file

@@ -4045,6 +4045,19 @@
40454045 if rt == "float_array"
40464046 return "float"
40474047 end
4048+ # `<X>_ptr_array.first` / `.last` returns an `<X>` (e.g.
4049+ # `int_array_ptr_array.first` → `int_array`). Without this,
4050+ # downstream typed-array consumers (notably the slice-assign
4051+ # `arr[i, n] = banks.first` path in compile_bracket_assign,
4052+ # which needs `infer_type(arg_ids[2]) == "int_array"` to fire)
4053+ # see "int" and silently fall through to element-assign,
4054+ # silently lowering `arr[i, n] = src` to `arr[i] = n`.
4055+ if is_ptr_array_type(rt) == 1
4056+ return ptr_array_elem_type(rt)
4057+ end
4058+ if rt == "poly_array"
4059+ return "poly"
4060+ end
40484061 end
40494062 return "int"
40504063 end
@@ -25927,6 +25940,12 @@
2592725940 if mname == "[]"
2592825941 return "((" + ct + ")sp_PtrArray_get(" + rc + ", " + compile_arg0_as_int(nid) + "))"
2592925942 end
25943+ if mname == "first"
25944+ return "((" + ct + ")sp_PtrArray_get(" + rc + ", 0))"
25945+ end
25946+ if mname == "last"
25947+ return "((" + ct + ")sp_PtrArray_get(" + rc + ", sp_PtrArray_length(" + rc + ") - 1))"
25948+ end
2593025949 if mname == "push"
2593125950 return "(sp_PtrArray_push(" + rc + ", " + compile_arg0(nid) + "), 0)"
2593225951 end