Commit 21800ec9
21800ec90340Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 3 files · +1 added · ~2 modified
Description
feat: Range as object with first, last, each, include?, to_a
Add sp_Range struct (first/last pair) as a first-class type:
- New SPINEL_TYPE_RANGE in the type system
- sp_Range runtime: sp_Range_new, sp_Range_include_p, sp_Range_to_a
- Range method dispatch: first, last, include?, to_a, sum, length/size
- Range#each with block inlined as C for loop
- PM_RANGE_NODE handling in codegen_expr and infer_type
- Fix binary operator check in infer_type to only match actual operator method names, preventing false matches on include?, new, etc.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 21800ec90340
- Parent
- f10bb189f5e8
examples/bm_range.rbaddedView file
1+
r = (1..10)2+
puts r.first # 13+
puts r.last # 104+
puts r.include?(5) # true5+
puts r.include?(11) # false6+
7+
arr = r.to_a8+
puts arr.length # 109+
puts arr.sum # 5510+
11+
total = 012+
r.each do |i|13+
total += i14+
end15+
puts total # 5516+
puts "done"src/codegen.cmodifiedView file
Loading diff…
src/codegen.hmodifiedView file
Loading diff…