diff --git a/libc3/env.c b/libc3/env.c
index acefafc..b5b0087 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -639,14 +639,14 @@ bool env_eval_call_resolve (s_env *env, s_call *call)
}
ident_init_copy(&tmp_ident, &call->ident);
if (! env_ident_resolve_module(env, &tmp_ident, &call->ident) ||
- ! module_ensure_loaded(call->ident.module, &env->facts) ||
+ ! env_module_ensure_loaded(env, call->ident.module) ||
! module_has_ident(call->ident.module, &call->ident,
&env->facts, &b) ||
! b ||
! env_call_get(env, call)) {
ident_init_copy(&call->ident, &tmp_ident);
call->ident.module = &g_sym_C3;
- if (! module_ensure_loaded(call->ident.module, &env->facts) ||
+ if (! env_module_ensure_loaded(env, call->ident.module) ||
! module_has_ident(call->ident.module, &call->ident,
&env->facts, &b) ||
! b ||
@@ -1762,7 +1762,7 @@ s_tag * env_ident_get (s_env *env, const s_ident *ident, s_tag *dest)
return NULL;
}
}
- if (! module_ensure_loaded(module, &env->facts))
+ if (! env_module_ensure_loaded(env, module))
return NULL;
tag_init_ident(&tag_ident, ident);
tag_init_sym( &tag_is_a, &g_sym_is_a);
@@ -1998,6 +1998,36 @@ const s_sym ** env_module (s_env *env, const s_sym **dest)
return dest;
}
+bool env_module_ensure_loaded (s_env *env, const s_sym *module)
+{
+ bool b;
+ const s_fact *fact;
+ s_tag tag_module_name;
+ s_tag tag_is_a;
+ s_tag tag_module;
+ if (! module_is_loading(module, &b))
+ return false;
+ if (b)
+ return true;
+ tag_init_sym(&tag_is_a, &g_sym_is_a);
+ tag_init_sym(&tag_module, &g_sym_module);
+ tag_init_sym(&tag_module_name, module);
+ if (! facts_find_fact_by_tags(&env->facts, &tag_module_name,
+ &tag_is_a, &tag_module, &fact))
+ return false;
+ if (! fact) {
+ if (! module_load(module)) {
+ err_write_1("env_module_ensure_loaded: module not found: ");
+ err_puts(module->str.ptr.pchar);
+ assert(! "env_module_ensure_loaded: module not found");
+ return false;
+ }
+ return true;
+ }
+ module_maybe_reload(module, &env->facts);
+ return true;
+}
+
bool * env_module_is_loading (s_env *env, const s_sym *module,
bool *dest)
{
diff --git a/libc3/env.h b/libc3/env.h
index fd34b61..7119e02 100644
--- a/libc3/env.h
+++ b/libc3/env.h
@@ -208,6 +208,7 @@ bool env_tag_ident_is_bound (s_env *env,
/* Modifiers. */
bool env_call_get (s_env *env, s_call *call);
+bool env_module_ensure_loaded (s_env *env, const s_sym *module);
/* Control structures. */
void env_error_f (s_env *env, const char *fmt, ...);
diff --git a/libc3/module.c b/libc3/module.c
index 28e56ec..10e1ff1 100644
--- a/libc3/module.c
+++ b/libc3/module.c
@@ -24,34 +24,9 @@
#include "tag.h"
#include "sym.h"
-bool module_ensure_loaded (const s_sym *module, s_facts *facts)
+bool module_ensure_loaded (const s_sym *module)
{
- bool b;
- const s_fact *fact;
- s_tag tag_module_name;
- s_tag tag_is_a;
- s_tag tag_module;
- if (! module_is_loading(module, &b))
- return false;
- if (b)
- return true;
- tag_init_sym(&tag_is_a, &g_sym_is_a);
- tag_init_sym(&tag_module, &g_sym_module);
- tag_init_sym(&tag_module_name, module);
- if (! facts_find_fact_by_tags(facts, &tag_module_name, &tag_is_a,
- &tag_module, &fact))
- return false;
- if (! fact) {
- if (! module_load(module)) {
- err_write_1("module_ensure_loaded: module not found: ");
- err_puts(module->str.ptr.pchar);
- assert(! "module_ensure_loaded: module not found");
- return false;
- }
- return true;
- }
- module_maybe_reload(module, facts);
- return true;
+ return env_module_ensure_loaded(&g_c3_env, module);
}
bool * module_has_ident (const s_sym *module, const s_ident *ident,
diff --git a/libc3/module.h b/libc3/module.h
index 487cd39..ed28eb6 100644
--- a/libc3/module.h
+++ b/libc3/module.h
@@ -23,7 +23,7 @@
#include "types.h"
/* Modifiers */
-bool module_ensure_loaded (const s_sym *module, s_facts *facts);
+bool module_ensure_loaded (const s_sym *module);
bool module_load (const s_sym *module);
bool module_maybe_reload (const s_sym *module, s_facts *facts);