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_interpolated for int_array, float_array, str_array, sym_array, poly_array, and the four one-level nested <x>_array_ptr_array variants. Each routes to the matching sp_*Array_inspect runtime helper that already exists.
  • Add a nil arm 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

@@ -14681,6 +14681,41 @@
1468114681 # a long long.
1468214682 fmt = fmt + "%s"
1468314683 arg_exprs.push("sp_exc_message(" + compile_expr(inner) + ")")
14684+ elsif it == "nil"
14685+ # CRuby: `"#{nil}"` -> `""`. Without an arm,
14686+ # the default int path emitted `"0"`.
14687+ fmt = fmt + "%s"
14688+ arg_exprs.push("\"\"")
14689+ elsif it == "int_array"
14690+ fmt = fmt + "%s"
14691+ arg_exprs.push("sp_IntArray_inspect(" + compile_expr(inner) + ")")
14692+ elsif it == "float_array"
14693+ fmt = fmt + "%s"
14694+ arg_exprs.push("sp_FloatArray_inspect(" + compile_expr(inner) + ")")
14695+ elsif it == "str_array"
14696+ fmt = fmt + "%s"
14697+ arg_exprs.push("sp_StrArray_inspect(" + compile_expr(inner) + ")")
14698+ elsif it == "sym_array"
14699+ # sym_array stores ids in an sp_IntArray
14700+ # backing; sp_SymArray_inspect renders each
14701+ # element as `:name` via sp_sym_to_s.
14702+ fmt = fmt + "%s"
14703+ arg_exprs.push("sp_SymArray_inspect(" + compile_expr(inner) + ")")
14704+ elsif it == "poly_array"
14705+ fmt = fmt + "%s"
14706+ arg_exprs.push("sp_PolyArray_inspect(" + compile_expr(inner) + ")")
14707+ elsif it == "int_array_ptr_array"
14708+ fmt = fmt + "%s"
14709+ arg_exprs.push("sp_IntArrayPtrArray_inspect(" + compile_expr(inner) + ")")
14710+ elsif it == "float_array_ptr_array"
14711+ fmt = fmt + "%s"
14712+ arg_exprs.push("sp_FloatArrayPtrArray_inspect(" + compile_expr(inner) + ")")
14713+ elsif it == "str_array_ptr_array"
14714+ fmt = fmt + "%s"
14715+ arg_exprs.push("sp_StrArrayPtrArray_inspect(" + compile_expr(inner) + ")")
14716+ elsif it == "sym_array_ptr_array"
14717+ fmt = fmt + "%s"
14718+ arg_exprs.push("sp_SymArrayPtrArray_inspect(" + compile_expr(inner) + ")")
1468414719 else
1468514720 fmt = fmt + "%lld"
1468614721 arg_exprs.push("(long long)" + compile_expr(inner))