Commit 08027fdf
08027fdf9e40Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Generalize array join for all typed arrays; infer poly.map return type
- codegen:
joinnow emitssp_%sArray_joinfor any typed array kind, not just TY_STR_ARRAY. Also supports zero-argument join (separator=""). - analyze: TY_POLY.map/collect infers return type from the block's last expression; returns ty_array_of(et) or TY_POLY_ARRAY if unknown.
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 08027fdf9e40
- Parent
- e93a0c486646
src/analyze.cmodifiedView file
@@ -801,6 +801,15 @@
801801
if (!strcmp(name, "to_f")) return TY_FLOAT;802802
if (!strcmp(name, "[]") && argc == 1) return TY_POLY; /* boxed array element access */803803
if (!strcmp(name, "dig") && argc >= 1) return TY_POLY;804+
{805+
int blk = nt_ref(nt, id, "block");806+
if (blk >= 0 && (!strcmp(name, "map") || !strcmp(name, "collect"))) {807+
int body = nt_ref(nt, blk, "body");808+
int bn = 0; const int *bb = body >= 0 ? nt_arr(nt, body, "body", &bn) : NULL;809+
TyKind et = bn > 0 ? infer_type(c, bb[bn - 1]) : TY_UNKNOWN;810+
return et != TY_UNKNOWN ? ty_array_of(et) : TY_POLY_ARRAY;811+
}812+
}804813
/* poly method dispatch: unify the return type over every class that805814
defines `name` (the runtime cls_id picks the impl). */806815
TyKind r = TY_UNKNOWN; int found = 0;src/codegen.cmodifiedView file
Loading diff…