diff --git a/libc3/env.c b/libc3/env.c
index ea4c96c..b8041d7 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -260,9 +260,8 @@ bool env_eval_call (s_env *env, const s_call *call, s_tag *dest)
result = env_eval_call_fn(env, &c, dest);
else {
err_write_1("env_eval_call: could not resolve call ");
- err_write_1(c.ident.module->str.ptr.pchar);
- err_write_1(".");
- err_puts(c.ident.sym->str.ptr.pchar);
+ err_inspect_ident(&c.ident);
+ err_write_1("\n");
result = false;
}
call_clean(&c);
@@ -349,9 +348,18 @@ 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) ||
+ ! module_has_symbol(call->ident.module, &call->ident,
+ &env->facts) ||
! call_get(call, &env->facts)) {
ident_init_copy(&call->ident, &tmp_ident);
- return false;
+ call->ident.module = &g_sym_C3;
+ if (! module_ensure_loaded(call->ident.module, &env->facts) ||
+ ! module_has_symbol(call->ident.module, &call->ident,
+ &env->facts) ||
+ ! call_get(call, &env->facts)) {
+ ident_init_copy(&call->ident, &tmp_ident);
+ return false;
+ }
}
return true;
}
diff --git a/libc3/module.c b/libc3/module.c
index fc913c4..8075919 100644
--- a/libc3/module.c
+++ b/libc3/module.c
@@ -52,6 +52,23 @@ bool module_ensure_loaded (const s_sym *module, s_facts *facts)
return module_maybe_reload(module, facts);
}
+bool module_has_symbol (const s_sym *module, const s_ident *ident,
+ s_facts *facts)
+{
+ s_tag tag_ident;
+ s_tag tag_module_name;
+ s_tag tag_operator;
+ s_tag tag_symbol;
+ tag_init_ident(&tag_ident, ident);
+ tag_init_sym( &tag_module_name, module);
+ tag_init_sym( &tag_operator, &g_sym_operator);
+ tag_init_sym( &tag_symbol, &g_sym_symbol);
+ return facts_find_fact_by_tags(facts, &tag_module_name,
+ &tag_symbol, &tag_ident) ||
+ facts_find_fact_by_tags(facts, &tag_module_name,
+ &tag_operator, &tag_ident);
+}
+
bool module_is_loading (const s_sym *module)
{
return env_module_is_loading(&g_c3_env, module);
diff --git a/libc3/module.h b/libc3/module.h
index 676ce48..070ca70 100644
--- a/libc3/module.h
+++ b/libc3/module.h
@@ -28,6 +28,9 @@ bool module_load (const s_sym *module, s_facts *facts);
bool module_maybe_reload (const s_sym *module, s_facts *facts);
/* Observers */
+bool module_has_symbol (const s_sym *module,
+ const s_ident *ident,
+ s_facts *facts);
bool module_is_loading (const s_sym *module);
s_tag * module_load_time (const s_sym *module, s_facts *facts,
s_tag *dest);