refactor: replace Foo.new constructor syntax with new Foo and simplify superclass constructor calls

Remove the `this new` constructor declaration syntax in favor of a `new` keyword that creates instances directly. Superclass constructors are now invoked via bare `super(args)` instead of `super.new(args)`, eliminating the semantic weirdness of calling a constructor on a partially-constructed instance. Update the compiler to treat `new` as a keyword token, replace the `isMethod` flag with `methodName`/`methodLength` fields, and change the VM's `NEW` opcode to pop the class from the stack before creating the instance. Add a default `new` native method on Object that returns `this`. Update all benchmarks and tests to use the new syntax.
This commit is contained in:
Bob Nystrom
2013-12-19 15:02:27 +00:00
parent f5a61e4241
commit 0e70d98169
30 changed files with 171 additions and 190 deletions
+1 -1
View File
@@ -2,4 +2,4 @@ class Foo {
write { io.write(_field) }
}
Foo.new.write // expect: null
(new Foo).write // expect: null
+1 -1
View File
@@ -15,7 +15,7 @@ class Foo {
}
}
var foo = Foo.new
var foo = new Foo
foo.set(1, 2, 3, 4, 5)
foo.write
// expect: 1
+4 -4
View File
@@ -19,15 +19,15 @@ class Node {
}
}
var a = Node.new
var a = new Node
a.set(null, "a", null)
var b = Node.new
var b = new Node
b.set(null, "b", null)
var c = Node.new
var c = new Node
c.set(a, "c", b)
a = null
b = null
var d = Node.new
var d = new Node
d.set(c, "d", null)
c = null
d.write
+1 -1
View File
@@ -3,7 +3,7 @@ class Foo {
init { _field = "value" } // ...before an assignment to it.
}
var foo = Foo.new
var foo = new Foo
// But invoke them in the right order.
foo.init
foo.write // expect: value