Commit 7107a59d

7107a59dff7aMerged

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

Description

codegen: coerce poly sleep arg, and carry a nil Fiber-storage value boxed

Two codegen gaps that block compiling the transpiled blog (toward #1314):

  • sleep(x) with a poly argument passed the raw sp_RbVal to sp_sleep(mrb_float). Coerce poly -> float (sp_poly_to_f), alongside the existing int->double cast.
  • Fiber[:k] = nil declared the value temp with the value's type, which is void for a nil literal (void _t = nil is a type error). Fiber storage is poly-valued, so carry a nil/void/untyped value boxed.

Both are reproducible standalone (no RBS); regression tests added.

Refs #1314

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

Details

Commit
7107a59dff7a
Parent
e919dec18869

src/codegen_call.cmodifiedView file

@@ -1107,6 +1107,7 @@
11071107 TyKind st = comp_ntype(c, argv[0]);
11081108 buf_puts(b, "((void)sp_sleep(");
11091109 if (st == TY_INT) { buf_puts(b, "(double)"); emit_expr(c, argv[0], b); }
1110+ else if (st == TY_POLY) { buf_puts(b, "sp_poly_to_f("); emit_expr(c, argv[0], b); buf_puts(b, ")"); }
11101111 else emit_expr(c, argv[0], b);
11111112 buf_puts(b, "), (mrb_int)0)");
11121113 return;
@@ -8058,15 +8059,19 @@
80588059 }
80598060 if (is_fiber2) {
80608061 TyKind fvt = comp_ntype(c, argv[1]);
8062+ /* Fiber storage is poly-valued. A nil/void/untyped value has no scalar
8063+ C slot -- carry it boxed (`void _t = nil` is otherwise a type error). */
8064+ int fval_poly = (fvt == TY_POLY || fvt == TY_UNKNOWN || fvt == TY_NIL || fvt == TY_VOID);
80618065 int tf = ++g_tmp;
80628066 buf_puts(b, "({ ");
8063- emit_ctype(c, fvt != TY_UNKNOWN ? fvt : TY_POLY, b);
8067+ emit_ctype(c, fval_poly ? TY_POLY : fvt, b);
80648068 buf_printf(b, " _t%d = ", tf);
8065- emit_expr(c, argv[1], b);
8069+ if (fval_poly) emit_boxed(c, argv[1], b);
8070+ else emit_expr(c, argv[1], b);
80668071 buf_puts(b, "; sp_Fiber_storage_set(sp_fiber_current, ");
80678072 emit_expr(c, argv[0], b);
80688073 buf_puts(b, ", ");
8069- if (fvt != TY_POLY && fvt != TY_UNKNOWN) {
8074+ if (!fval_poly) {
80708075 char tfs[32]; snprintf(tfs, sizeof tfs, "_t%d", tf);
80718076 emit_boxed_text(c, fvt, tfs, b);
80728077 }