Commit 317c657b

317c657bd756Merged

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

Description

Coerce poly indices/bounds to int at array-set and range-new sites

Add emit_int_expr (poly -> sp_poly_to_i) and apply it where the runtime ABI requires a raw integer but the expression widened to poly: typed-array []= indices (statement and expression forms), poly-array element index, and Range bounds. Also coerce a poly RHS to the element representation in the statement-form typed-array []=.

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

Details

Commit
317c657bd756
Parent
9bc171d1da21

src/codegen.cmodifiedView file

@@ -42,6 +42,16 @@
4242 else buf_printf(b, "(%s).v.i", expr);
4343 }
4444
45+/* Emit a node as an mrb_int, coercing a poly value through sp_poly_to_i. Used
46+ where the runtime ABI demands a raw integer (array indices, etc.) but the
47+ expression's static type widened to poly. */
48+void emit_int_expr(Compiler *c, int node, Buf *b) {
49+ if (comp_ntype(c, node) == TY_POLY) {
50+ buf_puts(b, "sp_poly_to_i("); emit_expr(c, node, b); buf_puts(b, ")");
51+ }
52+ else emit_expr(c, node, b);
53+}
54+
4555 void emit_boxed(Compiler *c, int node, Buf *b) {
4656 TyKind t = comp_ntype(c, node);
4757 if (t == TY_POLY) { emit_expr(c, node, b); return; }