diff --git a/src/library/kernel_bindings.cpp b/src/library/kernel_bindings.cpp index 4de39068f..d23f5a460 100644 --- a/src/library/kernel_bindings.cpp +++ b/src/library/kernel_bindings.cpp @@ -1104,7 +1104,7 @@ static int environment_prop_proof_irrel(lua_State * L) { return push_boolean(L, static int environment_cls_proof_irrel(lua_State * L) { return push_list_name(L, to_environment(L, 1).cls_proof_irrel()); } static int environment_eta(lua_State * L) { return push_boolean(L, to_environment(L, 1).eta()); } static int environment_impredicative(lua_State * L) { return push_boolean(L, to_environment(L, 1).impredicative()); } -static int environment_add_global_level(lua_State * L) { return push_environment(L, to_environment(L, 1).add_global_level(to_name_ext(L, 2))); } +static int environment_add_global_level(lua_State * L) { return push_environment(L, module::add_global_level(to_environment(L, 1), to_name_ext(L, 2))); } static int environment_is_global_level(lua_State * L) { return push_boolean(L, to_environment(L, 1).is_global_level(to_name_ext(L, 2))); } static int environment_find(lua_State * L) { return push_optional_declaration(L, to_environment(L, 1).find(to_name_ext(L, 2))); } static int environment_get(lua_State * L) { return push_declaration(L, to_environment(L, 1).get(to_name_ext(L, 2))); } diff --git a/src/library/module.cpp b/src/library/module.cpp index 8a182a6eb..f05d1a39d 100644 --- a/src/library/module.cpp +++ b/src/library/module.cpp @@ -99,7 +99,8 @@ void register_module_object_reader(std::string const & k, module_object_reader r readers[k] = r; } -static std::string g_decl("decl"); +static std::string g_glvl_key("glvl"); +static std::string g_decl_key("decl"); namespace module { environment add(environment const & env, std::string const & k, std::function const & wr) { @@ -108,15 +109,20 @@ environment add(environment const & env, std::string const & k, std::functionm_obj_code.data(), r->m_obj_code.size()); std::istringstream in(s, std::ios_base::binary); @@ -305,8 +316,10 @@ struct import_modules_fn { d >> k; if (k == g_olean_end_file) { break; - } else if (k == g_decl) { + } else if (k == g_decl_key) { import_decl(d, r->m_module_idx); + } else if (k == g_glvl_key) { + import_global_level(d); } else { object_readers & readers = get_object_readers(); auto it = readers.find(k); diff --git a/src/library/module.h b/src/library/module.h index df5b7cae2..d4d95a71b 100644 --- a/src/library/module.h +++ b/src/library/module.h @@ -75,6 +75,9 @@ namespace module { */ environment add(environment const & env, std::string const & k, std::function const & writer); +/** \brief Add the global level declaration to the environment, and mark it to be exported. */ +environment add_global_level(environment const & env, name const & l); + /** \brief Add the given declaration to the environment, and mark it to be exported. */ environment add(environment const & env, certified_declaration const & d); /** diff --git a/tests/lua/glvl1.lua b/tests/lua/glvl1.lua new file mode 100644 index 000000000..aa2a7d6a4 --- /dev/null +++ b/tests/lua/glvl1.lua @@ -0,0 +1,9 @@ +local env = environment() +env = env:add_global_level("u") +env = env:add_global_level("v") +assert(env:is_global_level("u")) + +env:export("glvl1_mod.olean") +local env2 = import_modules("glvl1_mod") +assert(env2:is_global_level("u")) +assert(env2:is_global_level("v"))