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:
Bob Nystrom
2013-12-25 23:01:45 +00:00
parent b72a42eedd
commit 6c61df3ed7
12 changed files with 209 additions and 44 deletions
+1 -3
View File
@@ -7,9 +7,7 @@ var fib = fn(n) {
}
var start = OS.clock
var i = 0
while (i < 5) {
for (i in 1..5) {
IO.write(fib.call(28))
i = i + 1
}
IO.write("elapsed: " + (OS.clock - start).toString)