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

@@ -32348,6 +32348,26 @@
3234832348 # `sp_IntArray *_t = sp_N_two_mats(...); sp_IntArray_get(_t, i)`,
3234932349 # mismatching the actual sp_PtrArray * return.
3235032350 val_t_local = infer_type(val_id)
32351+ # Scalar int RHS: `a, b = 1`. CRuby semantics — first target gets
32352+ # the scalar, the rest get nil. Spinel's int slot can't carry nil
32353+ # so the rest land as 0 (acceptable subset behaviour). Other
32354+ # scalar types need slot-type coordination with analyze (which
32355+ # currently doesn't model multi-write scalar inference) and are
32356+ # deferred.
32357+ if val_t_local == "int"
32358+ scalar_v = compile_expr(val_id)
32359+ k = 0
32360+ while k < targets.length
32361+ tid = targets[k]
32362+ if k == 0
32363+ emit_multi_write_target(tid, scalar_v, "int")
32364+ else
32365+ emit_multi_write_target(tid, "0", "nil")
32366+ end
32367+ k = k + 1
32368+ end
32369+ return
32370+ end
3235132371 @needs_gc = 1
3235232372 tmp = new_temp
3235332373 if val_t_local == "poly_array"