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

First test batch and associated fixes

The test runner is also nicer to use.
This commit is contained in:
Étienne Fildadut 2023-12-28 16:51:18 +01:00
parent 10084dec23
commit 82ce53be83
154 changed files with 1586 additions and 78 deletions

View file

@ -23,7 +23,9 @@ local VariableMetadata = ast.abstract.Runtime {
end
end,
set = function(self, state, value)
assert(not self.symbol.constant, ("trying to change the value of constant %s"):format(self.symbol.string))
if self.symbol.constant then
error(("trying to change the value of constant %s"):format(self.symbol.string), 0)
end
if self.symbol.type_check then
local r = self.symbol.type_check:call(state, ArgumentTuple:new(value))
if not r:truthy() then error(("type check failure for %s; %s does not satisfy %s"):format(self.symbol.string, value, self.symbol.type_check)) end
@ -82,7 +84,7 @@ local Environment = ast.abstract.Runtime {
define = function(self, state, symbol, exp)
local name = symbol.string
if self:defined_in_current(state, symbol) then
error(name.." is already defined in the current scope")
error(name.." is already defined in the current scope", 0)
end
if (self.partial and not self.partial[name])
or (self.export ~= symbol.exported) then
@ -107,7 +109,7 @@ local Environment = ast.abstract.Runtime {
elseif Overloadable:issub(val) then
exp = Overload:new(exp, val)
elseif self:defined_in_current(state, symbol) then
error(("can't add an overload variant to non-overloadable variable %s defined in the same scope"):format(identifier))
error(("can't add an overload variant to non-overloadable variable %s defined in the same scope"):format(identifier), 0)
end
end

View file

@ -49,13 +49,13 @@ List = ast.abstract.Runtime {
get = function(self, state, index)
local list = self.branched:get(state)
if index < 0 then index = #list.list + 1 + index end
if index > #list.list or index == 0 then error("list index out of bounds") end
if index > #list.list or index == 0 then error("list index out of bounds", 0) end
return list.list[index]
end,
set = function(self, state, index, val)
local list = self:_prepare_branch(state)
if index < 0 then index = #list.list + 1 + index end
if index > #list.list or index == 0 then error("list index out of bounds") end
if index > #list.list+1 or index == 0 then error("list index out of bounds", 0) end
list.list[index] = val
end,
insert = function(self, state, val)

View file

@ -23,7 +23,8 @@ local TupleToStruct = ast.abstract.Node {
_eval = function(self, state)
local t = Struct:new()
for i, e in ipairs(self.tuple.list) do
local tuple = self.tuple:eval(state)
for i, e in ipairs(tuple.list) do
if Pair:is(e) then
t:set(e.name, e.value)
else

View file

@ -58,7 +58,7 @@ Tuple = ast.abstract.Node {
get = function(self, index)
if index < 0 then index = #self.list + 1 + index end
if index > #self.list or index == 0 then error("tuple index out of bounds") end
if index > #self.list or index == 0 then error("tuple index out of bounds", 0) end
return self.list[index]
end
}