elena-lang
elena-lang copied to clipboard
Default multi-method dispatcher
If there is only one argument -> do not create frame, just replace the old argument with new one after typecasting.
A;
B
{
A cast() = new A();
}
singleton C
{
foo(A a)
{
console.writeLine("bar")
}
}
public program()
{
var b := new B();
var a := new A();
C.foo(a);
C.foo(b);
}
The generated code can be simplified:
@method $private'C.foo[2]
xmtredirect'foo$inline0 mssgconst : "foo[2]"
open 1h
pusha
pushfi -3
peeksi 0
movm mssgconst : "#cast<'$private'A>[1]"
callvi 0
pusha
pushfi 1
peeksi 0
movm mssgconst : "foo<'$private'A>[2]"
callrm '$private'C mssgconst : "foo<'$private'A>[2]"
close
quitn 2h
@end