Commit 78c568df

78c568dfd64bMerged

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

Description

Merge pull request #159 from mame/pr/array-shovel-push

fix(codegen): Array#<< in expression context emits push, not bit-shift

Details

Commit
78c568dfd64b
Parent
b4022cdd8f3b
Merge parent
140c550af427

spinel_codegen.rbmodifiedView file

@@ -2109,6 +2109,10 @@
21092109 if lt == "mutable_str"
21102110 return "mutable_str"
21112111 end
2112+ # Array `<<` returns the recv (so `(arr << x) << y` chains).
2113+ if is_array_type(lt) == 1
2114+ return lt
2115+ end
21122116 end
21132117 return "int"
21142118 end
@@ -16082,6 +16086,34 @@
1608216086 if lt == "string"
1608316087 return "sp_str_concat(" + compile_expr(recv) + ", " + compile_arg0(nid) + ")"
1608416088 end
16089+ # Array `<<` is push, not bit-shift. The compile_call_expr path
16090+ # also has a push branch for direct `arr.push(x)` style calls,
16091+ # but the operator form lands here.
16092+ if lt == "int_array"
16093+ @needs_int_array = 1
16094+ rc = compile_expr_gc_rooted(recv)
16095+ return "(sp_IntArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"
16096+ end
16097+ if lt == "float_array"
16098+ @needs_float_array = 1
16099+ rc = compile_expr_gc_rooted(recv)
16100+ return "(sp_FloatArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"
16101+ end
16102+ if lt == "str_array"
16103+ @needs_str_array = 1
16104+ rc = compile_expr_gc_rooted(recv)
16105+ return "(sp_StrArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"
16106+ end
16107+ if lt == "sym_array"
16108+ @needs_int_array = 1
16109+ rc = compile_expr_gc_rooted(recv)
16110+ return "(sp_IntArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"
16111+ end
16112+ if is_ptr_array_type(lt) == 1
16113+ @needs_ptr_array = 1
16114+ rc = compile_expr_gc_rooted(recv)
16115+ return "(sp_PtrArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"
16116+ end
1608516117 return "(" + compile_expr(recv) + " << " + compile_arg0(nid) + ")"
1608616118 end
1608716119 if mname == ">>"