Commit 9ff8a6a3

9ff8a6a34432Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · ~3 modified

Description

Hash#to_proc, multi-char string range #to_a, Hash#key

  • Hash#to_proc: a Proc mapping a key to the hash's value, closing over the hash via a per-variant lookup fn matching the sp_proc_call ABI (poly values ride _sp_proc_poly_ret). analyze returns TY_PROC and records the value type as the proc's call-return type.
  • String range #to_a now uses sp_StrArray_from_string_range (succ-based) so multi-character ranges like "aa".."ac" enumerate correctly instead of folding to a single ASCII-char loop.
  • Hash#key(value) on a symbol-keyed hash via sp_SymPolyHash_key.

Fixes bundle_tiny_misc.

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

Details

Commit
9ff8a6a34432
Parent
5718ac5f8f6f

lib/sp_runtime.hmodifiedView file

@@ -3835,6 +3835,7 @@
38353835 static sp_IntArray*sp_SymPolyHash_keys(sp_SymPolyHash*h){sp_IntArray*a=sp_IntArray_new();for(mrb_int i=0;i<h->len;i++)sp_IntArray_push(a,(mrb_int)h->order[i]);return a;}
38363836 static sp_PolyArray*sp_SymPolyHash_values(sp_SymPolyHash*h){sp_PolyArray*a=sp_PolyArray_new();for(mrb_int i=0;i<h->len;i++)sp_PolyArray_push(a,sp_SymPolyHash_get(h,h->order[i]));return a;}
38373837 static mrb_bool sp_SymPolyHash_has_value(sp_SymPolyHash*h,sp_RbVal v){if(!h)return FALSE;for(mrb_int i=0;i<h->len;i++)if(sp_poly_eq(sp_SymPolyHash_get(h,h->order[i]),v))return TRUE;return FALSE;}
3838+static sp_sym sp_SymPolyHash_key(sp_SymPolyHash*h,sp_RbVal v){if(!h)return (sp_sym)-1;for(mrb_int i=0;i<h->len;i++)if(sp_poly_eq(sp_SymPolyHash_get(h,h->order[i]),v))return h->order[i];return (sp_sym)-1;}
38383839 static sp_SymPolyHash*sp_SymPolyHash_merge(sp_SymPolyHash*a,sp_SymPolyHash*b){sp_SymPolyHash*r=sp_SymPolyHash_new();r->default_v=a->default_v;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_SymPolyHash_get(b,b->order[i]));return r;}
38393840 /* Hash#delete for sym_poly_hash. Removes key and re-tombstones the
38403841 slot, shifting probe-chain successors backward and dropping the