Commit 0de0c019
0de0c0193e99Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 2 files · +1 added · ~1 modified
Description
feat: add array-of-arrays type inference and codegen
Two-level array nesting is now supported. [[1,2],[3,4]] infers as int_array_ptr_array, [["a","b"]] as str_array_ptr_array, etc. Uses PtrArray with proper casts. Element access, each iteration, push, and length all work on nested arrays.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 0de0c0193e99
- Parent
- 93f743834642
spinel_codegen.rbmodifiedView file
@@ -1090,6 +1090,23 @@
10901090
end10911091
return "poly_array"10921092
end1093+
# Check if all elements are the same array type → array of arrays1094+
if et == "int_array" || et == "str_array" || et == "float_array"1095+
all_same = 11096+
k = 11097+
while k < elems.length1098+
if infer_type(elems[k]) != et1099+
all_same = 01100+
end1101+
k = k + 11102+
end1103+
if all_same == 11104+
@needs_ptr_array = 11105+
@needs_gc = 11106+
return et + "_ptr_array"1107+
end1108+
return "poly_array"1109+
end10931110
# Check if elements have mixed types10941111
k = 110951112
while k < elems.length@@ -2547,6 +2564,9 @@
25472564
if bt == "stringio" || bt == "lambda" || bt == "poly_array"25482565
return 125492566
end2567+
if is_ptr_array_type(bt) == 12568+
return 12569+
end25502570
if bt == "fiber" || bt == "bigint"25512571
return 125522572
endtest/bm_array_of_array.rbaddedView file
Loading diff…