1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-28 17:19:31 +00:00

Fix + operator overloading

This commit is contained in:
Étienne Fildadut 2021-04-04 20:29:22 +02:00
parent ec18d2e611
commit 9028970440
3 changed files with 14 additions and 12 deletions

View file

@ -194,7 +194,7 @@ $ f(a, b...)
~ f("discarded") ~ f("discarded")
``` ```
Functions with the same name can be defined, as long as they have a different number of argument. Functions with the same name can be defined, as long as they have a different number of argument. Functions will be selected based on the number of arguments given:
``` ```
$ f(a, b) $ f(a, b)

View file

@ -7,11 +7,11 @@ local anselme = {
} }
package.loaded[...] = anselme package.loaded[...] = anselme
-- TODO: for type checking functions: -- TODO: improve type checking.
-- pour éliminer totalement les undefined -- Right now, there is some basic type checking done at parsing - but since Lua and Anselme functions may not always define the type of
-- ne type checker/compiler les fonctions que lorsqu'elles sont apppelées, en déterminant leur type à ce moment là selon les arguments donnés -- their parameters and return value, a lot of checks are skipped ("undefined argument" type).
-- (du coup la surcharge ne se fera que selon l'arité. Mais ça sera 100% type checké) -- Probably won't be able to remove them completely (since lists can have mixed types, etc.), but would be good to limit them.
-- PB: les listes ont des types mixés (cf les varargs) + afficher des warnings dans le selecteur de variante lorsqu'un type de retour manque -- Ideally, we'd avoid runtime type checking.
-- load libs -- load libs
local preparse = require((...):gsub("anselme$", "parser.preparser")) local preparse = require((...):gsub("anselme$", "parser.preparser"))

View file

@ -133,12 +133,14 @@ functions = {
-- arithmetic -- arithmetic
["+"] = { ["+"] = {
{ {
arity = 2, types = { "number", "number" }, return_type = "number", arity = 2,
value = function(a, b) return a + b end value = function(a, b)
}, if type(a) == "string" then
{ return a .. b
arity = 2, types = { "string", "string" }, return_type = "string", else
value = function(a, b) return a .. b end return a + b
end
end
} }
}, },
["-"] = { ["-"] = {