Commit cbc0df9f

cbc0df9f832dMerged

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

Description

feat(codegen): support Hash#each_value block on poly_poly_hash

The block dispatcher only knew about each / each_pair; each_value fell through to the unresolved-call warning and the block body was silently dropped. Adds a direct iteration path that walks vals[order[i]] and binds the block param to the value (poly).

Surfaced via optcarrot's PPU init entries.each_value {|a| a.uniq! {|entry| entry.object_id } }, where entries is a heterogeneous-key heterogeneous-value hash. Other hash shapes can join the same arm as they surface.

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

Details

Commit
cbc0df9f832d
Parent
d0429b167fe0

spinel_codegen.rbmodifiedView file

@@ -33649,6 +33649,40 @@
3364933649 end
3365033650 end
3365133651
33652+ # `hash.each_value { |v| ... }` for poly_poly_hash. Other hash
33653+ # shapes can be added here once they surface; the underlying
33654+ # representation is the same `vals[order[i]]` walk.
33655+ if mname == "each_value" && recv >= 0 && @nd_block[nid] >= 0
33656+ rt_ev = infer_type(recv)
33657+ if rt_ev == "poly_poly_hash"
33658+ rc_ev = compile_expr_gc_rooted(recv)
33659+ bp_ev = get_block_param(nid, 0)
33660+ has_bp_ev = 1
33661+ if bp_ev == ""
33662+ has_bp_ev = 0
33663+ bp_ev = "_v"
33664+ end
33665+ tmp_ev = new_temp
33666+ emit(" for (mrb_int " + tmp_ev + " = 0; " + tmp_ev + " < " + rc_ev + "->len; " + tmp_ev + "++) {")
33667+ if has_bp_ev == 1
33668+ emit(" sp_RbVal lv_" + bp_ev + " = " + rc_ev + "->vals[" + rc_ev + "->order[" + tmp_ev + "]];")
33669+ end
33670+ @indent = @indent + 1
33671+ push_scope
33672+ if has_bp_ev == 1
33673+ declare_var(bp_ev, "poly")
33674+ end
33675+ redo_label_ev = push_redo_label
33676+ emit_redo_label(redo_label_ev)
33677+ compile_stmts_body(@nd_body[@nd_block[nid]])
33678+ pop_redo_label
33679+ pop_scope
33680+ @indent = @indent - 1
33681+ emit(" }")
33682+ return 1
33683+ end
33684+ end
33685+
3365233686 if mname == "each_slice"
3365333687 if @nd_block[nid] >= 0
3365433688 compile_each_slice_block(nid)