Commit 140c550a

140c550af427Merged

Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified

Description

fix(codegen): << operator on Array recv emits push, not bit-shift

compile_operator_expr only had push-style cases for mutable_str and string concatenation; every other type fell through to a literal C << (left shift) operator. @output_pixels << val on an IntArray then came out as (self->iv_output_pixels << val), which gcc rejected with "invalid operands to binary <<".

Add explicit branches for int_array / float_array / str_array / sym_array / ptr_array, each of which emits the matching sp_<X>Array_push and returns the (rooted) recv so the operator expression can chain ((arr << x) << y). infer_call_type's << branch is also widened to report the recv's array type so the outer operand of a chained << type-checks.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
140c550af427
Parent
bee7e89d5b64

spinel_codegen.rbmodifiedView file

@@ -2088,6 +2088,10 @@
20882088 if lt == "mutable_str"
20892089 return "mutable_str"
20902090 end
2091+ # Array `<<` returns the recv (so `(arr << x) << y` chains).
2092+ if is_array_type(lt) == 1
2093+ return lt
2094+ end
20912095 end
20922096 return "int"
20932097 end
@@ -15979,6 +15983,34 @@
1597915983 if lt == "string"
1598015984 return "sp_str_concat(" + compile_expr(recv) + ", " + compile_arg0(nid) + ")"
1598115985 end
15986+ # Array `<<` is push, not bit-shift. The compile_call_expr path
15987+ # also has a push branch for direct `arr.push(x)` style calls,
15988+ # but the operator form lands here.
15989+ if lt == "int_array"
15990+ @needs_int_array = 1
15991+ rc = compile_expr_gc_rooted(recv)
15992+ return "(sp_IntArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"
15993+ end
15994+ if lt == "float_array"
15995+ @needs_float_array = 1
15996+ rc = compile_expr_gc_rooted(recv)
15997+ return "(sp_FloatArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"
15998+ end
15999+ if lt == "str_array"
16000+ @needs_str_array = 1
16001+ rc = compile_expr_gc_rooted(recv)
16002+ return "(sp_StrArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"
16003+ end
16004+ if lt == "sym_array"
16005+ @needs_int_array = 1
16006+ rc = compile_expr_gc_rooted(recv)
16007+ return "(sp_IntArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"
16008+ end
16009+ if is_ptr_array_type(lt) == 1
16010+ @needs_ptr_array = 1
16011+ rc = compile_expr_gc_rooted(recv)
16012+ return "(sp_PtrArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"
16013+ end
1598216014 return "(" + compile_expr(recv) + " << " + compile_arg0(nid) + ")"
1598316015 end
1598416016 if mname == ">>"