"IO" -> "System".

Get rid of the separate opt-in IO class and replace it with a core
System class.

- Remove wren_io.c, wren_io.h, and io.wren.
- Remove the flags that disable it.
- Remove the overloads for print() with different arity. (It was an
  experiment, but I don't think it's that useful.)
- Remove IO.read(). That will reappear using libuv in the CLI at some
  point.
- Remove IO.time. Doesn't seem to have been used.
- Update all of the tests, docs, etc.

I'm sorry for all the breakage this causes, but I think "System" is a
better name for this class (it makes it natural to add things like
"System.gc()") and frees up "IO" for referring to the CLI's IO module.
This commit is contained in:
Bob Nystrom
2015-09-15 07:46:09 -07:00
parent 66b89a493f
commit 58e4d26648
491 changed files with 3285 additions and 3544 deletions
+3 -3
View File
@@ -1,8 +1,8 @@
var a = [1]
a.add(2)
IO.print(a) // expect: [1, 2]
System.print(a) // expect: [1, 2]
a.add(3)
IO.print(a) // expect: [1, 2, 3]
System.print(a) // expect: [1, 2, 3]
// Returns added element.
IO.print(a.add(4)) // expect: 4
System.print(a.add(4)) // expect: 4
+4 -4
View File
@@ -1,11 +1,11 @@
var a = [1]
a.addAll([2, 3])
IO.print(a) // expect: [1, 2, 3]
System.print(a) // expect: [1, 2, 3]
a.addAll([])
IO.print(a) // expect: [1, 2, 3]
System.print(a) // expect: [1, 2, 3]
a.addAll(4..6)
IO.print(a) // expect: [1, 2, 3, 4, 5, 6]
System.print(a) // expect: [1, 2, 3, 4, 5, 6]
// Returns argument.
var range = 7..9
IO.print(a.addAll(range) == range) // expect: true
System.print(a.addAll(range) == range) // expect: true
+3 -3
View File
@@ -1,7 +1,7 @@
var a = [1, 2, 3]
a.clear()
IO.print(a) // expect: []
IO.print(a.count) // expect: 0
System.print(a) // expect: []
System.print(a.count) // expect: 0
// Returns null.
IO.print([1, 2].clear()) // expect: null
System.print([1, 2].clear()) // expect: null
+4 -4
View File
@@ -1,6 +1,6 @@
var list = [1, 2, 3, 4, "foo"]
IO.print(list.contains(2)) // expect: true
IO.print(list.contains(5)) // expect: false
IO.print(list.contains("foo")) // expect: true
IO.print(list.contains("bar")) // expect: false
System.print(list.contains(2)) // expect: true
System.print(list.contains(5)) // expect: false
System.print(list.contains("foo")) // expect: true
System.print(list.contains("bar")) // expect: false
+3 -3
View File
@@ -1,3 +1,3 @@
IO.print([].count) // expect: 0
IO.print([1].count) // expect: 1
IO.print([1, 2, 3, 4].count) // expect: 4
System.print([].count) // expect: 0
System.print([1].count) // expect: 1
System.print([1, 2, 3, 4].count) // expect: 4
+3 -3
View File
@@ -1,6 +1,6 @@
var a = [1, 2, 3]
IO.print(a.count {|x| x > 3 }) // expect: 0
IO.print(a.count {|x| x > 1 }) // expect: 2
System.print(a.count {|x| x > 3 }) // expect: 0
System.print(a.count {|x| x > 1 }) // expect: 2
IO.print([].count {|x| true }) // expect: 0
System.print([].count {|x| true }) // expect: 0
@@ -1,3 +1,3 @@
var a = [1, 2, 3]
IO.print(a.count {|x| "truthy" }) // expect: 3
System.print(a.count {|x| "truthy" }) // expect: 3
+1 -1
View File
@@ -1,3 +1,3 @@
var words = ""
["One", "Two", "Three"].each {|word| words = words + word }
IO.print(words) // expect: OneTwoThree
System.print(words) // expect: OneTwoThree
+1 -1
View File
@@ -1,3 +1,3 @@
var i = 0
[].each {|item| i = i + 1 }
IO.print(i) // expect: 0
System.print(i) // expect: 0
+10 -10
View File
@@ -1,41 +1,41 @@
// Add to empty list.
var a = []
a.insert(0, 1)
IO.print(a) // expect: [1]
System.print(a) // expect: [1]
// Normal indices.
var b = [1, 2, 3]
b.insert(0, 4)
IO.print(b) // expect: [4, 1, 2, 3]
System.print(b) // expect: [4, 1, 2, 3]
var c = [1, 2, 3]
c.insert(1, 4)
IO.print(c) // expect: [1, 4, 2, 3]
System.print(c) // expect: [1, 4, 2, 3]
var d = [1, 2, 3]
d.insert(2, 4)
IO.print(d) // expect: [1, 2, 4, 3]
System.print(d) // expect: [1, 2, 4, 3]
var e = [1, 2, 3]
e.insert(3, 4)
IO.print(e) // expect: [1, 2, 3, 4]
System.print(e) // expect: [1, 2, 3, 4]
// Negative indices.
var f = [1, 2, 3]
f.insert(-4, 4)
IO.print(f) // expect: [4, 1, 2, 3]
System.print(f) // expect: [4, 1, 2, 3]
var g = [1, 2, 3]
g.insert(-3, 4)
IO.print(g) // expect: [1, 4, 2, 3]
System.print(g) // expect: [1, 4, 2, 3]
var h = [1, 2, 3]
h.insert(-2, 4)
IO.print(h) // expect: [1, 2, 4, 3]
System.print(h) // expect: [1, 2, 4, 3]
var i = [1, 2, 3]
i.insert(-1, 4)
IO.print(i) // expect: [1, 2, 3, 4]
System.print(i) // expect: [1, 2, 3, 4]
// Returns.inserted value.
IO.print([1, 2].insert(0, 3)) // expect: 3
System.print([1, 2].insert(0, 3)) // expect: 3
+8 -8
View File
@@ -1,13 +1,13 @@
var a = ["one", "two", "three", "four"]
IO.print(a.iterate(null)) // expect: 0
IO.print(a.iterate(0)) // expect: 1
IO.print(a.iterate(1)) // expect: 2
IO.print(a.iterate(2)) // expect: 3
IO.print(a.iterate(3)) // expect: false
System.print(a.iterate(null)) // expect: 0
System.print(a.iterate(0)) // expect: 1
System.print(a.iterate(1)) // expect: 2
System.print(a.iterate(2)) // expect: 3
System.print(a.iterate(3)) // expect: false
// Out of bounds.
IO.print(a.iterate(123)) // expect: false
IO.print(a.iterate(-1)) // expect: false
System.print(a.iterate(123)) // expect: false
System.print(a.iterate(-1)) // expect: false
// Nothing to iterate in an empty list.
IO.print([].iterate(null)) // expect: false
System.print([].iterate(null)) // expect: false
+4 -4
View File
@@ -1,5 +1,5 @@
var a = ["one", "two", "three", "four"]
IO.print(a.iteratorValue(0)) // expect: one
IO.print(a.iteratorValue(1)) // expect: two
IO.print(a.iteratorValue(2)) // expect: three
IO.print(a.iteratorValue(3)) // expect: four
System.print(a.iteratorValue(0)) // expect: one
System.print(a.iteratorValue(1)) // expect: two
System.print(a.iteratorValue(2)) // expect: three
System.print(a.iteratorValue(3)) // expect: four
+6 -6
View File
@@ -1,17 +1,17 @@
// Handle empty list.
IO.print([].join(",") == "") // expect: true
System.print([].join(",") == "") // expect: true
// Handle a simple list with an empty delimeter.
IO.print([1, 2, 3].join("")) // expect: 123
System.print([1, 2, 3].join("")) // expect: 123
// Handle a simple list with no separator.
IO.print([1, 2, 3].join) // expect: 123
System.print([1, 2, 3].join) // expect: 123
// Does not quote strings.
IO.print([1, "2", true].join(",")) // expect: 1,2,true
System.print([1, "2", true].join(",")) // expect: 1,2,true
// Nested lists.
IO.print([1, [2, [3], 4], 5].join(",")) // expect: 1,[2, [3], 4],5
System.print([1, [2, [3], 4], 5].join(",")) // expect: 1,[2, [3], 4],5
// Calls toString on elements.
class Foo {
@@ -19,6 +19,6 @@ class Foo {
toString { "Foo.toString" }
}
IO.print([1, Foo.new(), 2].join(", ")) // expect: 1, Foo.toString, 2
System.print([1, Foo.new(), 2].join(", ")) // expect: 1, Foo.toString, 2
// TODO: Handle lists that contain themselves.
+1 -1
View File
@@ -1,3 +1,3 @@
var a = [1, 2, 3]
var b = a.map {|x| x + 1 }.toList
IO.print(b) // expect: [2, 3, 4]
System.print(b) // expect: [2, 3, 4]
+3 -3
View File
@@ -1,6 +1,6 @@
var list = List.new()
IO.print(list.count) // expect: 0
IO.print(list) // expect: []
System.print(list.count) // expect: 0
System.print(list) // expect: []
list.add(1)
IO.print(list) // expect: [1]
System.print(list) // expect: [1]
+2 -2
View File
@@ -1,2 +1,2 @@
IO.print(![1, 2]) // expect: false
IO.print(![]) // expect: false
System.print(![1, 2]) // expect: false
System.print(![]) // expect: false
+8 -8
View File
@@ -6,13 +6,13 @@ var e = a + []
var f = [] + a
var g = [] + []
IO.print(a) // expect: [1, 2, 3]
IO.print(b) // expect: [4, 5, 6]
IO.print(c) // expect: [1, 2, 3, 4, 5, 6]
IO.print(d) // expect: [1, 2, 3, 4, 5, 6]
IO.print(e) // expect: [1, 2, 3]
IO.print(f) // expect: [1, 2, 3]
IO.print(g) // expect: []
System.print(a) // expect: [1, 2, 3]
System.print(b) // expect: [4, 5, 6]
System.print(c) // expect: [1, 2, 3, 4, 5, 6]
System.print(d) // expect: [1, 2, 3, 4, 5, 6]
System.print(e) // expect: [1, 2, 3]
System.print(f) // expect: [1, 2, 3]
System.print(g) // expect: []
// Doesn't modify original list.
IO.print(a) // expect: [1, 2, 3]
System.print(a) // expect: [1, 2, 3]
+6 -6
View File
@@ -3,12 +3,12 @@ var b = ["W", "o", "r", "l", "d"]
var max = Fn.new {|a, b| a > b ? a : b }
var sum = Fn.new {|a, b| a + b }
IO.print(a.reduce(max)) // expect: 5
IO.print(a.reduce(10, max)) // expect: 10
System.print(a.reduce(max)) // expect: 5
System.print(a.reduce(10, max)) // expect: 10
IO.print(a.reduce(sum)) // expect: 13
IO.print(a.reduce(-1, sum)) // expect: 12
System.print(a.reduce(sum)) // expect: 13
System.print(a.reduce(-1, sum)) // expect: 12
// sum also concatenates strings
IO.print(b.reduce("Hello ", sum)) // expect: Hello World
IO.print(b.reduce(sum)) // expect: World
System.print(b.reduce("Hello ", sum)) // expect: Hello World
System.print(b.reduce(sum)) // expect: World
+2 -2
View File
@@ -1,2 +1,2 @@
IO.print([1].reduce {|a, b| 42 }) // expect: 1
IO.print([].reduce(1) {|a, b| 42 }) // expect: 1
System.print([1].reduce {|a, b| 42 }) // expect: 1
System.print([].reduce(1) {|a, b| 42 }) // expect: 1
+7 -7
View File
@@ -1,27 +1,27 @@
var a = [1, 2, 3]
a.removeAt(0)
IO.print(a) // expect: [2, 3]
System.print(a) // expect: [2, 3]
var b = [1, 2, 3]
b.removeAt(1)
IO.print(b) // expect: [1, 3]
System.print(b) // expect: [1, 3]
var c = [1, 2, 3]
c.removeAt(2)
IO.print(c) // expect: [1, 2]
System.print(c) // expect: [1, 2]
// Index backwards from end.
var d = [1, 2, 3]
d.removeAt(-3)
IO.print(d) // expect: [2, 3]
System.print(d) // expect: [2, 3]
var e = [1, 2, 3]
e.removeAt(-2)
IO.print(e) // expect: [1, 3]
System.print(e) // expect: [1, 3]
var f = [1, 2, 3]
f.removeAt(-1)
IO.print(f) // expect: [1, 2]
System.print(f) // expect: [1, 2]
// Return the removed value.
IO.print([3, 4, 5].removeAt(1)) // expect: 4
System.print([3, 4, 5].removeAt(1)) // expect: 4
+8 -8
View File
@@ -1,12 +1,12 @@
// Returns elements.
var list = ["a", "b", "c", "d"]
IO.print(list[0]) // expect: a
IO.print(list[1]) // expect: b
IO.print(list[2]) // expect: c
IO.print(list[3]) // expect: d
System.print(list[0]) // expect: a
System.print(list[1]) // expect: b
System.print(list[2]) // expect: c
System.print(list[3]) // expect: d
// Allows indexing backwards from the end.
IO.print(list[-4]) // expect: a
IO.print(list[-3]) // expect: b
IO.print(list[-2]) // expect: c
IO.print(list[-1]) // expect: d
System.print(list[-4]) // expect: a
System.print(list[-3]) // expect: b
System.print(list[-2]) // expect: c
System.print(list[-1]) // expect: d
+23 -23
View File
@@ -1,35 +1,35 @@
// Returns lists.
var list = ["a", "b", "c", "d", "e"]
IO.print(list[0..0]) // expect: [a]
IO.print(list[1...1]) // expect: []
IO.print(list[1..2]) // expect: [b, c]
IO.print(list[1...2]) // expect: [b]
IO.print(list[2..4]) // expect: [c, d, e]
IO.print(list[2...5]) // expect: [c, d, e]
System.print(list[0..0]) // expect: [a]
System.print(list[1...1]) // expect: []
System.print(list[1..2]) // expect: [b, c]
System.print(list[1...2]) // expect: [b]
System.print(list[2..4]) // expect: [c, d, e]
System.print(list[2...5]) // expect: [c, d, e]
// A backwards range reverses.
IO.print(list[3..1]) // expect: [d, c, b]
IO.print(list[3...1]) // expect: [d, c]
IO.print(list[3...3]) // expect: []
System.print(list[3..1]) // expect: [d, c, b]
System.print(list[3...1]) // expect: [d, c]
System.print(list[3...3]) // expect: []
// Negative ranges index from the end.
IO.print(list[-5..-2]) // expect: [a, b, c, d]
IO.print(list[-5...-2]) // expect: [a, b, c]
IO.print(list[-3..-5]) // expect: [c, b, a]
IO.print(list[-3...-6]) // expect: [c, b, a]
System.print(list[-5..-2]) // expect: [a, b, c, d]
System.print(list[-5...-2]) // expect: [a, b, c]
System.print(list[-3..-5]) // expect: [c, b, a]
System.print(list[-3...-6]) // expect: [c, b, a]
// Half-negative ranges are treated like the negative value is fixed before
// walking the range.
IO.print(list[-5..3]) // expect: [a, b, c, d]
IO.print(list[-3...5]) // expect: [c, d, e]
IO.print(list[-2..1]) // expect: [d, c, b]
IO.print(list[-2...0]) // expect: [d, c, b]
System.print(list[-5..3]) // expect: [a, b, c, d]
System.print(list[-3...5]) // expect: [c, d, e]
System.print(list[-2..1]) // expect: [d, c, b]
System.print(list[-2...0]) // expect: [d, c, b]
IO.print(list[1..-2]) // expect: [b, c, d]
IO.print(list[2...-1]) // expect: [c, d]
IO.print(list[4..-5]) // expect: [e, d, c, b, a]
IO.print(list[3...-6]) // expect: [d, c, b, a]
System.print(list[1..-2]) // expect: [b, c, d]
System.print(list[2...-1]) // expect: [c, d]
System.print(list[4..-5]) // expect: [e, d, c, b, a]
System.print(list[3...-6]) // expect: [d, c, b, a]
// An empty range at zero is allowed on an empty list.
IO.print([][0...0]) // expect: []
IO.print([][0..-1]) // expect: []
System.print([][0...0]) // expect: []
System.print([][0..-1]) // expect: []
+3 -3
View File
@@ -4,13 +4,13 @@
list[0] = 5
list[1] = 6
list[2] = 7
IO.print(list) // expect: [5, 6, 7]
System.print(list) // expect: [5, 6, 7]
}
// Returns right-hand side.
{
var list = [1, 2, 3]
IO.print(list[1] = 5) // expect: 5
System.print(list[1] = 5) // expect: 5
}
// Negative indices.
@@ -19,5 +19,5 @@
list[-1] = 5
list[-2] = 6
list[-3] = 7
IO.print(list) // expect: [7, 6, 5]
System.print(list) // expect: [7, 6, 5]
}
+4 -4
View File
@@ -1,11 +1,11 @@
// Handle empty list.
IO.print([].toString) // expect: []
System.print([].toString) // expect: []
// Does not quote strings.
IO.print([1, "2", true].toString) // expect: [1, 2, true]
System.print([1, "2", true].toString) // expect: [1, 2, true]
// Nested lists.
IO.print([1, [2, [3], 4], 5]) // expect: [1, [2, [3], 4], 5]
System.print([1, [2, [3], 4], 5]) // expect: [1, [2, [3], 4], 5]
// Calls toString on elements.
class Foo {
@@ -13,6 +13,6 @@ class Foo {
toString { "Foo.toString" }
}
IO.print([1, Foo.new(), 2]) // expect: [1, Foo.toString, 2]
System.print([1, Foo.new(), 2]) // expect: [1, Foo.toString, 2]
// TODO: Handle lists that contain themselves.
+5 -5
View File
@@ -1,5 +1,5 @@
IO.print([] is List) // expect: true
IO.print([] is Sequence) // expect: true
IO.print([] is Object) // expect: true
IO.print([] is Bool) // expect: false
IO.print([].type == List) // expect: true
System.print([] is List) // expect: true
System.print([] is Sequence) // expect: true
System.print([] is Object) // expect: true
System.print([] is Bool) // expect: false
System.print([].type == List) // expect: true
+2 -2
View File
@@ -1,6 +1,6 @@
var a = [1, 2, 3]
var b = a.where {|x| x > 1 }.toList
IO.print(b) // expect: [2, 3]
System.print(b) // expect: [2, 3]
var c = a.where {|x| x > 10 }.toList
IO.print(c) // expect: []
System.print(c) // expect: []