Commit 2d7c57ed
2d7c57ed484bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Array#tally on int_array and str_array
Both runtime helpers already exist (sp_IntArray_tally_int returning an
int_int_hash, sp_StrArray_tally returning a str_int_hash); only the
analyze return type and codegen dispatch were missing. Wire them in so
[1,2,2,3].tally produces a usable hash with [], length, inspect, and
has_key?.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 2d7c57ed484b
- Parent
- 0c7545a4e3cf
src/analyze.cmodifiedView file
@@ -539,6 +539,10 @@
539539
if (!strcmp(name, "length") || !strcmp(name, "size") ||540540
!strcmp(name, "count") || !strcmp(name, "index")) return TY_INT;541541
if (!strcmp(name, "sum")) return ty_array_elem(rt);542+
if (!strcmp(name, "tally") && argc == 0) {543+
if (rt == TY_INT_ARRAY) return TY_INT_INT_HASH;544+
if (rt == TY_STR_ARRAY) return TY_STR_INT_HASH;545+
}542546
if ((!strcmp(name, "first") || !strcmp(name, "last")) && argc == 1) return rt; /* first(n)/last(n) -> subarray */543547
if (!strcmp(name, "first") || !strcmp(name, "last") ||544548
!strcmp(name, "min") || !strcmp(name, "max") ||src/codegen.cmodifiedView file
Loading diff…