feat: add range operators and iterator protocol for numeric for loops
Implement `..` and `...` infix operators on Num returning Range objects that support the iterator protocol, enabling concise numeric for loops like `for (i in 1..10)`. Add Range class with min/max properties and iterate/iteratorValue methods. Introduce TOKEN_DOTDOT and TOKEN_DOTDOTDOT lexer tokens with PREC_RANGE precedence in the compiler. Unroll method_call benchmark loops across all languages to stress dynamic dispatch instead of loop overhead, reducing iteration count from 1M to 100K with 10x unrolling. Update Wren benchmarks (binary_trees, fib, for) to use new range syntax. Add benchmark/README.md documenting each benchmark's purpose.
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
var inclusive = 2..5
|
||||
IO.write(inclusive is Range) // expect: true
|
||||
IO.write(inclusive.min) // expect: 2
|
||||
IO.write(inclusive.max) // expect: 5
|
||||
|
||||
var exclusive = 2...5
|
||||
IO.write(exclusive is Range) // expect: true
|
||||
IO.write(exclusive.min) // expect: 2
|
||||
IO.write(exclusive.max) // expect: 4
|
||||
|
||||
// TODO: Non-number RHS.
|
||||
// TODO: Non-integer RHS.
|
||||
// TODO: Range iteration.
|
||||
// TODO: Empty or negative ranges.
|
||||
Reference in New Issue
Block a user