Commit 93df4414
93df441492a2Merged
Sam Ruby <[email protected]> · 5 months ago · 5 files · ~5 modified
Description
Address PR review: cover bool and all pointer-backed boundary types
Generalize the return/arg boundary coercion beyond int/float/string/object:
- emit_unbox_node: handle TY_BOOL (int-backed, via sp_poly_to_i), and
unbox strings + every pointer-backed type (arrays, hashes, procs,
fibers, ...) through the existing emit_unbox_text helper rather than a
hand-rolled object-only cast. By-value types (Range/Time/...) have no
.v.pform and fall through unchanged. - emit_arg_or_default: same generalization for object/pointer params,
detected via c_type_name's trailing
*.
emit_unbox_text already emits the correct (T *)(expr).v.p form (postfix
. binds tighter than the cast), so the precedence is fine.
Extends the boundary fixture with bool-return and an Array[Integer] return+argument round-trip (a non-object pointer type), exercising the new paths; output matches reference Ruby. Full suite: 892 pass.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 93df441492a2
- Parent
- 4c9425787398
src/codegen_fold.cmodifiedView file
@@ -2201,13 +2201,22 @@
22012201
/* poly arg into a concrete param (holds the right type at runtime):22022202
coerce, else the generated C assigns sp_RbVal to a const char* /22032203
mrb_int / mrb_float / sp_<Class>* slot. */2204+
const char *ptn = c_type_name(pt);22042205
if (at == TY_POLY && pt == TY_STRING) { buf_puts(out, "sp_poly_to_s("); emit_expr(c, provided, out); buf_puts(out, ")"); }22052206
else if (at == TY_POLY && pt == TY_FLOAT) { buf_puts(out, "sp_poly_to_f("); emit_expr(c, provided, out); buf_puts(out, ")"); }22062207
else if (at == TY_POLY && (pt == TY_INT || pt == TY_BOOL)) { buf_puts(out, "sp_poly_to_i("); emit_expr(c, provided, out); buf_puts(out, ")"); }2207-
/* poly arg into an object param: unbox the pointer (a nil box has v.p2208-
== NULL, the object-nil representation). The callee's RBS asserts the2209-
class, mirroring the seed-trusting coercion on the return side. */2210-
else if (at == TY_POLY && ty_is_object(pt)) { buf_printf(out, "(sp_%s *)(", c->classes[ty_object_class(pt)].name); emit_expr(c, provided, out); buf_puts(out, ").v.p"); }2208+
/* poly arg into an object or other pointer-backed param (array, proc,2209+
...): unbox the pointer via emit_unbox_text (a nil box has v.p ==2210+
NULL, the pointer-nil representation). The callee's RBS asserts the2211+
type, mirroring the seed-trusting coercion on the return side. (Typed-2212+
value hashes are handled by the ty_is_hash block above; by-value types2213+
have no .v.p form and fall through to a plain emit.) */2214+
else if (at == TY_POLY && (ty_is_object(pt) || (ptn && ptn[0] && ptn[strlen(ptn) - 1] == '*'))) {2215+
Buf ub; memset(&ub, 0, sizeof ub);2216+
emit_expr(c, provided, &ub);2217+
emit_unbox_text(c, pt, ub.p ? ub.p : "", out);2218+
free(ub.p);2219+
}22112220
else emit_expr(c, provided, out);22122221
}22132222
}src/codegen_stmt.cmodifiedView file
Loading diff…
test/rbs-seed/boundary.expectedmodifiedView file
Loading diff…
test/rbs-seed/boundary.rbmodifiedView file
Loading diff…
test/rbs-seed/sig/boundary.rbsmodifiedView file
Loading diff…