Commit 1ce1cf3e
1ce1cf3e7444Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified
Description
Merge pull request #1412 from ryanseys/rs-c-proc-float-ret
feat(proc): return a Float from a proc/lambda through .call
Details
- Commit
- 1ce1cf3e7444
- Parent
- 070c929e6280
- Merge parent
- 5d47ba89882b
src/codegen.cmodifiedView file
@@ -870,15 +870,17 @@
870870
}871871
/* The proc fn returns mrb_int (the ABI); heap-pointer values (strings,872872
arrays, hashes, objects) are laundered through (mrb_int)(uintptr_t).873-
TY_POLY values are stored in _sp_proc_poly_ret (file-static sp_RbVal)874-
before return; the call site reads it back.875-
Float/range/time don't fit the slot and defer. */873+
TY_POLY and float values are stored in _sp_proc_poly_ret (file-static874+
sp_RbVal) before return -- float boxed via sp_box_float -- and the call875+
site reads it back (unboxing float with sp_poly_to_f).876+
Range/time don't fit the slot and defer. */876877
int ret_ptr = proc_slot_is_ptr(ret);877878
int ret_void = (ret == TY_VOID); /* body's last expr has no value (e.g. puts) */878879
int ret_poly = (ret == TY_POLY);879-
if (!proc_slot_is_direct(ret) && !ret_ptr && !ret_void && !ret_poly) {880+
int ret_fbox = (ret == TY_FLOAT); /* boxed through the poly return slot */881+
if (!proc_slot_is_direct(ret) && !ret_ptr && !ret_void && !ret_poly && !ret_fbox) {880882
free(params.v); free(used.v); free(locals.v); free(caps.v);881-
unsupported(c, create, "proc with float/range/time return (later slice)");883+
unsupported(c, create, "proc with range/time return (later slice)");882884
return;883885
}884886
@@ -969,9 +971,10 @@
969971
}970972
else buf_puts(pb, " return 0;\n");971973
}972-
else if (ret_poly) {973-
/* Store the sp_RbVal result in the file-static _sp_proc_poly_ret slot;974-
the call site reads it back after sp_proc_call returns. */974+
else if (ret_poly || ret_fbox) {975+
/* Store the result in the file-static _sp_proc_poly_ret slot (boxed:976+
a float tail becomes sp_box_float via g_result_poly); the call site977+
reads it back after sp_proc_call returns. */975978
if (!g_needs_proc_poly_retslot) {976979
g_needs_proc_poly_retslot = 1;977980
buf_puts(&g_proc_protos, "static sp_RbVal _sp_proc_poly_ret;\n");src/codegen_call.cmodifiedView file
Loading diff…
test/proc_float_return.rbaddedView file
Loading diff…
test/proc_float_return.rb.expectedaddedView file
Loading diff…