lean2/tests/lua/env4.lua
Leonardo de Moura 35bacf95fc feat(shell): provide the default environment when parsing Lua files
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2014-01-12 18:21:14 -08:00

33 lines
1.3 KiB
Lua

local env = environment()
env:import("Int")
env:add_uvar_cnstr("M", level(level(), 1))
env:add_uvar_cnstr("Z", level(level("M"), 1))
assert(env:is_ge(level("Z"), level("M")))
local child = env:mk_child()
assert(env:has_children())
assert(child:has_parent())
child:add_var("x", Const("Int"))
for o in child:local_objects() do
assert(o:get_name() == name("x"))
print(o)
end
local eenv = empty_environment()
print(not eenv:find_object("Int"))
assert(not pcall(function() env:parent() end))
local p = child:parent()
assert(p:has_children())
assert(not pcall(function() env:add_uvar_cnstr("Z") end))
child:add_uvar_cnstr("Z")
assert(not pcall(function() child:add_uvar_cnstr("M", level("Z")) end))
child:add_definition("val1", Const("true"), true)
child:add_definition("val2", Const("Bool"), Const("true"), true)
local ok, msg = pcall(function() child:add_definition("val3", Const("Int"), Const("true"), true) end)
assert(not ok)
print(msg)
assert(child:normalize(Const("val2")) == Const("val2"))
child:add_theorem("Th1", HEq(iVal(0), iVal(0)), Const("trivial"))
child:add_axiom("H1", HEq(Const("x"), iVal(0)))
assert(child:has_object("H1"))
local ctx = context(context(), "x", Const("Int"), iVal(10))
assert(child:normalize(Var(0), ctx) == iVal(10))
assert(child:type_check(Var(0), ctx) == Const("Int"))