Commit 89aeabde
89aeabded473Merged
Ryan Seys <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
feat(codegen): string interpolation renders array containers, not pointers
93d04586 fixed Symbol interpolation ("#{:foo}" -> "foo" instead
of the raw sp_sym id). The same default-int fall-through bit every
container type stored as a pointer: puts "ints: #{[1,2,3]}"
printed a memory address like 4318536016 rather than CRuby's
"ints: [1, 2, 3]". Direct .inspect calls on the same arrays
already routed to sp_IntArray_inspect and friends, so the value
shape was right -- the gap was only in compile_interpolated.
- Add arms to
compile_interpolatedforint_array,float_array,str_array,sym_array,poly_array, and the four one-level nested<x>_array_ptr_arrayvariants. Each routes to the matchingsp_*Array_inspectruntime helper that already exists. - Add a
nilarm so"#{nil}"renders""(CRuby behaviour) instead of"0"from the default int path.
Hash interpolation ("#{ {a: 1} }") is also broken via the same
default path, but fixing it needs new sp_*Hash_inspect helpers
for the eight typed-Hash variants -- defer to a follow-up. The
audit also turned up that direct Hash#to_s / Hash#inspect
calls emit a "cannot resolve" warning on every typed-hash variant;
same root cause, same follow-up.
Test test/interp_array_container.rb covers each variant plus an
empty literal, a nested-array literal, and a nil interpolation.
Bootstrap fixpoint green; 619 / 619 pass.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 89aeabded473
- Parent
- e4d2ffaa5870
spinel_codegen.rbmodifiedView file
# a long long. fmt = fmt + "%s" arg_exprs.push("sp_exc_message(" + compile_expr(inner) + ")") elsif it == "nil" # CRuby: `"#{nil}"` -> `""`. Without an arm, # the default int path emitted `"0"`. fmt = fmt + "%s" arg_exprs.push("\"\"") elsif it == "int_array" fmt = fmt + "%s" arg_exprs.push("sp_IntArray_inspect(" + compile_expr(inner) + ")") elsif it == "float_array" fmt = fmt + "%s" arg_exprs.push("sp_FloatArray_inspect(" + compile_expr(inner) + ")") elsif it == "str_array" fmt = fmt + "%s" arg_exprs.push("sp_StrArray_inspect(" + compile_expr(inner) + ")") elsif it == "sym_array" # sym_array stores ids in an sp_IntArray # backing; sp_SymArray_inspect renders each # element as `:name` via sp_sym_to_s. fmt = fmt + "%s" arg_exprs.push("sp_SymArray_inspect(" + compile_expr(inner) + ")") elsif it == "poly_array" fmt = fmt + "%s" arg_exprs.push("sp_PolyArray_inspect(" + compile_expr(inner) + ")") elsif it == "int_array_ptr_array" fmt = fmt + "%s" arg_exprs.push("sp_IntArrayPtrArray_inspect(" + compile_expr(inner) + ")") elsif it == "float_array_ptr_array" fmt = fmt + "%s" arg_exprs.push("sp_FloatArrayPtrArray_inspect(" + compile_expr(inner) + ")") elsif it == "str_array_ptr_array" fmt = fmt + "%s" arg_exprs.push("sp_StrArrayPtrArray_inspect(" + compile_expr(inner) + ")") elsif it == "sym_array_ptr_array" fmt = fmt + "%s" arg_exprs.push("sp_SymArrayPtrArray_inspect(" + compile_expr(inner) + ")") else fmt = fmt + "%lld" arg_exprs.push("(long long)" + compile_expr(inner))test/interp_array_container.rbaddedView file
Loading diff…
test/interp_array_container.rb.expectedaddedView file
Loading diff…