52 lines
1.1 KiB
Lua
52 lines
1.1 KiB
Lua
|
|
--[[
|
|
env is a table with
|
|
__p the parent env if there is one
|
|
__t a table of strings with the same keys as the env
|
|
entries in __t can be "special" or "macro"
|
|
if there isnt an entry it's assumed to be normal
|
|
--]]
|
|
|
|
-- todo: guard against setting / getting __t and __p ?
|
|
|
|
function e_create(env, sym, val, type, cont)
|
|
if not is_sym(sym) then
|
|
return tostr(sym) .. " is not a symbol"
|
|
end
|
|
|
|
env[sym] = none
|
|
return e_set(env, sym, val, type, cont)
|
|
end
|
|
|
|
function e_set(env, sym, val, type, cont)
|
|
if not is_sym(sym) then
|
|
return tostr(sym) .. " is not a symbol"
|
|
end
|
|
|
|
if env[sym] != nil then
|
|
env[sym] = val
|
|
env.__t[sym] = type
|
|
return cont(val, type)
|
|
elseif env.__p != nil then
|
|
return e_set(env.__p, sym, val, type, cont)
|
|
else
|
|
return tostr(sym) .. " sym unbound cant set it"
|
|
end
|
|
end
|
|
|
|
function e_get(env, sym, cont)
|
|
if not is_sym(sym) then
|
|
return tostr(sym) .. " is not a symbol"
|
|
end
|
|
|
|
if env[sym] != nil then
|
|
return cont(env[sym], env.__t[sym])
|
|
elseif env.__p != nil then
|
|
return e_get(env.__p, sym, cont)
|
|
else
|
|
return tostr(sym) .. " sym unbound cant get it"
|
|
end
|
|
end
|
|
|
|
|