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
end2112+
# Array `<<` returns the recv (so `(arr << x) << y` chains).2113+
if is_array_type(lt) == 12114+
return lt2115+
end21122116
end21132117
return "int"21142118
end@@ -16082,6 +16086,34 @@
1608216086
if lt == "string"1608316087
return "sp_str_concat(" + compile_expr(recv) + ", " + compile_arg0(nid) + ")"1608416088
end16089+
# Array `<<` is push, not bit-shift. The compile_call_expr path16090+
# 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 = 116094+
rc = compile_expr_gc_rooted(recv)16095+
return "(sp_IntArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"16096+
end16097+
if lt == "float_array"16098+
@needs_float_array = 116099+
rc = compile_expr_gc_rooted(recv)16100+
return "(sp_FloatArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"16101+
end16102+
if lt == "str_array"16103+
@needs_str_array = 116104+
rc = compile_expr_gc_rooted(recv)16105+
return "(sp_StrArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"16106+
end16107+
if lt == "sym_array"16108+
@needs_int_array = 116109+
rc = compile_expr_gc_rooted(recv)16110+
return "(sp_IntArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"16111+
end16112+
if is_ptr_array_type(lt) == 116113+
@needs_ptr_array = 116114+
rc = compile_expr_gc_rooted(recv)16115+
return "(sp_PtrArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"16116+
end1608516117
return "(" + compile_expr(recv) + " << " + compile_arg0(nid) + ")"1608616118
end1608716119
if mname == ">>"test/array_shovel.rbaddedView file
Loading diff…