diff --git a/src/bindings/lua/environment.cpp b/src/bindings/lua/environment.cpp index baaea700a..5bc364415 100644 --- a/src/bindings/lua/environment.cpp +++ b/src/bindings/lua/environment.cpp @@ -50,6 +50,11 @@ static int mk_environment(lua_State * L) { return push_environment(L, f.get_environment()); } +static int environment_mk_child(lua_State * L) { + rw_environment env(L, 1); + return push_environment(L, env->mk_child()); +} + static int environment_has_parent(lua_State * L) { ro_environment env(L, 1); lua_pushboolean(L, env->has_parent()); @@ -214,6 +219,7 @@ static int environment_tostring(lua_State * L) { static const struct luaL_Reg environment_m[] = { {"__gc", environment_gc}, // never throws {"__tostring", safe_function}, + {"mk_child", safe_function}, {"has_parent", safe_function}, {"has_children", safe_function}, {"parent", safe_function}, diff --git a/tests/lua/env4.lua b/tests/lua/env4.lua new file mode 100644 index 000000000..d17f89d32 --- /dev/null +++ b/tests/lua/env4.lua @@ -0,0 +1,30 @@ +assert(not pcall(function() get_environment() end)) +local env = environment() +env:add_uvar("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() +assert(eenv:find_object("Int"):is_null()) +assert(not pcall(function() env:parent() end)) +local p = child:parent() +assert(p:has_children()) +assert(not pcall(function() env:add_uvar("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", Eq(iVal(0), iVal(0)), Const("Trivial")) +child:add_axiom("H1", Eq(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:check_type(Var(0), ctx) == Const("Int"))