feat: add overloaded IO.print methods accepting 2-16 arguments and printList_ helper

Add 15 static overloads of IO.print in builtin/io.wren and src/wren_io.c, each delegating to a new private printList_ method that iterates over a list of objects. Update all benchmark and test files to use the new multi-argument syntax, removing explicit .toString calls and string concatenation. Add a comprehensive test/io/print.wren verifying single-argument return value, multi-argument null return, and concatenation of up to 16 arguments.
This commit is contained in:
Bob Nystrom
2014-04-09 14:48:35 +00:00
parent 786e20ba93
commit 3e5fdc2250
14 changed files with 176 additions and 25 deletions
+2 -2
View File
@@ -1,9 +1,9 @@
for (i in 0..2) {
IO.print("outer " + i.toString)
IO.print("outer ", i)
if (i > 1) break
for (j in 0..2) {
IO.print("inner " + j.toString)
IO.print("inner ", j)
if (j > 1) break
}
}
+2 -2
View File
@@ -1,11 +1,11 @@
var i = 0
while (true) {
IO.print("outer " + i.toString)
IO.print("outer ", i)
if (i > 1) break
var j = 0
while (true) {
IO.print("inner " + j.toString)
IO.print("inner ", j)
if (j > 1) break
j = j + 1
+2 -2
View File
@@ -1,10 +1,10 @@
class Foo {
static sayName {
IO.print(Foo.toString)
IO.print(Foo)
}
sayName {
IO.print(Foo.toString)
IO.print(Foo)
}
static toString { "Foo!" }
+2 -2
View File
@@ -1,6 +1,6 @@
class A {
new(arg) {
IO.print("new A " + arg)
IO.print("new A ", arg)
_field = arg
}
@@ -10,7 +10,7 @@ class A {
class B is A {
new(arg1, arg2) {
super(arg2)
IO.print("new B " + arg1)
IO.print("new B ", arg1)
_field = arg1
}
+3 -3
View File
@@ -1,7 +1,7 @@
var f0 = new Fn { IO.print("zero") }
var f1 = new Fn {|a| IO.print("one " + a) }
var f2 = new Fn {|a, b| IO.print("two " + a + " " + b) }
var f3 = new Fn {|a, b, c| IO.print("three " + a + " " + b + " " + c) }
var f1 = new Fn {|a| IO.print("one ", a) }
var f2 = new Fn {|a, b| IO.print("two ", a, " ", b) }
var f3 = new Fn {|a, b, c| IO.print("three ", a, " ", b, " ", c) }
f0.call("a") // expect: zero
f0.call("a", "b") // expect: zero
+1 -1
View File
@@ -1,2 +1,2 @@
var f2 = new Fn {|a, b| IO.print(a + b) }
var f2 = new Fn {|a, b| IO.print(a, b) }
f2.call("a") // expect runtime error: Function expects more arguments.
+25
View File
@@ -0,0 +1,25 @@
// With one argument, returns the argument.
IO.print(IO.print(1) == 1) // expect: 1
// expect: true
// With more than one argument, returns null.
IO.print(IO.print(1, 2) == null) // expect: 12
// expect: true
// Allows multiple arguments and concatenates them.
IO.print(1) // expect: 1
IO.print(1, 2) // expect: 12
IO.print(1, 2, 3) // expect: 123
IO.print(1, 2, 3, 4) // expect: 1234
IO.print(1, 2, 3, 4, 5) // expect: 12345
IO.print(1, 2, 3, 4, 5, 6) // expect: 123456
IO.print(1, 2, 3, 4, 5, 6, 7) // expect: 1234567
IO.print(1, 2, 3, 4, 5, 6, 7, 8) // expect: 12345678
IO.print(1, 2, 3, 4, 5, 6, 7, 8, 9) // expect: 123456789
IO.print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // expect: 12345678910
IO.print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) // expect: 1234567891011
IO.print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) // expect: 123456789101112
IO.print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) // expect: 12345678910111213
IO.print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) // expect: 1234567891011121314
IO.print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) // expect: 123456789101112131415
IO.print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) // expect: 12345678910111213141516