Commit bef69f24

bef69f244ae5Merged

Yusuke Endoh <[email protected]> · 6 months ago · 3 files · +1 added · ~2 modified

Description

feat(parse+codegen): CallTargetNode in multi-write targets

PM_CALL_TARGET_NODE (obj.attr = ... appearing as one slot in a multi-write destructure, e.g. a, b, obj.attr = arr) was not emitted by the parser, so codegen's target list saw a hole and silently dropped the setter assignment.

Add the parser case and handle CallTargetNode in both the ArrayNode RHS branch and the IntArray-returning RHS branch of compile_multi_write. Inline as a direct iv_<name> write when the receiver class has an attr_writer for the name; otherwise emit a sp_<Cls>_<name>_eq() call to the explicit setter.

This lets optcarrot's PPU#setup_frame multi-assign reach @cpu.next_frame_clock so the CPU outer loop iterates instead of exiting on the initial 0 == 0 check.

Details

Commit
bef69f244ae5
Parent
eaad8a4edb93

spinel_codegen.rbmodifiedView file

@@ -22380,6 +22380,29 @@
2238022380 end
2238122381 emit(" " + self_arrow + sanitize_ivar(iname) + " = " + v + ";")
2238222382 end
22383+ return
22384+ end
22385+ if @nd_type[tid] == "CallTargetNode"
22386+ # `obj.attr = val` style — used as one slot in a multi-write
22387+ # destructure. Lower as either a direct ivar write (when the
22388+ # receiver class has an attr_writer for the name) or as a call
22389+ # to `sp_<C>_<attr>_eq`.
22390+ recv_id = @nd_receiver[tid]
22391+ mname = @nd_name[tid]
22392+ if mname.end_with?("=")
22393+ mname = mname[0, mname.length - 1]
22394+ end
22395+ recv_t = infer_type(recv_id)
22396+ recv_c = compile_expr(recv_id)
22397+ if recv_t.start_with?("obj_")
22398+ cls_n = recv_t[4, recv_t.length - 4]
22399+ ci_w = find_class_idx(cls_n)
22400+ if cls_has_attr_writer(ci_w, mname) == 1
22401+ emit(" " + recv_c + "->iv_" + mname + " = " + value_expr + ";")
22402+ else
22403+ emit(" sp_" + cls_n + "_" + mname + "_eq(" + recv_c + ", " + value_expr + ");")
22404+ end
22405+ end
2238322406 end
2238422407 end
2238522408
@@ -22588,6 +22611,28 @@
2258822611 if @nd_type[tid] == "LocalVariableTargetNode"
2258922612 emit(" " + fiber_var_ref(@nd_name[tid]) + " = sp_IntArray_get(" + tmp + ", " + k.to_s + ");")
2259022613 end
22614+ if @nd_type[tid] == "CallTargetNode"
22615+ # `obj.attr = <slot>` in a multi-write context.
22616+ # Inline as a direct ivar write when the recv class has an
22617+ # attr_writer; otherwise fall back to the generated setter.
22618+ recv_id = @nd_receiver[tid]
22619+ mname = @nd_name[tid]
22620+ if mname.end_with?("=")
22621+ mname = mname[0, mname.length - 1]
22622+ end
22623+ recv_t = infer_type(recv_id)
22624+ recv_c = compile_expr(recv_id)
22625+ slot_expr = "sp_IntArray_get(" + tmp + ", " + k.to_s + ")"
22626+ if recv_t.start_with?("obj_")
22627+ cls_n = recv_t[4, recv_t.length - 4]
22628+ ci_w = find_class_idx(cls_n)
22629+ if cls_has_attr_writer(ci_w, mname) == 1
22630+ emit(" " + recv_c + "->iv_" + mname + " = " + slot_expr + ";")
22631+ else
22632+ emit(" sp_" + cls_n + "_" + mname + "_eq(" + recv_c + ", " + slot_expr + ");")
22633+ end
22634+ end
22635+ end
2259122636 k = k + 1
2259222637 end
2259322638 end