Commit e8d797a9
e8d797a945dcMerged
notorious94 <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): promote local sym_array type after empty-then-push (#85)
Details
- Commit
- e8d797a945dc
- Parent
- 0c3c5d918fc5
spinel_codegen.rbmodifiedView file
@@ -11069,6 +11069,19 @@
1106911069
end1107011070
ki = ki + 11107111071
end11072+
elsif arg_type == "symbol"11073+
# sym_array uses sp_IntArray storage, so int_array11074+
# helpers stay required even after promotion.11075+
@needs_int_array = 111076+
ki = 011077+
while ki < names.length11078+
if names[ki] == arr_name11079+
if types[ki] == "int_array"11080+
types[ki] = "sym_array"11081+
end11082+
end11083+
ki = ki + 111084+
end1107211085
end1107311086
end1107411087
end@@ -17443,8 +17456,11 @@
1744317456
end1744417457
vref = fiber_var_ref(lname)1744517458
vt = find_var_type(lname)17446-
# Empty array literal: create the correct array type17447-
if vt == "str_array" || vt == "float_array" || is_ptr_array_type(vt) == 117459+
# Empty array literal: create the correct array type. Returning17460+
# early here also preserves the scope's already-promoted type17461+
# (issue #58, #85) — the fall-through path below would clobber17462+
# vt with infer_type([])'s "int_array" via set_var_type.17463+
if vt == "str_array" || vt == "float_array" || vt == "sym_array" || is_ptr_array_type(vt) == 11744817464
expr_id = @nd_expression[nid]1744917465
if expr_id >= 0 && @nd_type[expr_id] == "ArrayNode"1745017466
elems = parse_id_list(@nd_elements[expr_id])@@ -17457,6 +17473,11 @@
1745717473
@needs_float_array = 11745817474
@needs_gc = 11745917475
emit(" " + vref + " = sp_FloatArray_new();")17476+
elsif vt == "sym_array"17477+
# sym_array shares sp_IntArray storage.17478+
@needs_int_array = 117479+
@needs_gc = 117480+
emit(" " + vref + " = sp_IntArray_new();")1746017481
else1746117482
@needs_ptr_array = 11746217483
@needs_gc = 1