Commit 1a76e599
1a76e599863aMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): sym_poly_hash.merge(sym_int_hash) positional-arg dispatch
Sam Ruby's #559. Sibling of #551 (which closed the
KeywordHashNode arg path). The positional case
h.merge(other) where other is a sym_int_hash variable
or literal fell through to the unsupported-call warning
and silently emit-0.
Mirror the existing sym_str_hash cross-variant arm (#515): when the merge argument's static type is sym_int_hash, route to a new sp_SymPolyHash_merge_int runtime helper that iterates the arg's pairs and boxes each int value via sp_box_int into the result sp_SymPolyHash slot. Helper is emitted as part of emit_sym_int_hash_runtime so it's gated by @needs_sym_int_hash (both typedefs it references are either always-present sp_SymPolyHash or already-gated sp_SymIntHash).
Closes #559
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 1a76e599863a
- Parent
- 2d7eba6fc3dd
spinel_codegen.rbmodifiedView file
# so the has_key? guard is redundant — drop it for two lookups per # element instead of three. emit_raw("static sp_SymIntHash*sp_SymArray_tally(sp_IntArray*a){sp_SymIntHash*h=sp_SymIntHash_new();for(mrb_int i=0;i<a->len;i++){sp_sym k=(sp_sym)a->data[a->start+i];sp_SymIntHash_set(h,k,sp_SymIntHash_get(h,k)+1);}return h;}") # Cross-variant merge: sym_poly_hash receiver merging in a # sym_int_hash arg boxes each int value into sp_RbVal so the # result's poly slots are populated correctly. Sibling of # sp_SymPolyHash_merge_str (#515). Issue #559. emit_raw("static sp_SymPolyHash*sp_SymPolyHash_merge_int(sp_SymPolyHash*a,sp_SymIntHash*b){sp_SymPolyHash*r=sp_SymPolyHash_new();for(mrb_int i=0;i<a->len;i++)sp_SymPolyHash_set(r,a->order[i],sp_SymPolyHash_get(a,a->order[i]));for(mrb_int i=0;i<b->len;i++)sp_SymPolyHash_set(r,b->order[i],sp_box_int(sp_SymIntHash_get(b,b->order[i])));return r;}") emit_raw("") end tmp = new_temp emit(" sp_SymPolyHash *" + tmp + " = sp_SymPolyHash_merge_str(" + rc + ", " + compile_expr(aargs[0]) + ");") return tmp # Cross-variant: sym_int_hash arg merged into a # sym_poly_hash receiver. Issue #559. elsif arg_t == "sym_int_hash" tmp = new_temp emit(" sp_SymPolyHash *" + tmp + " = sp_SymPolyHash_merge_int(" + rc + ", " + compile_expr(aargs[0]) + ");") return tmp elsif arg_t == "poly" # Poly-typed local whose runtime value is a sym_poly_hash # (typical when an `is_a?` branch widened the statictest/sym_poly_hash_merge_sym_int.rbaddedView file
Loading diff…
test/sym_poly_hash_merge_sym_int.rb.expectedaddedView file
Loading diff…