Commit 6a5a8494

6a5a84942787Merged

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

Description

Emit pointer-backed ivar ||=, fix cross-kind concat, coerce Complex.polar args

  • @fiber ||= Fiber.new { ... } (PPU#run) was dropped entirely: the ivar or-write only handled poly/bool/int/string slots, so a fiber (and other pointer-backed object/array/hash/proc) slot emitted nothing and the fiber was never created, segfaulting at resume. Emit if(!ref) ref=v for those.
  • Array#concat now reads the source with its own array kind and coerces each element into the receiver's element type (IntArray#concat(PolyArray)).
  • Complex.polar coerces poly magnitude/angle args via sp_poly_to_f.

optcarrot now compiles and runs end to end (checksum still off).

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

Details

Commit
6a5a84942787
Parent
7416ab243e35

src/codegen.cmodifiedView file

@@ -52,6 +52,15 @@
5252 else emit_expr(c, node, b);
5353 }
5454
55+/* Emit a node as an mrb_float. A poly value is unboxed via sp_poly_to_f; any
56+ other (numeric) value is plain-cast, matching the legacy `(mrb_float)(...)`. */
57+void emit_float_expr(Compiler *c, int node, Buf *b) {
58+ if (comp_ntype(c, node) == TY_POLY) {
59+ buf_puts(b, "sp_poly_to_f("); emit_expr(c, node, b); buf_puts(b, ")");
60+ }
61+ else { buf_puts(b, "(mrb_float)("); emit_expr(c, node, b); buf_puts(b, ")"); }
62+}
63+
5564 void emit_boxed(Compiler *c, int node, Buf *b) {
5665 TyKind t = comp_ntype(c, node);
5766 if (t == TY_POLY) { emit_expr(c, node, b); return; }