Commit d0429b16

d0429b167fe0Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

feat(codegen): support arr[i] = v in expression position on int_array

The stmt-form is handled by compile_bracket_assign. In rvalue chains like outer = arr[i] = rhs the call lands in the expression dispatcher, which had no []= arm and emitted the unresolved-call warning + literal 0.

Surfaced via optcarrot PPU's @io_latch = @sp_ram[@regs_oam] = io_latch_mask(data) shape.

Lifts idx/val into temps so each subexpression evaluates once, emits the sp_IntArray_set side effect, and returns the rhs (Ruby []= semantics).

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
d0429b167fe0
Parent
d35f926a9d3d

spinel_codegen.rbmodifiedView file

@@ -26467,6 +26467,26 @@
2646726467 if mname == "replace" && recv_type == "int_array"
2646826468 return "(sp_IntArray_replace(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"
2646926469 end
26470+ # `a[i] = v` in expression position. The stmt-form is
26471+ # handled by `compile_bracket_assign`; in rvalue chains like
26472+ # `@io_latch = @sp_ram[i] = mask(data)` (optcarrot PPU), the
26473+ # call lands here. Lift idx/val into temps so each side is
26474+ # evaluated exactly once, then return the rhs (Ruby `[]=`
26475+ # semantics).
26476+ if mname == "[]=" && recv_type == "int_array"
26477+ args_id = @nd_arguments[nid]
26478+ if args_id >= 0
26479+ a_set = get_args(args_id)
26480+ if a_set.length >= 2
26481+ idx_tmp = new_temp
26482+ val_tmp = new_temp
26483+ emit(" mrb_int " + idx_tmp + " = " + compile_expr(a_set[0]) + ";")
26484+ emit(" mrb_int " + val_tmp + " = " + compile_expr(a_set[1]) + ";")
26485+ emit(" sp_IntArray_set(" + rc + ", " + idx_tmp + ", " + val_tmp + ");")
26486+ return val_tmp
26487+ end
26488+ end
26489+ end
2647026490 # take_while / drop_while: block-driven prefix scan. take_while
2647126491 # collects elements from the front while the block stays truthy;
2647226492 # drop_while skips them and returns the rest. Mirrors the