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
if lt == "mutable_str" return "mutable_str" end # Array `<<` returns the recv (so `(arr << x) << y` chains). if is_array_type(lt) == 1 return lt end end return "int" end if lt == "string" return "sp_str_concat(" + compile_expr(recv) + ", " + compile_arg0(nid) + ")" end # Array `<<` is push, not bit-shift. The compile_call_expr path # also has a push branch for direct `arr.push(x)` style calls, # but the operator form lands here. if lt == "int_array" @needs_int_array = 1 rc = compile_expr_gc_rooted(recv) return "(sp_IntArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")" end if lt == "float_array" @needs_float_array = 1 rc = compile_expr_gc_rooted(recv) return "(sp_FloatArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")" end if lt == "str_array" @needs_str_array = 1 rc = compile_expr_gc_rooted(recv) return "(sp_StrArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")" end if lt == "sym_array" @needs_int_array = 1 rc = compile_expr_gc_rooted(recv) return "(sp_IntArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")" end if is_ptr_array_type(lt) == 1 @needs_ptr_array = 1 rc = compile_expr_gc_rooted(recv) return "(sp_PtrArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")" end return "(" + compile_expr(recv) + " << " + compile_arg0(nid) + ")" end if mname == ">>"test/array_shovel.rbaddedView file
Loading diff…