Commit b16ee8e5

b16ee8e509acMerged

Richard Ramsden <[email protected]> · 6 months ago · 4 files · +1 added · ~3 modified

Description

feat: support splat in multi-assign destructuring

Multi-assign now handles a SplatNode rest target (a, *b = arr, *a, b = arr, a, *b, c = arr) for every typed-array element kind: int, str, float, sym, ptr, and poly. ArrayNode-literal RHS picks the precise element type per fixed target (so heterogeneous literals like [1, "x", 2.0] don't have to flatten through the poly boxer), and poly-target slots are boxed via box_value_to_poly when the source is of a different static type.

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

Details

Commit
b16ee8e509ac
Parent
9f101b63bdce

lib/sp_runtime.hmodifiedView file

@@ -252,6 +252,7 @@
252252 static inline mrb_bool sp_PtrArray_empty(sp_PtrArray*a){return a->len==0;}
253253 static void sp_PtrArray_reverse_bang(sp_PtrArray*a){for(mrb_int i=0,j=a->len-1;i<j;i++,j--){void*t=a->data[i];a->data[i]=a->data[j];a->data[j]=t;}}
254254 static sp_PtrArray*sp_PtrArray_dup(sp_PtrArray*a){sp_PtrArray*b=sp_PtrArray_new_scan(a->scan_elem);for(mrb_int i=0;i<a->len;i++)sp_PtrArray_push(b,a->data[i]);return b;}
255+static sp_PtrArray*sp_PtrArray_slice(sp_PtrArray*a,mrb_int start,mrb_int len){if(start<0)start+=a->len;if(start<0)start=0;sp_PtrArray*b=sp_PtrArray_new_scan(a->scan_elem);if(start>=a->len||len<=0)return b;if(start+len>a->len)len=a->len-start;for(mrb_int i=0;i<len;i++)sp_PtrArray_push(b,a->data[start+i]);return b;}
255256 static void sp_PtrArray_shuffle_bang(sp_PtrArray*a){for(mrb_int i=a->len-1;i>0;i--){mrb_int j=(mrb_int)(rand()%(i+1));void*t=a->data[i];a->data[i]=a->data[j];a->data[j]=t;}}
256257 static sp_PtrArray*sp_PtrArray_shuffle(sp_PtrArray*a){sp_PtrArray*b=sp_PtrArray_dup(a);sp_PtrArray_shuffle_bang(b);return b;}
257258