diff --git a/libkc3/buf_inspect.c b/libkc3/buf_inspect.c
index 409bc73..9df8365 100644
--- a/libkc3/buf_inspect.c
+++ b/libkc3/buf_inspect.c
@@ -358,6 +358,7 @@ sw buf_inspect_call (s_buf *buf, const s_call *call)
s8 op_precedence;
sw r;
sw result = 0;
+ const s_sym *sym;
if (call->ident.module == &g_sym_KC3 &&
call->ident.sym == &g_sym_access)
return buf_inspect_call_access(buf, call);
@@ -366,8 +367,12 @@ sw buf_inspect_call (s_buf *buf, const s_call *call)
return buf_inspect_call_if_then_else(buf, call);
if (! operator_find(&call->ident, &op))
return -1;
- if (op && operator_symbol(&call->ident) == &g_sym__brackets)
- return buf_inspect_call_brackets(buf, call);
+ if (op) {
+ if (! operator_symbol(&call->ident, &sym))
+ return -1;
+ if (sym == &g_sym__brackets)
+ return buf_inspect_call_brackets(buf, call);
+ }
if (call->ident.sym == &g_sym_cast)
return buf_inspect_cast(buf, call);
op_arity = op ? operator_arity(&call->ident) : 0;
@@ -653,10 +658,13 @@ sw buf_inspect_call_op_unary (s_buf *buf, const s_call *call)
{
sw r;
sw result = 0;
+ const s_sym *sym;
s_ident tmp;
assert(buf);
assert(call);
- if (operator_symbol(&call->ident) == &g_sym__paren)
+ if (! operator_symbol(&call->ident, &sym))
+ return -1;
+ if (sym == &g_sym__paren)
return buf_inspect_call_paren(buf, call);
if (operator_ident(&call->ident, &tmp) != &tmp)
return -1;
@@ -704,13 +712,18 @@ sw buf_inspect_call_size (const s_call *call)
s8 op_precedence;
sw r;
sw result = 0;
+ const s_sym *sym;
if (call->ident.module == &g_sym_KC3 &&
call->ident.sym == &g_sym_if_then_else)
return buf_inspect_call_if_then_else_size(call);
if (! operator_find(&call->ident, &op))
return -1;
- if (op && operator_symbol(&call->ident) == &g_sym__brackets)
- return buf_inspect_call_brackets_size(call);
+ if (op) {
+ if (! operator_symbol(&call->ident, &sym))
+ return -1;
+ if (sym == &g_sym__brackets)
+ return buf_inspect_call_brackets_size(call);
+ }
if (call->ident.sym == &g_sym_cast)
return buf_inspect_cast_size(call);
op_arity = op ? operator_arity(&call->ident) : 0;
diff --git a/libkc3/env.c b/libkc3/env.c
index 6f73c6e..3984a70 100644
--- a/libkc3/env.c
+++ b/libkc3/env.c
@@ -620,6 +620,7 @@ bool env_eval_call_fn_args (s_env *env, const s_fn *fn,
const s_list *args_final = NULL;
s_fn_clause *clause;
s_frame frame;
+ const s_sym *module;
s_list *search_modules;
s_tag tag;
s_list *tmp = NULL;
@@ -627,7 +628,12 @@ bool env_eval_call_fn_args (s_env *env, const s_fn *fn,
assert(fn);
assert(dest);
search_modules = env->search_modules;
- if (! env_module_search_modules(env, &fn->module, &env->search_modules))
+ module = fn->module;
+ if (! module)
+ module = env->current_defmodule;
+ if (! module)
+ module = &g_sym_KC3;
+ if (! env_module_search_modules(env, &module, &env->search_modules))
return false;
clause = fn->clauses;
if (arguments) {
@@ -2560,14 +2566,17 @@ bool * env_operator_find (s_env *env, const s_ident *op, bool *dest)
s_ident * env_operator_ident (s_env *env, const s_ident *op,
s_ident *dest)
{
+ s_ident tmp;
assert(env);
assert(op);
assert(dest);
if (env->current_defmodule == op->module)
- dest->module = NULL;
+ tmp.module = NULL;
else
- dest->module = op->module;
- dest->sym = env_operator_symbol(env, op);
+ tmp.module = op->module;
+ if (! env_operator_symbol(env, op, &tmp.sym))
+ return NULL;
+ *dest = tmp;
return dest;
}
@@ -2689,11 +2698,12 @@ s_ident * env_operator_resolve (s_env *env, const s_ident *op,
return dest;
}
-const s_sym * env_operator_symbol (s_env *env, const s_ident *op)
+const s_sym ** env_operator_symbol (s_env *env, const s_ident *op,
+ const s_sym **dest)
{
s_facts_cursor cursor;
const s_fact *fact;
- const s_sym *r;
+ const s_sym **result = NULL;
s_tag tag_op;
s_tag tag_sym_sym;
s_tag tag_var;
@@ -2708,17 +2718,18 @@ const s_sym * env_operator_symbol (s_env *env, const s_ident *op)
if (! facts_cursor_next(&cursor, &fact))
return NULL;
if (fact &&
- tag_var.type == TAG_SYM)
- r = tag_var.data.sym;
+ tag_var.type == TAG_SYM) {
+ *dest = tag_var.data.sym;
+ result = dest;
+ }
else {
err_write_1("env_operator_symbol: symbol for operator ");
err_write_1(op->sym->str.ptr.pchar);
err_write_1(" not found in module ");
err_puts(op->module->str.ptr.pchar);
- r = NULL;
}
facts_cursor_clean(&cursor);
- return r;
+ return result;
}
void env_pop_error_handler (s_env *env)
diff --git a/libkc3/env.h b/libkc3/env.h
index a78fd1b..0410921 100644
--- a/libkc3/env.h
+++ b/libkc3/env.h
@@ -197,7 +197,8 @@ bool * env_operator_is_right_associative (s_env *env,
s8 env_operator_precedence (s_env *env, const s_ident *op);
s_ident * env_operator_resolve (s_env *env, const s_ident *op,
u8 arity, s_ident *dest);
-const s_sym * env_operator_symbol (s_env *env, const s_ident *op);
+const s_sym ** env_operator_symbol (s_env *env, const s_ident *op,
+ const s_sym **dest);
u8 env_special_operator_arity (s_env *env,
const s_ident *ident);
bool * env_struct_type_exists (s_env *env, const s_sym *module,
diff --git a/libkc3/operator.c b/libkc3/operator.c
index 27f480d..e7e4ed4 100644
--- a/libkc3/operator.c
+++ b/libkc3/operator.c
@@ -44,7 +44,7 @@ s_ident * operator_resolve (const s_ident *op, u8 arity,
return env_operator_resolve(&g_kc3_env, op, arity, dest);
}
-const s_sym * operator_symbol (const s_ident *op)
+const s_sym ** operator_symbol (const s_ident *op, const s_sym **dest)
{
- return env_operator_symbol(&g_kc3_env, op);
+ return env_operator_symbol(&g_kc3_env, op, dest);
}
diff --git a/libkc3/operator.h b/libkc3/operator.h
index 0351dbb..ae8c583 100644
--- a/libkc3/operator.h
+++ b/libkc3/operator.h
@@ -24,6 +24,6 @@ bool * operator_is_right_associative (const s_ident *op,
s8 operator_precedence (const s_ident *op);
s_ident * operator_resolve (const s_ident *ident, u8 arity,
s_ident *dest);
-const s_sym * operator_symbol (const s_ident *op);
+const s_sym ** operator_symbol (const s_ident *op, const s_sym **dest);
#endif /* LIBKC3_OPERATOR_H */