Commit a8639f57
a8639f578040Merged
Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): multi-write from array-returning RHS to ivar/const targets
compile_multi_write's int_array-returning RHS branch (where the
RHS is a non-literal expression evaluating to an array — e.g.
.map { ... }, a method call) only emitted assignments for
LocalVariableTargetNode targets. InstanceVariableTargetNode
and ConstantTargetNode targets were silently dropped: the C
code compiled fine, but the ivars / constants stayed at their
default values (typically 0 or nil).
Repro:
class C
def initialize
@a, @b = [10, 20].map { |x| x + 1 }
end
attr_reader :a, :b
end
c = C.new
puts c.a # expected: 11; spinel emitted: 0
puts c.b # expected: 21; spinel emitted: 0
Add ivar + const target handling alongside the existing local
target handling in the int_array branch. Each target gets a
sp_IntArray_get(<tmp>, k) indexed extraction; ivar writes go
through self_arrow + sanitize_ivar(...), const writes through
cst_<NAME> (only when the constant has been registered, so we
don't emit assignments to undeclared symbols).
Test: test/multi_write_ivar_const_from_array_rhs.rb covers
ivar targets with .map { ... } RHS, mixed local + ivar, and
ivar targets with a top-level method call RHS.
(Constant-target coverage requires the multi-write-to-constants parser support, which lives in a sibling PR.)
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- a8639f578040
- Parent
- e341e5e20470
spinel_codegen.rbmodifiedView file
k = 0 while k < targets.length tid = targets[k] rhs = "sp_IntArray_get(" + tmp + ", " + k.to_s + ")" if @nd_type[tid] == "LocalVariableTargetNode" emit(" " + fiber_var_ref(@nd_name[tid]) + " = sp_IntArray_get(" + tmp + ", " + k.to_s + ");") emit(" " + fiber_var_ref(@nd_name[tid]) + " = " + rhs + ";") end if @nd_type[tid] == "InstanceVariableTargetNode" emit(" " + self_arrow + sanitize_ivar(@nd_name[tid]) + " = " + rhs + ";") end if @nd_type[tid] == "ConstantTargetNode" if find_const_idx(@nd_name[tid]) >= 0 emit(" cst_" + @nd_name[tid] + " = " + rhs + ";") end end k = k + 1 endtest/multi_write_ivar_const_from_array_rhs.rbaddedView file
Loading diff…