Commit 2b1e8fda

2b1e8fda8d42Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

Coerce poly receiver in integer bitwise operators

poly & x, poly | x, poly ^ x, poly >> x now coerce the receiver via sp_poly_to_i (the matching inference already types these int), instead of emitting a raw C bitwise op on two sp_RbVal structs. << stays on the earlier ambiguous shift/append path. Part of compiling optcarrot's register-poly code.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
2b1e8fda8d42
Parent
a7380f4183b2

src/codegen_call.cmodifiedView file

@@ -3520,13 +3520,18 @@
35203520 unsupported(c, id, "arithmetic");
35213521 }
35223522
3523- /* integer bitwise operators */
3524- if (recv >= 0 && argc == 1 && rt == TY_INT &&
3525- (!strcmp(name, "&") || !strcmp(name, "|") || !strcmp(name, "^") ||
3526- !strcmp(name, "<<") || !strcmp(name, ">>"))) {
3523+ /* integer bitwise operators. A poly receiver is coerced to int (the matching
3524+ inference types these TY_INT); `<<` on a poly is handled earlier as the
3525+ ambiguous shift/append via sp_poly_shl, so only &,|,^,>> reach here. */
3526+ if (recv >= 0 && argc == 1 &&
3527+ ((rt == TY_INT && (!strcmp(name, "&") || !strcmp(name, "|") || !strcmp(name, "^") ||
3528+ !strcmp(name, "<<") || !strcmp(name, ">>"))) ||
3529+ (rt == TY_POLY && (!strcmp(name, "&") || !strcmp(name, "|") || !strcmp(name, "^") ||
3530+ !strcmp(name, ">>"))))) {
35273531 TyKind at0 = comp_ntype(c, argv[0]);
35283532 buf_puts(b, "(");
3529- emit_expr(c, recv, b);
3533+ if (rt == TY_POLY) { buf_puts(b, "sp_poly_to_i("); emit_expr(c, recv, b); buf_puts(b, ")"); }
3534+ else emit_expr(c, recv, b);
35303535 buf_printf(b, " %s ", name);
35313536 if (at0 == TY_POLY) {
35323537 buf_puts(b, "sp_poly_to_i("); emit_expr(c, argv[0], b); buf_puts(b, ")");