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

Move anselme code into its own directory

This commit is contained in:
Étienne Fildadut 2023-12-29 18:41:06 +01:00
parent 404e7dd56e
commit 5dd971ff8f
179 changed files with 603 additions and 579 deletions

View file

@ -0,0 +1,38 @@
local ast = require("anselme.ast")
local Nil, Boolean, Definition = ast.Nil, ast.Boolean, ast.Definition
return {
{
"defined", "(c::closure, s::string)",
function(state, c, s)
return Boolean:new(c.exported_scope:defined_in_current_strict(state, s:to_identifier()))
end
},
{
"_._", "(c::closure, s::string)",
function(state, c, s)
local identifier = s:to_identifier()
assert(c.exported_scope:defined_in_current_strict(state, identifier), ("no exported variable %q defined in closure"):format(s.string))
return c.exported_scope:get(state, identifier)
end
},
{
"_._", "(c::closure, s::string) = v",
function(state, c, s, v)
local identifier = s:to_identifier()
assert(c.exported_scope:defined_in_current_strict(state, identifier), ("no exported variable %q defined in closure"):format(s.string))
c.exported_scope:set(state, identifier, v)
return Nil:new()
end
},
{
"_._", "(c::closure, s::symbol) = v",
function(state, c, s, v)
assert(s.exported, "can't define a non-exported variable from the outside of the closure")
state.scope:push(c.exported_scope)
local r = Definition:new(s, v):eval(state)
state.scope:pop()
return r
end
}
}