Commit e192423d
e192423dde46Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
codegen: scalar int RHS in multi-assign no longer emits IntArray * = int
`a, b = 1` previously emitted `sp_IntArray *_t = 1LL;` which failed to compile. CRuby semantics: the first slot gets the scalar, the rest are nil. Spinel's int slot can't carry nil so the rest land as 0 — acceptable for the subset since the previous behaviour was a hard compile error.
Only the int scalar case is wired here. Other scalar types (string, symbol, float) need slot-type coordination with analyze (which currently doesn't model multi-write scalar inference, so the slots get typed as int and the typed value is stored into the wrong slot shape) and are deferred.
Fixes #977
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- e192423dde46
- Parent
- a1ec07c78c49
spinel_codegen.rbmodifiedView file
# `sp_IntArray *_t = sp_N_two_mats(...); sp_IntArray_get(_t, i)`, # mismatching the actual sp_PtrArray * return. val_t_local = infer_type(val_id) # Scalar int RHS: `a, b = 1`. CRuby semantics — first target gets # the scalar, the rest get nil. Spinel's int slot can't carry nil # so the rest land as 0 (acceptable subset behaviour). Other # scalar types need slot-type coordination with analyze (which # currently doesn't model multi-write scalar inference) and are # deferred. if val_t_local == "int" scalar_v = compile_expr(val_id) k = 0 while k < targets.length tid = targets[k] if k == 0 emit_multi_write_target(tid, scalar_v, "int") else emit_multi_write_target(tid, "0", "nil") end k = k + 1 end return end @needs_gc = 1 tmp = new_temp if val_t_local == "poly_array"test/multi_write_scalar_rhs.rbaddedView file
Loading diff…
test/multi_write_scalar_rhs.rb.expectedaddedView file
Loading diff…