Commit c98048e1
c98048e104bdMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
Merge pull request #92 from notorious94/istiad/fix/issue#85
fix(codegen): promote local sym_array type after empty-then-push (#85)
Details
- Commit
- c98048e104bd
- Parent
- 6ee8a675b277
- Merge parent
- e8d797a945dc
spinel_codegen.rbmodifiedView file
@@ -11131,6 +11131,19 @@
1113111131
end1113211132
ki = ki + 11113311133
end11134+
elsif arg_type == "symbol"11135+
# sym_array uses sp_IntArray storage, so int_array11136+
# helpers stay required even after promotion.11137+
@needs_int_array = 111138+
ki = 011139+
while ki < names.length11140+
if names[ki] == arr_name11141+
if types[ki] == "int_array"11142+
types[ki] = "sym_array"11143+
end11144+
end11145+
ki = ki + 111146+
end1113411147
end1113511148
end1113611149
end@@ -17584,8 +17597,11 @@
1758417597
end1758517598
vref = fiber_var_ref(lname)1758617599
vt = find_var_type(lname)17587-
# Empty array literal: create the correct array type17588-
if vt == "str_array" || vt == "float_array" || is_ptr_array_type(vt) == 117600+
# Empty array literal: create the correct array type. Returning17601+
# early here also preserves the scope's already-promoted type17602+
# (issue #58, #85) — the fall-through path below would clobber17603+
# vt with infer_type([])'s "int_array" via set_var_type.17604+
if vt == "str_array" || vt == "float_array" || vt == "sym_array" || is_ptr_array_type(vt) == 11758917605
expr_id = @nd_expression[nid]1759017606
if expr_id >= 0 && @nd_type[expr_id] == "ArrayNode"1759117607
elems = parse_id_list(@nd_elements[expr_id])@@ -17598,6 +17614,11 @@
1759817614
@needs_float_array = 11759917615
@needs_gc = 11760017616
emit(" " + vref + " = sp_FloatArray_new();")17617+
elsif vt == "sym_array"17618+
# sym_array shares sp_IntArray storage.17619+
@needs_int_array = 117620+
@needs_gc = 117621+
emit(" " + vref + " = sp_IntArray_new();")1760117622
else1760217623
@needs_ptr_array = 11760317624
@needs_gc = 1