Commit ee2689d5
ee2689d5d693Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Poly-valued hash compound assignment (h[k] op= v)
h[k] += v on a hash with poly values now folds via sp_poly_ on the boxed operands instead of a raw C operator between an sp_RbVal and a scalar, fixing the -Werror invalid-operands compile.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- ee2689d5d693
- Parent
- d3901c763fd3
src/codegen.cmodifiedView file
@@ -2908,10 +2908,19 @@
29082908
buf_printf(b, "; %s _t%d = ", c_type_name(ty_hash_key(rt)), tb); emit_expr(c, argv[0], b);29092909
buf_puts(b, "; ");29102910
buf_printf(b, "sp_%sHash_set(_t%d, _t%d, ", hn, ta, tb);2911+
const char *pf = vt == TY_POLY ?2912+
(!strcmp(op, "+") ? "sp_poly_add" : !strcmp(op, "-") ? "sp_poly_sub" :2913+
!strcmp(op, "*") ? "sp_poly_mul" : !strcmp(op, "/") ? "sp_poly_div" :2914+
!strcmp(op, "%") ? "sp_poly_mod" : !strcmp(op, "**") ? "sp_poly_pow" : NULL) : NULL;29112915
if (vt == TY_STRING && !strcmp(op, "+")) {29122916
buf_printf(b, "sp_str_concat(sp_%sHash_get(_t%d, _t%d), ", hn, ta, tb);29132917
emit_expr(c, v, b); buf_puts(b, ")");29142918
}2919+
else if (pf) {2920+
/* a poly-valued slot folds via the dynamic operator on boxed operands */2921+
buf_printf(b, "%s(sp_%sHash_get(_t%d, _t%d), ", pf, hn, ta, tb);2922+
emit_boxed(c, v, b); buf_puts(b, ")");2923+
}29152924
else {29162925
buf_printf(b, "sp_%sHash_get(_t%d, _t%d) %s ", hn, ta, tb, op);29172926
buf_puts(b, "("); emit_expr(c, v, b); buf_puts(b, ")");