Add CODE_SUPER_0 through CODE_SUPER_16 bytecodes to the VM for invoking inherited methods, along with a `namedCall` compiler helper that parses method names and argument lists after a dot. The interpreter dispatches super calls by walking up the class hierarchy from the receiver's immediate class, skipping methods defined on that class. Includes three test cases covering calling a different superclass method, calling the same method name, and indirectly inherited methods. Also fixes error formatting to handle newline tokens gracefully and adds a TODO note about not deduplicating placeholder constants for super calls.
19 lines
174 B
Plaintext
19 lines
174 B
Plaintext
class A {
|
|
foo {
|
|
io.write("A.foo")
|
|
}
|
|
}
|
|
|
|
class B is A {}
|
|
|
|
class C is B {
|
|
foo {
|
|
io.write("C.foo")
|
|
super.foo
|
|
}
|
|
}
|
|
|
|
C.new.foo
|
|
// expect: C.foo
|
|
// expect: A.foo
|