Commit 8bd71dae

8bd71dae0c9bMerged

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

Description

Poly Tier 2a: arithmetic/comparison/conversions + method-name mangling

  • Poly operands: +,-,,/,%,** via sp_poly_, <,>,<=,>= via sp_poly_lt/gt/ le/ge, and to_s/inspect/to_i/to_f on a poly receiver. Inference yields poly for arithmetic, bool for comparison/predicate, string/int/float for conversions.
  • Call-site args are boxed when the callee parameter is poly.
  • Mangle Ruby method names into C identifiers (?->_p, !->_bang, =->_set) at every dispatch / definition / super site, so predicate and bang methods (e.g. def bigger?) compile.

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

Details

Commit
8bd71dae0c9b
Parent
d88cd194215b

src/analyze.cmodifiedView file

@@ -162,6 +162,23 @@
162162 !strcmp(name, "full_message") || !strcmp(name, "class")) return TY_STRING;
163163 }
164164
165+ /* poly receiver / poly operand: result type of operations on sp_RbVal */
166+ if (recv >= 0 && (rt == TY_POLY || a0 == TY_POLY)) {
167+ if (!strcmp(name, "+") || !strcmp(name, "-") || !strcmp(name, "*") ||
168+ !strcmp(name, "/") || !strcmp(name, "%") || !strcmp(name, "**"))
169+ return TY_POLY;
170+ if (!strcmp(name, "<") || !strcmp(name, ">") || !strcmp(name, "<=") ||
171+ !strcmp(name, ">=") || !strcmp(name, "==") || !strcmp(name, "!=") ||
172+ !strcmp(name, "nil?") || !strcmp(name, "is_a?") || !strcmp(name, "kind_of?") ||
173+ !strcmp(name, "include?"))
174+ return TY_BOOL;
175+ if (rt == TY_POLY) {
176+ if (!strcmp(name, "to_s") || !strcmp(name, "inspect")) return TY_STRING;
177+ if (!strcmp(name, "to_i")) return TY_INT;
178+ if (!strcmp(name, "to_f")) return TY_FLOAT;
179+ }
180+ }
181+
165182 /* range receiver methods */
166183 if (recv >= 0 && rt == TY_RANGE) {
167184 if (!strcmp(name, "to_a")) return TY_INT_ARRAY;