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

Second test batch and associated fixes

This commit is contained in:
Étienne Fildadut 2023-12-29 17:15:43 +01:00
parent 7abb116876
commit 9b7d1e436e
56 changed files with 760 additions and 27 deletions

View file

@ -17,7 +17,9 @@ AttachBlock = ast.abstract.Node {
end,
_format = function(self, state, priority, indentation, ...)
return self.expression:format(state, priority, indentation, ...).."\n\t"..self.block:format(state, priority, indentation + 1, ...)
local exp = self.expression:format(state, priority, indentation, ...)
if exp:sub(-2) == " _" then exp = exp:sub(1, -3) end
return exp.."\n\t"..self.block:format(state, priority, indentation + 1, ...)
end,
traverse = function(self, fn, ...)

View file

@ -50,12 +50,9 @@ local Definition = ast.abstract.Node {
symbol:prepare(state)
val:prepare(state)
if self.symbol.alias then
state.scope:define(symbol:with{ alias = false }, val) -- disable alias to avoid call in Identifier:_prepare
elseif Overloadable:issub(val) then
state.scope:define_overloadable(symbol, val)
else
state.scope:define(symbol, val)
-- predefine exported variables
if symbol.exported then
self:eval(state)
end
end
}

View file

@ -28,7 +28,7 @@ local VariableMetadata = ast.abstract.Runtime {
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
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), 0) end
end
if self.symbol.alias then
local assign_args = ArgumentTuple:new()
@ -185,14 +185,12 @@ local Environment = ast.abstract.Runtime {
return self:_get_variable(state, identifier):set(state, val)
end,
-- returns a list {[symbol]=val,...} of all exported variables in the current strict layer
-- returns a list {[symbol]=val,...} of all exported variables (evaluated) in the current strict layer
list_exported = function(self, state)
assert(self.export, "not an export scope layer")
local r = {}
for _, vm in self.variables:iter(state) do
if vm.symbol.exported then
r[vm.symbol] = vm:get(state)
end
r[vm.symbol] = vm:get(state)
end
return r
end,

View file

@ -165,7 +165,7 @@ Node = class {
local r = {}
for _, tr in ipairs(l) do
table.insert(r, "(("..tr.source.."))")
table.insert(r, Call:new(Identifier:new("_#_"), ArgumentTuple:new(tr.context, Identifier:new("_"))))
table.insert(r, Call:new(Identifier:new("_#_"), ArgumentTuple:new(tr.context, Identifier:new("_"))):format())
table.insert(r, "\t"..Call:new(Identifier:new("_->_"), ArgumentTuple:new(tr, tr)):format())
table.insert(r, "")
end