Commit 6678332b
6678332b8d44Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · ~3 modified
Description
Fix array * string join, multi-var for, inject bitops, Integer#div, split(nil)
- codegen: array * string calls sp_*Array_join (array join by separator)
- analyze+codegen: for a, b in coll with MultiTargetNode destructuring
- codegen: inject/reduce handles bitwise ops (&, |, ^, <<, >>) on int arrays
- analyze+codegen: empty array literal [] treated as int_array for inject/reduce
- analyze+codegen: Integer#div as floor division (sp_idiv)
- lib/sp_runtime.h: sp_poly_get_sym/sp_poly_get_str for poly receiver []
- codegen: poly receiver [] with sym/str/int arg dispatches to runtime helpers
- codegen: split(nil) routes to sp_str_split_ws (same as no-arg whitespace mode)
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 6678332b8d44
- Parent
- 65acf2f90b71
lib/sp_runtime.hmodifiedView file
@@ -3638,6 +3638,22 @@
36383638
in shorthand: `{a: 1, b: "x"}` rather than `{:a=>1, :b=>"x"}`. */36393639
static const char*sp_SymPolyHash_inspect(sp_SymPolyHash*h){if(!h){char*r=sp_str_alloc_raw(3);r[0]='{';r[1]='}';r[2]=0;sp_str_set_len(r,2);return r;}sp_String*s=sp_String_new("{");for(mrb_int i=0;i<h->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_sym_to_s(h->order[i]));sp_String_append(s,": ");sp_String_append(s,sp_poly_inspect(sp_SymPolyHash_get(h,h->order[i])));}sp_String_append(s,"}");return s->data;}36403640
3641+
/* poly_val[sym_key]: runtime dispatch for poly receiver `[]` with symbol arg. */3642+
static sp_RbVal sp_poly_get_sym(sp_RbVal v, sp_sym key) {3643+
if (v.tag != SP_TAG_OBJ) return sp_box_nil();3644+
switch (v.cls_id) {3645+
case SP_BUILTIN_SYM_POLY_HASH: return sp_SymPolyHash_get((sp_SymPolyHash*)v.v.p, key);3646+
default: return sp_box_nil();3647+
}3648+
}3649+
/* poly_val[str_key]: runtime dispatch for poly receiver `[]` with string arg. */3650+
static sp_RbVal sp_poly_get_str(sp_RbVal v, const char *key) {3651+
if (v.tag != SP_TAG_OBJ) return sp_box_nil();3652+
switch (v.cls_id) {3653+
case SP_BUILTIN_STR_POLY_HASH: return sp_StrPolyHash_get((sp_StrPolyHash*)v.v.p, key);3654+
default: return sp_box_nil();3655+
}3656+
}36413657
/* PolyPolyHash: heterogeneous keys + values (both sp_RbVal). For36423658
primitives the hash/eql is tag-based (value equality); for OBJ tag36433659
the default is pointer identity. Codegen patches sp_obj_hash_hook /src/analyze.cmodifiedView file
Loading diff…
src/codegen.cmodifiedView file
Loading diff…