Commit 61a12a45
61a12a452f0dMerged
Ryan Seys <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
fix(analyze,codegen): bridge no-recv IO calls; poly_array of procs; poly .call
Bundles three related fixes that the test fixture surfaces together:
-
puts/print/printfreached in expression context — the last statement of aproc { ... }body, a consumedif-arm, a ternary branch.compile_no_recv_call_exprhad no symmetric path for these no-recv IO methods, so the call fell through to warn_unresolved_call and emitted0without firing the side-effect. Fix: bridge throughcompile_io_call_stmt(nid, mname, -1)for the whitelistputs/print/printf(all three return nil in MRI), passing"0"up as the C expression value. Future no-recv void-IO methods need only a one-line whitelist addition. Also extractscompile_printf(nid)next tocompile_printso both dispatchers share the emitter. -
Heterogeneous array literals of procs (
[proc { ... }, ...]) were inferred asint_arrayand the construction emittedsp_IntArray_push(_, sp_proc_new(...))— int-from-pointer C-compile error. Add aproc/lambdaarm toinfer_array_elem_type_from_idsin bothspinel_analyze.rbandspinel_codegen.rbso such literals lower topoly_arrayand each element is boxed viasp_box_proc. Mirrors the existingis_hash_type(et)arm above. -
Poly
.call(...)dispatch. When the per-element block param ofeachiterating a poly_array of procs binds with static typepoly,p.calllands incompile_poly_method_call. Add anmname == "call"arm insideemit_poly_builtin_dispatchthat fires forcls_id == SP_BUILTIN_PROC: unbox via(sp_Proc *) recv.v.pand invokesp_proc_callwith the same mrb_int[] arg-packing convention. Lives after the user-class loop, so classes with their own.callmethod (e.g. functor objects) still resolve first.
Test (test/io_call_in_proc_body.rb) iterates an array of procs and
.calls each, exercising the IO bridge for puts / print / printf
plus the array-of-procs inference and poly .call dispatch:
[ proc { puts "a" }, proc { print "b\n" }, proc { printf("c=%d\n", 3) } ].each { |p| p.call }
Symbol#to_proc (&:call) is still TODO in spinel
(find_block_arg returns -1 for the SymbolNode shape); the
explicit-block form is the closest equivalent that works today.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 61a12a452f0d
- Parent
- 9c05e832a7c0
spinel_analyze.rbmodifiedView file
@needs_rb_value = 1 return "poly_array" end # Proc / lambda literals as elements (`[proc { ... }, proc { ... }]`): # each element is a heap-allocated sp_Proc pointer. Spinel has no # typed `proc_ptr_array` slot, so box via poly_array — sp_box_proc # is called on each push, and the poly-builtin dispatch on `arr[i]` # recovers the proc. Without this arm, the array's inferred type # fell back to `int_array`, and `sp_IntArray_push` was called with # a sp_Proc pointer — int-from-pointer C-compile error. if et == "proc" || et == "lambda" @needs_gc = 1 @needs_rb_value = 1 return "poly_array" end # Check if elements have mixed types k = 1 while k < elems.lengthspinel_codegen.rbmodifiedView file
Loading diff…
test/io_call_in_proc_body.rbaddedView file
Loading diff…
test/io_call_in_proc_body.rb.expectedaddedView file
Loading diff…