Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tail-calls of inline functions #123

Open
Bananattack opened this issue Mar 9, 2021 · 0 comments
Open

Fix tail-calls of inline functions #123

Bananattack opened this issue Mar 9, 2021 · 0 comments

Comments

@Bananattack
Copy link
Collaborator

Bananattack commented Mar 9, 2021

Currently it is not possible to tail call an inline function. It will compile but generate incorrect code.

inline func beep() {
    (0xC0 as func)();
}

func call_beep() {
    return beep();
}

In this case, tail-call optimization doesn't apply as there is no stack entry to bypass. However, it should still behave the same as the original call (which is inlined), terminated by a return statement, when no tail-call ois possible.

This should at the very least, generate the following rather than invalid code:

call 0xC0
ret

or generate an error, failing that.

Potentially if tail-calls get optimized at the IR level (which is after inline functions are expanded), then this could generate the more optimal

jp 0xC0

branch instruction instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant