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:
@@ -4,5 +4,5 @@ class Foo {
|
||||
|
||||
// Classes inherit the argument-less "new" one by default.
|
||||
var foo = new Foo
|
||||
io.write(foo is Foo) // expect: true
|
||||
io.write(foo.toString) // expect: Foo
|
||||
IO.write(foo is Foo) // expect: true
|
||||
IO.write(foo.toString) // expect: Foo
|
||||
|
||||
@@ -2,6 +2,6 @@ class Foo {
|
||||
+ other { return "Foo " + other }
|
||||
}
|
||||
|
||||
io.write(new Foo + "value") // expect: Foo value
|
||||
IO.write(new Foo + "value") // expect: Foo value
|
||||
|
||||
// TODO: Other expressions following a constructor, like new Foo.bar("arg").
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Foo {
|
||||
new { io.write("zero") }
|
||||
new(a) { io.write(a) }
|
||||
new(a, b) { io.write(a + b) }
|
||||
new { IO.write("zero") }
|
||||
new(a) { IO.write(a) }
|
||||
new(a, b) { IO.write(a + b) }
|
||||
|
||||
toString { return "Foo" }
|
||||
}
|
||||
@@ -13,5 +13,5 @@ new Foo("one", "two") // expect: onetwo
|
||||
|
||||
// Returns the new instance.
|
||||
var foo = new Foo // expect: zero
|
||||
io.write(foo is Foo) // expect: true
|
||||
io.write(foo.toString) // expect: Foo
|
||||
IO.write(foo is Foo) // expect: true
|
||||
IO.write(foo.toString) // expect: Foo
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class A {
|
||||
new(arg) {
|
||||
io.write("new A " + arg)
|
||||
IO.write("new A " + arg)
|
||||
_field = arg
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class A {
|
||||
class B is A {
|
||||
new(arg1, arg2) {
|
||||
super(arg2)
|
||||
io.write("new B " + arg1)
|
||||
IO.write("new B " + arg1)
|
||||
_field = arg1
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class B is A {
|
||||
class C is B {
|
||||
new {
|
||||
super("one", "two")
|
||||
io.write("new C")
|
||||
IO.write("new C")
|
||||
_field = "c"
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ var c = new C
|
||||
// expect: new A two
|
||||
// expect: new B one
|
||||
// expect: new C
|
||||
io.write(c is A) // expect: true
|
||||
io.write(c is B) // expect: true
|
||||
io.write(c is C) // expect: true
|
||||
IO.write(c is A) // expect: true
|
||||
IO.write(c is B) // expect: true
|
||||
IO.write(c is C) // expect: true
|
||||
|
||||
io.write(c.aField) // expect: two
|
||||
io.write(c.bField) // expect: one
|
||||
io.write(c.cField) // expect: c
|
||||
IO.write(c.aField) // expect: two
|
||||
IO.write(c.bField) // expect: one
|
||||
IO.write(c.cField) // expect: c
|
||||
|
||||
Reference in New Issue
Block a user