Commit 87579127
87579127d3d6Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 6 files · +2 added · ~4 modified
Description
Merge PR #1518: bind missing block and proc params to nil
A block/proc invoked with fewer arguments than it declares bound the
unsupplied params to the typed zero (0 for an int slot, a stale value for a
poly), so proc { |a, b| p b }.call(1) printed 0 where CRuby yields nil.
Each proc-body param binding is now guarded on argc: a param past the supplied count takes its slot's nil sentinel (SP_INT_NIL for int/bool, sp_float_nil() for float, sp_box_nil() for poly, fixing a stale read of the reused static side-channel). String interpolation of an int slot now routes through sp_int_interp, rendering the nil sentinel as "" (CRuby interpolates nil as empty) and every other value as its decimal. bundle_tiny_misc's expected output, which had baked the old zero-fill, is regenerated from the ruby oracle. Adds test/proc_arity_nil.rb.
Combined-state gates: test 1003/0/0, bench 57/57, optcarrot checksum 59662.
Closes #1518
Co-authored-by: Ryan Seys [email protected] Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 87579127d3d6
- Parent
- 823c59693dba
- Merge parent
- e87134841bdf
lib/sp_runtime.hmodifiedView file
/* Issue #760: NULL entries treated as empty strings. */static const char*sp_str_concat_arr(const char *const *parts,int n){size_t total=0;for(int i=0;i<n;i++)total+=sp_str_byte_len(parts[i]?parts[i]:"");char*r=sp_str_alloc(total);char*p=r;for(int i=0;i<n;i++){const char*s=parts[i]?parts[i]:"";size_t sl=sp_str_byte_len(s);memcpy(p,s,sl);p+=sl;}return r;}static const char*sp_int_to_s(mrb_int n){char*b=sp_str_alloc_raw(32);int len=snprintf(b,32,"%lld",(long long)n);if(len<0)len=0;sp_str_set_len(b,(size_t)len);return b;}/* String-interpolation of an int slot: a nil sentinel renders as the empty string (CRuby interpolates nil as ""), every other value as its decimal. */static const char*sp_int_interp(mrb_int n){return n==SP_INT_NIL?sp_str_empty:sp_int_to_s(n);}static const char*sp_int_to_s_base(mrb_int n,mrb_int base){if(base<2||base>36)base=10;char*b=sp_str_alloc_raw(72);char tmp[72];int i=0;int neg=0;uint64_t u;if(n<0){neg=1;u=(uint64_t)(-(n+1))+1;}else{u=(uint64_t)n;}if(u==0){tmp[i++]='0';}else{while(u>0){mrb_int d=u%base;tmp[i++]=d<10?'0'+d:'a'+d-10;u/=base;}}int j=0;if(neg)b[j++]='-';while(i>0)b[j++]=tmp[--i];b[j]=0;sp_str_set_len(b,(size_t)j);return b;}/* Float#to_s (Ruby semantics): produce the shortest decimal that round-trips back to the same double, formatted per CRuby — fixedsrc/codegen.cmodifiedView file
Loading diff…
src/codegen_expr.cmodifiedView file
Loading diff…
test/bundle_tiny_misc.rb.expectedmodifiedView file
Loading diff…
test/proc_arity_nil.rbaddedView file
Loading diff…
test/proc_arity_nil.rb.expectedaddedView file
Loading diff…