Commit d1af8542

d1af854201d3Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · +1 added · ~1 modified

Description

Specialize Array#transpose for str_array / float_array element arrays

transpose was only wired for int-element nested arrays (int_array_ptr_array); a nested array of strings or floats (float_array_ptr_array, e.g. pr_geohash's latlng.transpose in GeoHash.decode) fell through to the unresolved-call stub and failed to compile.

Mirror the int specialization for str and float: build one column array per inner index, collecting element [i][j] via the matching get/push helpers. The analyzer already preserves the ptr_array type through transpose, so only codegen needed the new arms. Companion to the flatten element-type fix.

Closes #1079

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
d1af854201d3
Parent
09f5d8cd2fdc

spinel_codegen.rbmodifiedView file

@@ -23974,6 +23974,54 @@
2397423974 emit(" }")
2397523975 return tmp
2397623976 end
23977+ # Same matrix transpose for [[Str]] / [[Float]] nested arrays:
23978+ # build one column array per inner index, collecting element [i][j].
23979+ if mname == "transpose" && elem_type == "str_array"
23980+ @needs_str_array = 1
23981+ @needs_gc = 1
23982+ tmp = new_temp
23983+ col = new_temp
23984+ itmp = new_temp
23985+ jtmp = new_temp
23986+ cols = new_temp
23987+ emit(" sp_PtrArray *" + tmp + " = sp_PtrArray_new();")
23988+ emit(" SP_GC_ROOT(" + tmp + ");")
23989+ emit(" if (sp_PtrArray_length(" + rc + ") > 0) {")
23990+ emit(" mrb_int " + cols + " = sp_StrArray_length((sp_StrArray *)sp_PtrArray_get(" + rc + ", 0));")
23991+ emit(" for (mrb_int " + jtmp + " = 0; " + jtmp + " < " + cols + "; " + jtmp + "++) {")
23992+ emit(" sp_StrArray *" + col + " = sp_StrArray_new();")
23993+ emit(" SP_GC_ROOT(" + col + ");")
23994+ emit(" for (mrb_int " + itmp + " = 0; " + itmp + " < sp_PtrArray_length(" + rc + "); " + itmp + "++) {")
23995+ emit(" sp_StrArray_push(" + col + ", sp_StrArray_get((sp_StrArray *)sp_PtrArray_get(" + rc + ", " + itmp + "), " + jtmp + "));")
23996+ emit(" }")
23997+ emit(" sp_PtrArray_push(" + tmp + ", " + col + ");")
23998+ emit(" }")
23999+ emit(" }")
24000+ return tmp
24001+ end
24002+ if mname == "transpose" && elem_type == "float_array"
24003+ @needs_float_array = 1
24004+ @needs_gc = 1
24005+ tmp = new_temp
24006+ col = new_temp
24007+ itmp = new_temp
24008+ jtmp = new_temp
24009+ cols = new_temp
24010+ emit(" sp_PtrArray *" + tmp + " = sp_PtrArray_new();")
24011+ emit(" SP_GC_ROOT(" + tmp + ");")
24012+ emit(" if (sp_PtrArray_length(" + rc + ") > 0) {")
24013+ emit(" mrb_int " + cols + " = sp_FloatArray_length((sp_FloatArray *)sp_PtrArray_get(" + rc + ", 0));")
24014+ emit(" for (mrb_int " + jtmp + " = 0; " + jtmp + " < " + cols + "; " + jtmp + "++) {")
24015+ emit(" sp_FloatArray *" + col + " = sp_FloatArray_new();")
24016+ emit(" SP_GC_ROOT(" + col + ");")
24017+ emit(" for (mrb_int " + itmp + " = 0; " + itmp + " < sp_PtrArray_length(" + rc + "); " + itmp + "++) {")
24018+ emit(" sp_FloatArray_push(" + col + ", sp_FloatArray_get((sp_FloatArray *)sp_PtrArray_get(" + rc + ", " + itmp + "), " + jtmp + "));")
24019+ emit(" }")
24020+ emit(" sp_PtrArray_push(" + tmp + ", " + col + ");")
24021+ emit(" }")
24022+ emit(" }")
24023+ return tmp
24024+ end
2397724025 end
2397824026 if recv_type == "str_array"
2397924027 if mname == "length"