mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
Overload cleanup
This commit is contained in:
parent
9a38dfa34f
commit
41f85181a3
4 changed files with 12 additions and 12 deletions
|
|
@ -76,10 +76,10 @@ Function = Overloadable {
|
||||||
compatible_with_arguments = function(self, state, args)
|
compatible_with_arguments = function(self, state, args)
|
||||||
return args:match_parameter_tuple(state, self.parameters)
|
return args:match_parameter_tuple(state, self.parameters)
|
||||||
end,
|
end,
|
||||||
format_parameters = function(self, state)
|
format_signature = function(self, state)
|
||||||
return self.parameters:format(state)
|
return self.parameters:format(state)
|
||||||
end,
|
end,
|
||||||
hash_parameters = function(self)
|
hash_signature = function(self)
|
||||||
return self.parameters:hash()
|
return self.parameters:hash()
|
||||||
end,
|
end,
|
||||||
call_dispatched = function(self, state, args)
|
call_dispatched = function(self, state, args)
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,10 @@ LuaFunction = ast.abstract.Runtime(Overloadable) {
|
||||||
compatible_with_arguments = function(self, state, args)
|
compatible_with_arguments = function(self, state, args)
|
||||||
return args:match_parameter_tuple(state, self.parameters)
|
return args:match_parameter_tuple(state, self.parameters)
|
||||||
end,
|
end,
|
||||||
format_parameters = function(self, state)
|
format_signature = function(self, state)
|
||||||
return self.parameters:format(state)
|
return self.parameters:format(state)
|
||||||
end,
|
end,
|
||||||
hash_parameters = function(self)
|
hash_signature = function(self)
|
||||||
return self.parameters:hash()
|
return self.parameters:hash()
|
||||||
end,
|
end,
|
||||||
call_dispatched = function(self, state, args)
|
call_dispatched = function(self, state, args)
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ Overload = ast.abstract.Node {
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
insert = function(self, val) -- only for construction
|
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)
|
table.insert(self.list, val)
|
||||||
self._signatures[val:hash_parameters()] = true
|
self._signatures[val:hash_signature()] = true
|
||||||
end,
|
end,
|
||||||
|
|
||||||
_format = function(self, ...)
|
_format = function(self, ...)
|
||||||
|
|
@ -50,12 +50,12 @@ Overload = ast.abstract.Node {
|
||||||
if secondary_specificity > success_secondary_specificity then
|
if secondary_specificity > success_secondary_specificity then
|
||||||
success, success_specificity, success_secondary_specificity = fn, specificity, secondary_specificity
|
success, success_specificity, success_secondary_specificity = fn, specificity, secondary_specificity
|
||||||
elseif secondary_specificity == success_secondary_specificity then
|
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
|
||||||
end
|
end
|
||||||
-- no need to add error message for less specific function since we already should have at least one success
|
-- no need to add error message for less specific function since we already should have at least one success
|
||||||
elseif not success then
|
elseif not success then
|
||||||
table.insert(failure, fn:format_parameters(state) .. ": " .. secondary_specificity)
|
table.insert(failure, fn:format_signature(state) .. ": " .. secondary_specificity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if success then
|
if success then
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,12 @@ return ast.abstract.Node {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- return string
|
-- return string
|
||||||
format_parameters = function(self, state)
|
format_signature = function(self, state)
|
||||||
return self:format(state)
|
error("not implemented for "..self.type)
|
||||||
end,
|
end,
|
||||||
-- return string
|
-- return string
|
||||||
hash_parameters = function(self)
|
hash_signature = function(self)
|
||||||
return self:hash()
|
error("not implemented for "..self.type)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- can be called either after a successful :dispatch or :compatible_with_arguments
|
-- can be called either after a successful :dispatch or :compatible_with_arguments
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue