Closed arakov closed 3 years ago
Use case:
import extensions;
A;
B
{
foo(A a)
{
console.printLine("bar")
}
}
C
{
A cast() = new A();
}
public program()
{
auto c := new C();
auto b := new B();
b.foo(c);
}
The program code is:
@method program.#invoke
open 1h
pusha
pushr 0
pushr 0
movr class : '$private'C
pusha
movm mssgconst : "#constructor[1]"
callrm '$private'C#class mssgconst : "#constructor[1]"
storefi 2
movr class : '$private'B
pusha
movm mssgconst : "#constructor[1]"
callrm '$private'B#class mssgconst : "#constructor[1]"
storefi 3
pushfi 2
pushfi 3
peeksi 0
movm mssgconst : "foo[2]"
callvi 0
peekfi 1
close
quit
@end
A resolved message should be used (instead of multi-one) with explicit typecasting
// ...
pushfi 2
peeksi 0
movm mssgconst : "#cast<'$private'A>[1]"
callvi 0
pusha
pushfi 3
peeksi 0
movm mssgconst : "foo<'$private'A>[2]"
callvi 0
// ...
The optimization can be applied only if the class is closed or sealed, or method is sealed
done
Typecast the argument list to the expected ones and call it directly if there is only a single strong-typed method. The default multi-method call is not needed if all arguments and the target are known in run-time