Commit 44d9090a
44d9090a484dMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
fix: benchmark improvements - global constants, yield params, clamp conflict
- Make constants file-scope globals (accessible from all functions)
- Fix yield_params_suffix for zero-param methods (was generating "voidvoid")
- Rename sp_clamp to sp_int_clamp to avoid conflicts with user methods
- Fix sp_str_split to return empty array for empty strings
- Fix << operator to always enable string helpers
- Fix ARGV[] to infer "string" return type
Benchmarks: 26/39 OK (up from 24), 1 CC error (down from 5) Tests: 58/60 pass (unchanged)
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 44d9090a484d
- Parent
- 040080709c79
spinel_codegen.rbmodifiedView file
@@ -3986,6 +3986,7 @@
39863986
@needs_string_helpers = 139873987
end39883988
if mname == "<<"3989+
@needs_string_helpers = 139893990
if @nd_receiver[nid] >= 039903991
rt = infer_type(@nd_receiver[nid])39913992
if rt == "string"@@ -4828,6 +4829,7 @@
48284829
end48294830
emit_class_structs48304831
emit_forward_decls4832+
emit_global_constants48314833
emit_class_methods48324834
emit_toplevel_methods48334835
emit_main@@ -4867,7 +4869,7 @@
48674869
emit_raw("}")48684870
emit_raw("")48694871
emit_raw("static mrb_int sp_gcd(mrb_int a,mrb_int b){if(a<0)a=-a;if(b<0)b=-b;while(b){mrb_int t=b;b=a%b;a=t;}return a;}")4870-
emit_raw("static mrb_int sp_clamp(mrb_int v,mrb_int lo,mrb_int hi){return v<lo?lo:v>hi?hi:v;}")4872+
emit_raw("static mrb_int sp_int_clamp(mrb_int v,mrb_int lo,mrb_int hi){return v<lo?lo:v>hi?hi:v;}")48714873
emit_raw("static const char*sp_int_chr(mrb_int n){char*s=(char*)malloc(2);s[0]=(char)n;s[1]=0;return s;}")48724874
emit_raw("typedef struct{mrb_int first;mrb_int last;}sp_Range;")48734875
emit_raw("static sp_Range sp_range_new(mrb_int f,mrb_int l){sp_Range r;r.first=f;r.last=l;return r;}")@@ -5109,6 +5111,19 @@
51095111
end51105112
51115113
# ---- Struct emission ----5114+
def emit_global_constants5115+
# Emit file-scope constant declarations (initialized in main)5116+
i = 05117+
while i < @const_names.length5118+
ctp = c_type(@const_types[i])5119+
emit_raw("static " + ctp + " cst_" + @const_names[i] + " = " + c_default_val(@const_types[i]) + ";")5120+
i = i + 15121+
end5122+
if @const_names.length > 05123+
emit_raw("")5124+
end5125+
end5126+
51125127
def emit_class_structs51135128
# Forward declare typedefs51145129
i = 0@@ -5279,8 +5294,8 @@
52795294
end52805295
52815296
def yield_params_suffix(mi)5282-
pnames = @meth_param_names[mi].split(",")5283-
if pnames.length == 05297+
pd = method_params_decl(mi)5298+
if pd == ""52845299
return "void (*_block)(mrb_int, void*), void *_benv"52855300
end52865301
return ", void (*_block)(mrb_int, void*), void *_benv"@@ -5346,6 +5361,9 @@
53465361
return result53475362
end53485363
if pnames.length == 05364+
if @meth_has_yield[mi] == 15365+
return ""5366+
end53495367
return "void"53505368
end53515369
result = ""@@ -6387,12 +6405,11 @@
63876405
j = j + 163886406
end63896407
6390-
# Constants6408+
# Constants (initialize global declarations)63916409
i = 063926410
while i < @const_names.length6393-
ctp = c_type(@const_types[i])63946411
val = compile_expr(@const_expr_ids[i])6395-
emit(" " + ctp + " cst_" + @const_names[i] + " = " + val + ";")6412+
emit(" cst_" + @const_names[i] + " = " + val + ";")63966413
i = i + 163976414
end63986415
@@ -7676,7 +7693,7 @@
76767693
if args_id >= 076777694
a = get_args(args_id)76787695
if a.length >= 27679-
return "sp_clamp(" + rc + ", " + compile_expr(a[0]) + ", " + compile_expr(a[1]) + ")"7696+
return "sp_int_clamp(" + rc + ", " + compile_expr(a[0]) + ", " + compile_expr(a[1]) + ")"76807697
end76817698
end76827699
end