PistonDevelopers / dyon

A rusty dynamically typed scripting language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Move binary and unary operators to external functions

bvssvni opened this issue · comments

Instead of treating binary and unary operators as special, they can be turned into external functions. This will simplify the runtime quite a bit.

One problem is that when overriding external functions, the type checker makes wrong assumptions.

The runtime type is not guaranteed, so it might be acceptable to just let the type checker make wrong assumptions and get errors at runtime when something is wrong.

Another solution is to make a type error if one declares a function with same name and incompatible type as the one assumed by the type checker.

Another solution is to add smarter type inference such that the type checker can handle all the cases where the output type depends on the type of the input.

One problem is that && and || are lazy, which means they do not always evaluate the right argument.

A solution to the lazy problem is to add support for making external functions lazy, e.g. by specifying a default value to return, if the argument is evaluated to that value. This requires lazy functions to return same type as the argument which has a default value.