Commit 233226f9
233226f9c93fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
codegen: compute between? object operands before writing their decl prefix
Comparable#between? on a user type hoists self/lo/hi into g_pre as typed
temps. Each RHS was emitted after writing the T _tN = prefix to g_pre, so
when an operand (e.g. Temp.new(5)) itself hoisted a temp into g_pre (its
boxed-int ctor arg, rooted there), that nested declaration was spliced into
the middle of our half-written line, producing sp_Temp * _t7 = sp_RbVal _t10 = .... Emit each operand into its local buffer first so its g_pre
hoist lands before our declaration line. Fixes comparable_between_user_type.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 233226f9c93f
- Parent
- a4015e0b6a4d
src/codegen_call.cmodifiedView file
@@ -7686,17 +7686,21 @@
76867686
if (mi_b >= 0) {76877687
int ts = ++g_tmp, tlo = ++g_tmp, thi = ++g_tmp;76887688
const char *cname = c->classes[defcls_b].name;7689+
/* Compute each RHS into a local buffer first: emit_expr may itself7690+
hoist temps into g_pre (e.g. an arg `Temp.new(5)` roots its boxed7691+
int there). Doing that before writing our own `T _tN = ` prefix7692+
keeps the nested hoist from splitting our declaration line. */7693+
Buf rb; memset(&rb, 0, sizeof rb); emit_expr(c, recv, &rb);76897694
emit_indent(g_pre, g_indent);76907695
emit_ctype(c, rt, g_pre); buf_printf(g_pre, " _t%d = ", ts);7691-
Buf rb; memset(&rb, 0, sizeof rb); emit_expr(c, recv, &rb);76927696
buf_puts(g_pre, rb.p ? rb.p : ""); buf_puts(g_pre, ";\n"); free(rb.p);7697+
Buf lb; memset(&lb, 0, sizeof lb); emit_expr(c, argv[0], &lb);76937698
emit_indent(g_pre, g_indent);76947699
emit_ctype(c, rt, g_pre); buf_printf(g_pre, " _t%d = ", tlo);7695-
Buf lb; memset(&lb, 0, sizeof lb); emit_expr(c, argv[0], &lb);76967700
buf_puts(g_pre, lb.p ? lb.p : ""); buf_puts(g_pre, ";\n"); free(lb.p);7701+
Buf hb; memset(&hb, 0, sizeof hb); emit_expr(c, argv[1], &hb);76977702
emit_indent(g_pre, g_indent);76987703
emit_ctype(c, rt, g_pre); buf_printf(g_pre, " _t%d = ", thi);7699-
Buf hb; memset(&hb, 0, sizeof hb); emit_expr(c, argv[1], &hb);77007704
buf_puts(g_pre, hb.p ? hb.p : ""); buf_puts(g_pre, ";\n"); free(hb.p);77017705
buf_printf(b, "(sp_%s_%s((sp_%s *)_t%d, _t%d) >= 0 && sp_%s_%s((sp_%s *)_t%d, _t%d) <= 0)",77027706
cname, mc("<=>"), cname, ts, tlo,