Commit 0f74f04c

0f74f04c3facMerged

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

Description

Integer bit/arith methods, Integer.sqrt, Float#divmod

Adds Integer#allbits?/anybits?/nobits? (mask predicates), ceildiv, pow (1-arg sp_int_pow, 3-arg modular sp_powmod), pred, succ/next, the Integer.sqrt(n) class method (exact via sp_int_sqrt), and Float#divmod which returns the mixed [Integer, Float] tuple as a poly array.

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

Details

Commit
0f74f04c3fac
Parent
e1f1ebb73901

src/analyze.cmodifiedView file

@@ -308,6 +308,10 @@
308308 (!strcmp(name, "pid") || !strcmp(name, "ppid")))
309309 return TY_INT;
310310 if (rty && !strcmp(rty, "ConstantReadNode") &&
311+ nt_str(nt, recv, "name") && !strcmp(nt_str(nt, recv, "name"), "Integer") &&
312+ !strcmp(name, "sqrt"))
313+ return TY_INT;
314+ if (rty && !strcmp(rty, "ConstantReadNode") &&
311315 nt_str(nt, recv, "name") && !strcmp(nt_str(nt, recv, "name"), "Dir") &&
312316 (!strcmp(name, "exist?") || !strcmp(name, "exists?")))
313317 return TY_BOOL;
@@ -607,6 +611,9 @@
607611 if (!strcmp(name, "ceil") || !strcmp(name, "floor") ||
608612 !strcmp(name, "round") || !strcmp(name, "truncate")) return TY_INT; /* no precision arg -> self */
609613 if (!strcmp(name, "divmod") && argc == 1) return TY_INT_ARRAY; /* [quotient, remainder] */
614+ if ((!strcmp(name, "allbits?") || !strcmp(name, "anybits?") || !strcmp(name, "nobits?")) && argc == 1) return TY_BOOL;
615+ if ((!strcmp(name, "ceildiv") || !strcmp(name, "pow")) && argc >= 1) return TY_INT;
616+ if ((!strcmp(name, "pred") || !strcmp(name, "succ") || !strcmp(name, "next")) && argc == 0) return TY_INT;
610617 if (!strcmp(name, "chr")) return TY_STRING;
611618 if (!strcmp(name, "[]") && argc == 1) return TY_INT; /* bit access */
612619 if (!strcmp(name, "gcd") || !strcmp(name, "lcm") || !strcmp(name, "clamp")) return TY_INT;
@@ -615,6 +622,7 @@
615622 }
616623 /* float receiver methods */
617624 if (recv >= 0 && rt == TY_FLOAT) {
625+ if (!strcmp(name, "divmod") && argc == 1) return TY_POLY_ARRAY; /* [Integer, Float] */
618626 if (!strcmp(name, "floor") || !strcmp(name, "ceil") ||
619627 !strcmp(name, "round") || !strcmp(name, "truncate")) {
620628 /* value-based return type: ndigits > 0 (literal) -> Float, else Integer */