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:
@@ -6,8 +6,7 @@ class Foo {
|
||||
static bar(arg) { return "on metaclass " + arg }
|
||||
}
|
||||
|
||||
io.write("on metaclass " + "arg") // expect: on metaclass arg
|
||||
io.write(Foo.new.bar) // expect: on instance
|
||||
io.write(Foo.bar) // expect: on metaclass
|
||||
io.write(Foo.new.bar("arg")) // expect: on instance arg
|
||||
io.write(Foo.bar("arg")) // expect: on metaclass arg
|
||||
io.write((new Foo).bar) // expect: on instance
|
||||
io.write(Foo.bar) // expect: on metaclass
|
||||
io.write((new Foo).bar("arg")) // expect: on instance arg
|
||||
io.write(Foo.bar("arg")) // expect: on metaclass arg
|
||||
|
||||
Reference in New Issue
Block a user