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
end emit(" " + self_arrow + sanitize_ivar(iname) + " = " + v + ";") end return end if @nd_type[tid] == "CallTargetNode" # `obj.attr = val` style — used as one slot in a multi-write # destructure. Lower as either a direct ivar write (when the # receiver class has an attr_writer for the name) or as a call # to `sp_<C>_<attr>_eq`. recv_id = @nd_receiver[tid] mname = @nd_name[tid] if mname.end_with?("=") mname = mname[0, mname.length - 1] end recv_t = infer_type(recv_id) recv_c = compile_expr(recv_id) if recv_t.start_with?("obj_") cls_n = recv_t[4, recv_t.length - 4] ci_w = find_class_idx(cls_n) if cls_has_attr_writer(ci_w, mname) == 1 emit(" " + recv_c + "->iv_" + mname + " = " + value_expr + ";") else emit(" sp_" + cls_n + "_" + mname + "_eq(" + recv_c + ", " + value_expr + ");") end end end end if @nd_type[tid] == "LocalVariableTargetNode" emit(" " + fiber_var_ref(@nd_name[tid]) + " = sp_IntArray_get(" + tmp + ", " + k.to_s + ");") end if @nd_type[tid] == "CallTargetNode" # `obj.attr = <slot>` in a multi-write context. # Inline as a direct ivar write when the recv class has an # attr_writer; otherwise fall back to the generated setter. recv_id = @nd_receiver[tid] mname = @nd_name[tid] if mname.end_with?("=") mname = mname[0, mname.length - 1] end recv_t = infer_type(recv_id) recv_c = compile_expr(recv_id) slot_expr = "sp_IntArray_get(" + tmp + ", " + k.to_s + ")" if recv_t.start_with?("obj_") cls_n = recv_t[4, recv_t.length - 4] ci_w = find_class_idx(cls_n) if cls_has_attr_writer(ci_w, mname) == 1 emit(" " + recv_c + "->iv_" + mname + " = " + slot_expr + ";") else emit(" sp_" + cls_n + "_" + mname + "_eq(" + recv_c + ", " + slot_expr + ");") end end end k = k + 1 end endspinel_parse.cmodifiedView file
Loading diff…
test/multi_write_setter.rbaddedView file
Loading diff…