refactor: convert IO from singleton instance to static class with metaclass native methods

Replace the global `io` singleton object with a static `IO` class, moving the `write` native from the instance to the metaclass. Update all benchmark, example, and test files to use `IO.write()` instead of `io.write()`.
This commit is contained in:
Bob Nystrom
2013-12-22 03:25:09 +00:00
parent 1a77a43fa0
commit 8bb1a94a25
119 changed files with 532 additions and 536 deletions
+4 -4
View File
@@ -26,7 +26,7 @@ var stretchDepth = maxDepth + 1
var start = OS.clock
io.write("stretch tree of depth " + stretchDepth.toString + " check: " +
IO.write("stretch tree of depth " + stretchDepth.toString + " check: " +
new Tree(0, stretchDepth).check.toString)
var longLivedTree = new Tree(0, maxDepth)
@@ -48,13 +48,13 @@ while (depth < stretchDepth) {
i = i + 1
}
io.write((iterations * 2).toString + " trees of depth " + depth.toString +
IO.write((iterations * 2).toString + " trees of depth " + depth.toString +
" check: " + check.toString)
iterations = iterations / 4
depth = depth + 2
}
io.write("long lived tree of depth " + maxDepth.toString + " check: " +
IO.write("long lived tree of depth " + maxDepth.toString + " check: " +
longLivedTree.check.toString)
io.write("elapsed: " + (OS.clock - start).toString)
IO.write("elapsed: " + (OS.clock - start).toString)
+2 -2
View File
@@ -9,7 +9,7 @@ var fib = fn(n) {
var start = OS.clock
var i = 0
while (i < 5) {
io.write(fib.call(28))
IO.write(fib.call(28))
i = i + 1
}
io.write("elapsed: " + (OS.clock - start).toString)
IO.write("elapsed: " + (OS.clock - start).toString)
+3 -3
View File
@@ -39,7 +39,7 @@ while (i < n) {
i = i + 1
}
io.write(toggle.value)
IO.write(toggle.value)
val = true
var ntoggle = new NthToggle(val, 3)
@@ -50,6 +50,6 @@ while (i < n) {
i = i + 1
}
io.write(ntoggle.value)
IO.write(ntoggle.value)
io.write("elapsed: " + (OS.clock - start).toString)
IO.write("elapsed: " + (OS.clock - start).toString)