Commit d5706015

d5706015539cMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · +1 added · ~1 modified

Description

Add method(:name) → sp_Proc, fix sp_float_to_s format string

method(:name) wraps a named function in sp_Proc via adapter:

  • Scans AST for method() calls, emits adapter functions at file scope
  • Adapter: meth_adapt(void *env, mrb_int arg) → sp_(arg)
  • sp_Proc_new(meth_adapt, NULL) returned as expression

Fix: sp_float_to_s format string was consumed by vfprintf (%g → %%g)

Test: examples/bm_method.rb — method(:double).call(5) → 10.

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

Details

Commit
d5706015539c
Parent
4880c5964ded

examples/bm_method.rbaddedView file

1+def double(x)
2+ x * 2
3+end
4+
5+# Direct call for type inference
6+puts double(1) # 2
7+
8+m = method(:double)
9+puts m.call(5) # 10
10+puts m.call(10) # 20
11+
12+def add_ten(x)
13+ x + 10
14+end
15+
16+puts add_ten(0) # 10
17+
18+a = method(:add_ten)
19+puts a.call(3) # 13
20+
21+puts "done"