Commit 47f4dbb4
47f4dbb41704Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Array#slice_when and Array#chunk on int_array
Implement slice_when { |a, b| cond } and chunk { |x| key } for int_array receivers. Both produce inline-loop inspect strings via new emit_slice_when_chunk_inspect_expr in codegen; analyze.c types the block params correctly (two-element comparator for slice_when, single element for chunk).
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 47f4dbb41704
- Parent
- 3342d08c7d13
src/analyze.cmodifiedView file
@@ -975,7 +975,8 @@
975975
pr = nt_ref(nt, pr, "receiver");976976
if (pr >= 0 && nt_type(nt, pr) && !strcmp(nt_type(nt, pr), "CallNode") && nt_str(nt, pr, "name") &&977977
(!strcmp(nt_str(nt, pr, "name"), "product") || !strcmp(nt_str(nt, pr, "name"), "slice_before") ||978-
!strcmp(nt_str(nt, pr, "name"), "slice_after")))978+
!strcmp(nt_str(nt, pr, "name"), "slice_after") || !strcmp(nt_str(nt, pr, "name"), "slice_when") ||979+
!strcmp(nt_str(nt, pr, "name"), "chunk")))979980
return TY_STRING;980981
}981982
@@ -2899,7 +2900,8 @@
28992900
!strcmp(name, "map!") || !strcmp(name, "collect!") ||29002901
!strcmp(name, "select!") || !strcmp(name, "filter!") || !strcmp(name, "reject!") ||29012902
!strcmp(name, "keep_if") || !strcmp(name, "delete_if") || !strcmp(name, "each_index") ||2902-
!strcmp(name, "flat_map") || !strcmp(name, "each_with_object")) &&2903+
!strcmp(name, "flat_map") || !strcmp(name, "each_with_object") ||2904+
!strcmp(name, "chunk")) &&29032905
ty_is_array(rt))29042906
pt = ty_array_elem(rt);29052907
/* TY_POLY receiver with iteration methods: element type is TY_POLY */@@ -2932,10 +2934,10 @@
29322934
continue;29332935
}29342936
2935-
/* array.sort/min/max/minmax { |a, b| cmp } -- a comparator block binds2936-
both parameters to the element type */2937+
/* array.sort/min/max/minmax/slice_when { |a, b| cmp } -- a comparator block2938+
binds both parameters to the element type */29372939
if ((!strcmp(name, "sort") || !strcmp(name, "sort!") || !strcmp(name, "min") || !strcmp(name, "max") ||2938-
!strcmp(name, "minmax")) && ty_is_array(rt)) {2940+
!strcmp(name, "minmax") || !strcmp(name, "slice_when")) && ty_is_array(rt)) {29392941
Scope *cs = comp_scope_of(c, block);29402942
for (int pj = 0; pj < 2; pj++) {29412943
const char *pn = block_param_name(c, block, pj);src/codegen.cmodifiedView file
Loading diff…