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 end
1107011070 ki = ki + 1
1107111071 end
11072+ elsif arg_type == "symbol"
11073+ # sym_array uses sp_IntArray storage, so int_array
11074+ # helpers stay required even after promotion.
11075+ @needs_int_array = 1
11076+ ki = 0
11077+ while ki < names.length
11078+ if names[ki] == arr_name
11079+ if types[ki] == "int_array"
11080+ types[ki] = "sym_array"
11081+ end
11082+ end
11083+ ki = ki + 1
11084+ end
1107211085 end
1107311086 end
1107411087 end
@@ -17443,8 +17456,11 @@
1744317456 end
1744417457 vref = fiber_var_ref(lname)
1744517458 vt = find_var_type(lname)
17446- # Empty array literal: create the correct array type
17447- if vt == "str_array" || vt == "float_array" || is_ptr_array_type(vt) == 1
17459+ # Empty array literal: create the correct array type. Returning
17460+ # early here also preserves the scope's already-promoted type
17461+ # (issue #58, #85) — the fall-through path below would clobber
17462+ # 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) == 1
1744817464 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 = 1
1745817474 @needs_gc = 1
1745917475 emit(" " + vref + " = sp_FloatArray_new();")
17476+ elsif vt == "sym_array"
17477+ # sym_array shares sp_IntArray storage.
17478+ @needs_int_array = 1
17479+ @needs_gc = 1
17480+ emit(" " + vref + " = sp_IntArray_new();")
1746017481 else
1746117482 @needs_ptr_array = 1
1746217483 @needs_gc = 1