Commit d5ed9a21
d5ed9a21cd1cMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · ~3 modified
Description
String#% with an array, and === on scalar comparables
Two operator additions:
- "fmt" % [args] formats printf-style; any typed array argument is boxed to poly (new sp_typed_to_poly, factored out of sp_PolyArray_eq_typed) so one sp_str_format_polyarr path covers mixed specs (%d/%x/%.2f/...).
- a === b on a scalar comparable (bool/int/float/string/symbol) is value equality; mismatched families are false. Range/Class/Regexp === keep their own handlers. The analyzer types === as Bool.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- d5ed9a21cd1c
- Parent
- a1cb0e042740
lib/sp_runtime.hmodifiedView file
@@ -3255,11 +3255,11 @@
32553255
}32563256
return TRUE;32573257
}3258-
/* Compare a poly array against a typed (int/str/float) array by boxing the3259-
typed side element-wise. `kind` is the typed array's SP_BUILTIN_* tag. */3260-
static mrb_bool sp_PolyArray_eq_typed(sp_PolyArray *pa, void *tp, int kind) {3261-
if (!pa || !tp) return FALSE;3258+
/* Box a typed (int/str/float) array into a fresh poly array element-wise.3259+
`kind` is the typed array's SP_BUILTIN_* tag. */3260+
static sp_PolyArray *sp_typed_to_poly(void *tp, int kind) {32623261
sp_PolyArray *tb = sp_PolyArray_new();3262+
if (!tp) return tb;32633263
if (kind == SP_BUILTIN_STR_ARRAY) {32643264
sp_StrArray *a = (sp_StrArray *)tp;32653265
for (mrb_int i = 0; i < a->len; i++) sp_PolyArray_push(tb, sp_box_str(sp_StrArray_get(a, i)));@@ -3272,7 +3272,13 @@
32723272
sp_IntArray *a = (sp_IntArray *)tp;32733273
for (mrb_int i = 0; i < a->len; i++) sp_PolyArray_push(tb, sp_box_int(sp_IntArray_get(a, i)));32743274
}3275-
return sp_PolyArray_eq(pa, tb);3275+
return tb;3276+
}3277+
/* Compare a poly array against a typed (int/str/float) array by boxing the3278+
typed side element-wise. `kind` is the typed array's SP_BUILTIN_* tag. */3279+
static mrb_bool sp_PolyArray_eq_typed(sp_PolyArray *pa, void *tp, int kind) {3280+
if (!pa || !tp) return FALSE;3281+
return sp_PolyArray_eq(pa, sp_typed_to_poly(tp, kind));32763282
}32773283
static mrb_bool sp_PolyArray_include(sp_PolyArray *a, sp_RbVal v) {32783284
if (!a) return FALSE;src/analyze.cmodifiedView file
Loading diff…
src/codegen.cmodifiedView file
Loading diff…