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

Operator overloading #85

Open
liquidev opened this issue Jun 10, 2022 · 0 comments
Open

Operator overloading #85

liquidev opened this issue Jun 10, 2022 · 0 comments

Comments

@liquidev
Copy link
Member

Once traits are implemented, it would make sense to make all the built-in operators dispatch to trait methods instead of magic bytecode. This does mean that for a few releases basic operations will take a performance hit, until we have an IR that would allow us to optimize bytecode better and do some rudimentary static type analysis to dispatch specialized bytecode instructions.

Here's a list of operators and their associated traits with methods, once that is finished:

Op Trait Method
infix () Call call/n where n is the number of arguments in ()
prefix ! Not not/0
prefix - Negate negate/0
infix * Multiply multiply/1
infix / Divide divide/1
infix + Add add/1
infix - Subtract subtract/1
infix == Equals equals/1
infix != Equals boolean NOT equals/1
infix < Ordered less/1
infix <= Ordered less_or_equal/1
infix > Ordered less/1 on the RHS
infix >= Ordered less_or_equal/1 on the RHS

. cannot be overloaded because it's magic for method lookups + calls.
= cannot be overloaded because it's magic for assignments.
and and or cannot be overloaded because they're magic for control flow.

@liquidev liquidev moved this to 📦 Backlog in Mica 1.0 Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 📦 Backlog
Development

No branches or pull requests

1 participant