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 end
10911091 return "poly_array"
10921092 end
1093+ # Check if all elements are the same array type → array of arrays
1094+ if et == "int_array" || et == "str_array" || et == "float_array"
1095+ all_same = 1
1096+ k = 1
1097+ while k < elems.length
1098+ if infer_type(elems[k]) != et
1099+ all_same = 0
1100+ end
1101+ k = k + 1
1102+ end
1103+ if all_same == 1
1104+ @needs_ptr_array = 1
1105+ @needs_gc = 1
1106+ return et + "_ptr_array"
1107+ end
1108+ return "poly_array"
1109+ end
10931110 # Check if elements have mixed types
10941111 k = 1
10951112 while k < elems.length
@@ -2547,6 +2564,9 @@
25472564 if bt == "stringio" || bt == "lambda" || bt == "poly_array"
25482565 return 1
25492566 end
2567+ if is_ptr_array_type(bt) == 1
2568+ return 1
2569+ end
25502570 if bt == "fiber" || bt == "bigint"
25512571 return 1
25522572 end