elena-lang
elena-lang copied to clipboard
Resolving an interface in run-time
In the following code
import extensions;
interface IFoo
{
abstract bar() {}
}
A : interface<IFoo>
{
bar()
{
console.printLine("A implementation of IFoo")
}
}
public program()
{
IFoo o := new A();
o.bar()
}
A class implements an interface IFoo. Interface typecasting method is :
@method system@interface#1&mytest@$private@IFoo.#cast<'$private'IFoo>[1]
open 1h
pusha
new class : '$inline0 1
xsetfi 1 0
close
quitn 1h
@end
It creates a proxy class $inline0 containing interface implementation method:
@method $inline0.bar[1]
geti 0h
movm mssgconst : "bar[1]"
jumpvi 0
@end
where jumpvi command is used which uses binary search to resolve a message.
A special class should be generated which resolve interface methods in run-time and directly jump to them.