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 # 1
3+puts r.last # 10
4+puts r.include?(5) # true
5+puts r.include?(11) # false
6+
7+arr = r.to_a
8+puts arr.length # 10
9+puts arr.sum # 55
10+
11+total = 0
12+r.each do |i|
13+ total += i
14+end
15+puts total # 55
16+puts "done"