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:
@@ -22,7 +22,7 @@ class Bar is Foo {
|
||||
}
|
||||
}
|
||||
|
||||
var bar = Bar.new
|
||||
var bar = new Bar
|
||||
bar.foo("foo 1", "foo 2")
|
||||
bar.bar("bar 1", "bar 2")
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ class Bar is Foo {
|
||||
override { io.write("bar") }
|
||||
}
|
||||
|
||||
var bar = Bar.new
|
||||
var bar = new Bar
|
||||
bar.methodOnFoo // expect: foo
|
||||
bar.methodOnBar // expect: bar
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
class A {}
|
||||
class B is A {}
|
||||
class C is B {}
|
||||
var a = A.new
|
||||
var b = B.new
|
||||
var c = C.new
|
||||
var a = new A
|
||||
var b = new B
|
||||
var c = new C
|
||||
|
||||
io.write(a is A) // expect: true
|
||||
io.write(a is B) // expect: false
|
||||
|
||||
Reference in New Issue
Block a user