ELENA-LANG / elena-lang

ELENA is a general-purpose language with late binding. It is multi-paradigm, combining features of functional and object-oriented programming. Rich set of tools are provided to deal with message dispatching : multi-methods, message qualifying, generic message handlers, run-time interfaces
https://elena-lang.github.io/
MIT License
236 stars 26 forks source link

Default multi-method dispatcher #525

Open arakov opened 4 years ago

arakov commented 4 years ago

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