1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00

Overload cleanup

This commit is contained in:
Étienne Fildadut 2024-01-03 22:12:46 +01:00
parent 9a38dfa34f
commit 41f85181a3
4 changed files with 12 additions and 12 deletions

View file

@ -76,10 +76,10 @@ Function = Overloadable {
compatible_with_arguments = function(self, state, args)
return args:match_parameter_tuple(state, self.parameters)
end,
format_parameters = function(self, state)
format_signature = function(self, state)
return self.parameters:format(state)
end,
hash_parameters = function(self)
hash_signature = function(self)
return self.parameters:hash()
end,
call_dispatched = function(self, state, args)

View file

@ -40,10 +40,10 @@ LuaFunction = ast.abstract.Runtime(Overloadable) {
compatible_with_arguments = function(self, state, args)
return args:match_parameter_tuple(state, self.parameters)
end,
format_parameters = function(self, state)
format_signature = function(self, state)
return self.parameters:format(state)
end,
hash_parameters = function(self)
hash_signature = function(self)
return self.parameters:hash()
end,
call_dispatched = function(self, state, args)

View file

@ -17,9 +17,9 @@ Overload = ast.abstract.Node {
end
end,
insert = function(self, val) -- only for construction
assert0(not self._signatures[val:hash_parameters()], ("a function with parameters %s is already defined in the overload"):format(val:format_parameters()))
assert0(not self._signatures[val:hash_signature()], ("a function with parameters %s is already defined in the overload"):format(val:format_signature()))
table.insert(self.list, val)
self._signatures[val:hash_parameters()] = true
self._signatures[val:hash_signature()] = true
end,
_format = function(self, ...)
@ -50,12 +50,12 @@ Overload = ast.abstract.Node {
if secondary_specificity > success_secondary_specificity then
success, success_specificity, success_secondary_specificity = fn, specificity, secondary_specificity
elseif secondary_specificity == success_secondary_specificity then
return nil, ("more than one function match %s, matching functions were at least (specificity %s.%s):\n\t• %s\n\t• %s"):format(args:format(state), specificity, secondary_specificity, fn:format_parameters(state), success:format_parameters(state))
return nil, ("more than one function match %s, matching functions were at least (specificity %s.%s):\n\t• %s\n\t• %s"):format(args:format(state), specificity, secondary_specificity, fn:format_signature(state), success:format_signature(state))
end
end
-- no need to add error message for less specific function since we already should have at least one success
elseif not success then
table.insert(failure, fn:format_parameters(state) .. ": " .. secondary_specificity)
table.insert(failure, fn:format_signature(state) .. ": " .. secondary_specificity)
end
end
if success then

View file

@ -13,12 +13,12 @@ return ast.abstract.Node {
end,
-- return string
format_parameters = function(self, state)
return self:format(state)
format_signature = function(self, state)
error("not implemented for "..self.type)
end,
-- return string
hash_parameters = function(self)
return self:hash()
hash_signature = function(self)
error("not implemented for "..self.type)
end,
-- can be called either after a successful :dispatch or :compatible_with_arguments