diff --git a/ic3/configure b/ic3/configure
index e9b8101..79658ad 100755
--- a/ic3/configure
+++ b/ic3/configure
@@ -72,7 +72,7 @@ LOCAL_LIBS_COV="$LIBC3_COV"
LIBS_COV="$LOCAL_LIBS_COV $LIBS"
# Debug config
-CFLAGS_DEBUG="$CFLAGS -DDEBUG -O0 -ggdb"
+CFLAGS_DEBUG="$CFLAGS -DDEBUG -O0 -g"
LDFLAGS_DEBUG="$LDFLAGS"
LIBC3_DEBUG=../libc3/libc3_debug.la
LOCAL_LIBS_DEBUG="$LIBC3_DEBUG"
diff --git a/ic3/ic3.c b/ic3/ic3.c
index 54abfce..2636b58 100644
--- a/ic3/ic3.c
+++ b/ic3/ic3.c
@@ -100,6 +100,7 @@ int main (int argc, char **argv)
buf_init(&out, false, sizeof(o), o);
buf_file_open_w(&out, stdout);
while ((r = ic3_buf_ignore_spaces(&out, &in)) >= 0) {
+ (void) 0;
if ((r = buf_parse_tag(&in, &input)) > 0) {
if (! eval_tag(&input, &result)) {
tag_clean(&input);
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 8d0a869..09b49d6 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -249,7 +249,7 @@ sw buf_inspect_call (s_buf *buf, const s_call *call)
return buf_inspect_call_brackets(buf, call);
if (call->ident.sym == sym_1("cast"))
return buf_inspect_cast(buf, call);
- if (operator_is_unary(&call->ident))
+ if (operator_find(&call->ident, 1))
return buf_inspect_call_op_unary(buf, call);
if ((op_precedence = operator_precedence(&call->ident)) > 0)
return buf_inspect_call_op(buf, call, op_precedence);
@@ -451,7 +451,7 @@ sw buf_inspect_call_size (const s_call *call)
s8 op_precedence;
sw r;
sw result = 0;
- if (operator_is_unary(&call->ident))
+ if (operator_find(&call->ident, 1))
return buf_inspect_call_op_unary_size(call);
if ((op_precedence = operator_precedence(&call->ident)) > 0)
return buf_inspect_call_op_size(call, op_precedence);
@@ -474,7 +474,7 @@ sw buf_inspect_cast (s_buf *buf, const s_call *call)
assert(call);
assert(call->arguments);
assert(! list_next(call->arguments));
- module = call->ident.module_name;
+ module = call->ident.module;
if ((r = buf_inspect_paren_sym(buf, module)) < 0)
return r;
result += r;
@@ -497,7 +497,7 @@ sw buf_inspect_cast_size (const s_call *call)
assert(call);
assert(call->arguments);
assert(! list_next(call->arguments));
- module = call->ident.module_name;
+ module = call->ident.module;
if ((r = buf_inspect_paren_sym_size(module)) <= 0)
return r;
result += r;
@@ -988,8 +988,8 @@ sw buf_inspect_ident (s_buf *buf, const s_ident *ident)
assert(buf);
assert(ident);
result = 0;
- if (ident->module_name) {
- if ((r = buf_inspect_sym(buf, ident->module_name)) < 0)
+ if (ident->module) {
+ if ((r = buf_inspect_sym(buf, ident->module)) < 0)
return r;
result += r;
if ((r = buf_write_1(buf, ".")) < 0)
@@ -1043,8 +1043,8 @@ sw buf_inspect_ident_size (const s_ident *ident)
sw r;
sw result = 0;
assert(ident);
- if (ident->module_name) {
- if ((r = buf_inspect_sym_size(ident->module_name)) < 0)
+ if (ident->module) {
+ if ((r = buf_inspect_sym_size(ident->module)) < 0)
return r;
result += r;
result += strlen(".");
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index c75753a..91571d7 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -578,6 +578,7 @@ sw buf_parse_call_args_paren (s_buf *buf, s_call *dest)
sw buf_parse_call_op (s_buf *buf, s_call *dest)
{
+ s_ident next_op;
s_call tmp;
sw r;
sw result = 0;
@@ -592,6 +593,13 @@ sw buf_parse_call_op (s_buf *buf, s_call *dest)
if ((r = buf_ignore_spaces_but_newline(buf)) < 0)
goto restore;
result += r;
+ if ((r = buf_parse_ident_peek(buf, &next_op)) <= 0)
+ goto restore;
+ if (! operator_find(&next_op, 2) ||
+ operator_precedence(&next_op) < 0) {
+ r = 0;
+ goto restore;
+ }
if ((r = buf_parse_call_op_rec(buf, &tmp, 0)) <= 0)
goto restore;
result += r;
@@ -633,18 +641,17 @@ sw buf_parse_call_op_rec (s_buf *buf, s_call *dest, u8 min_precedence)
tag_copy(&dest->arguments->tag, left);
if ((r = buf_parse_ident_peek(buf, &next_op)) <= 0)
goto restore;
- if ((op_precedence = operator_precedence(&next_op)) < 0) {
+ if (! operator_find(&next_op, 2) ||
+ (op_precedence = operator_precedence(&next_op)) < 0) {
r = 0;
goto restore;
}
- if (! operator_is_binary(&next_op))
- goto restore;
while (r > 0 && op_precedence >= min_precedence) {
if ((r = buf_parse_ident(buf, &next_op)) <= 0)
goto restore;
result += r;
op = next_op;
- tmp.ident = op;
+ operator_call_ident(&op, 2, &tmp.ident);
if ((r = buf_ignore_spaces(buf)) < 0)
goto restore;
result += r;
@@ -662,7 +669,7 @@ sw buf_parse_call_op_rec (s_buf *buf, s_call *dest, u8 min_precedence)
if (r <= 0)
break;
next_op_precedence = operator_precedence(&next_op);
- while (r > 0 && operator_is_binary(&next_op) &&
+ while (r > 0 && operator_find(&next_op, 2) &&
(next_op_precedence >= op_precedence ||
(operator_is_right_associative(&next_op) &&
next_op_precedence == op_precedence))) {
@@ -691,7 +698,7 @@ sw buf_parse_call_op_rec (s_buf *buf, s_call *dest, u8 min_precedence)
if (r <= 0 || (op_precedence = next_op_precedence) < min_precedence)
break;
call_init_op(&tmp3);
- tmp3.ident = op;
+ operator_call_ident(&op, 2, &tmp3.ident);
tmp3.arguments->tag = *left;
list_next(tmp3.arguments)->tag = *right;
tag_init_call(left, &tmp3);
@@ -721,7 +728,7 @@ sw buf_parse_call_op_unary (s_buf *buf, s_call *dest)
if ((r = buf_parse_ident(buf, &tmp.ident)) <= 0)
goto restore;
result += r;
- if (! operator_is_unary(&tmp.ident))
+ if (! operator_find(&tmp.ident, 1))
goto restore;
if ((r = buf_ignore_spaces(buf)) < 0)
goto restore;
@@ -730,6 +737,7 @@ sw buf_parse_call_op_unary (s_buf *buf, s_call *dest)
goto restore;
result += r;
*dest = tmp;
+ operator_call_ident(&tmp.ident, 1, &dest->ident);
r = result;
goto clean;
restore:
@@ -1340,7 +1348,7 @@ sw buf_parse_ident (s_buf *buf, s_ident *dest)
{
character c;
sw csize;
- const s_sym *module_name = NULL;
+ const s_sym *module = NULL;
sw r;
sw result = 0;
s_buf_save save;
@@ -1350,7 +1358,7 @@ sw buf_parse_ident (s_buf *buf, s_ident *dest)
assert(buf);
assert(dest);
buf_save_init(buf, &save);
- if ((r = buf_parse_module_name(buf, &module_name)) < 0)
+ if ((r = buf_parse_module_name(buf, &module)) < 0)
goto clean;
if (r > 0) {
result += r;
@@ -1368,7 +1376,7 @@ sw buf_parse_ident (s_buf *buf, s_ident *dest)
goto restore;
result += r;
str_to_ident(&str, dest);
- dest->module_name = module_name;
+ dest->module = module;
str_clean(&str);
r = result;
goto clean;
@@ -1390,7 +1398,7 @@ sw buf_parse_ident (s_buf *buf, s_ident *dest)
}
buf_read_to_str(&tmp, &str);
str_to_ident(&str, dest);
- dest->module_name = module_name;
+ dest->module = module;
str_clean(&str);
r = result;
goto clean;
diff --git a/libc3/call.c b/libc3/call.c
index 9ee76c4..b43046f 100644
--- a/libc3/call.c
+++ b/libc3/call.c
@@ -63,7 +63,7 @@ bool call_get (s_call *call, s_facts *facts)
tag_init_ident(&tag_ident, &call->ident);
tag_init_1( &tag_is_a, ":is_a");
tag_init_1( &tag_macro, ":macro");
- tag_init_sym( &tag_module_name, call->ident.module_name);
+ tag_init_sym( &tag_module_name, call->ident.module);
tag_init_1( &tag_special_operator, ":special_operator");
tag_init_sym( &tag_sym, call->ident.sym);
tag_init_1( &tag_symbol, ":symbol");
@@ -75,7 +75,7 @@ bool call_get (s_call *call, s_facts *facts)
if (! facts_with_cursor_next(&cursor)) {
warnx("symbol %s not found in module %s",
call->ident.sym->str.ptr.ps8,
- call->ident.module_name->str.ptr.ps8);
+ call->ident.module->str.ptr.ps8);
facts_with_cursor_clean(&cursor);
return false;
}
@@ -86,7 +86,7 @@ bool call_get (s_call *call, s_facts *facts)
if (facts_with_cursor_next(&cursor)) {
if (tag_var.type != TAG_FN)
errx(1, "%s.%s is not a function",
- call->ident.module_name->str.ptr.ps8,
+ call->ident.module->str.ptr.ps8,
call->ident.sym->str.ptr.ps8);
call->fn = fn_new_copy(&tag_var.data.fn);
}
@@ -97,7 +97,85 @@ bool call_get (s_call *call, s_facts *facts)
if (facts_with_cursor_next(&cursor)) {
if (tag_var.type != TAG_CFN)
errx(1, "%s.%s is not a C function",
- call->ident.module_name->str.ptr.ps8,
+ call->ident.module->str.ptr.ps8,
+ call->ident.sym->str.ptr.ps8);
+ call->cfn = cfn_new_copy(&tag_var.data.cfn);
+ }
+ facts_with_cursor_clean(&cursor);
+ facts_with(facts, &cursor, (t_facts_spec) {
+ &tag_ident, &tag_is_a, &tag_macro, NULL, NULL });
+ if (facts_with_cursor_next(&cursor)) {
+ if (call->fn)
+ call->fn->macro = true;
+ if (call->cfn)
+ call->cfn->macro = true;
+ }
+ facts_with_cursor_clean(&cursor);
+ facts_with(facts, &cursor, (t_facts_spec) {
+ &tag_ident, &tag_is_a, &tag_special_operator, NULL, NULL});
+ if (facts_with_cursor_next(&cursor)) {
+ if (call->fn)
+ call->fn->special_operator = true;
+ if (call->cfn)
+ call->cfn->special_operator = true;
+ }
+ facts_with_cursor_clean(&cursor);
+ return true;
+}
+
+bool call_op_get (s_call *call, s_facts *facts)
+{
+ s_facts_with_cursor cursor;
+ s_tag tag_cfn;
+ s_tag tag_fn;
+ s_tag tag_ident;
+ s_tag tag_is_a;
+ s_tag tag_macro;
+ s_tag tag_module_name;
+ s_tag tag_special_operator;
+ s_tag tag_sym;
+ s_tag tag_symbol;
+ s_tag tag_var;
+ tag_init_1( &tag_cfn, ":cfn");
+ tag_init_1( &tag_fn, ":fn");
+ tag_init_ident(&tag_ident, &call->ident);
+ tag_init_1( &tag_is_a, ":is_a");
+ tag_init_1( &tag_macro, ":macro");
+ tag_init_sym( &tag_module_name, call->ident.module);
+ tag_init_1( &tag_special_operator, ":special_operator");
+ tag_init_sym( &tag_sym, call->ident.sym);
+ tag_init_1( &tag_symbol, ":symbol");
+ tag_init_var( &tag_var);
+ facts_with(facts, &cursor, (t_facts_spec) {
+ &tag_module_name,
+ &tag_symbol, &tag_ident, /* module exports symbol */
+ NULL, NULL });
+ if (! facts_with_cursor_next(&cursor)) {
+ warnx("symbol %s not found in module %s",
+ call->ident.sym->str.ptr.ps8,
+ call->ident.module->str.ptr.ps8);
+ facts_with_cursor_clean(&cursor);
+ return false;
+ }
+ facts_with_cursor_clean(&cursor);
+ facts_with(facts, &cursor, (t_facts_spec) {
+ &tag_ident, &tag_fn, &tag_var,
+ NULL, NULL });
+ if (facts_with_cursor_next(&cursor)) {
+ if (tag_var.type != TAG_FN)
+ errx(1, "%s.%s is not a function",
+ call->ident.module->str.ptr.ps8,
+ call->ident.sym->str.ptr.ps8);
+ call->fn = fn_new_copy(&tag_var.data.fn);
+ }
+ facts_with_cursor_clean(&cursor);
+ facts_with(facts, &cursor, (t_facts_spec) {
+ &tag_ident, &tag_cfn, &tag_var,
+ NULL, NULL });
+ if (facts_with_cursor_next(&cursor)) {
+ if (tag_var.type != TAG_CFN)
+ errx(1, "%s.%s is not a C function",
+ call->ident.module->str.ptr.ps8,
call->ident.sym->str.ptr.ps8);
call->cfn = cfn_new_copy(&tag_var.data.cfn);
}
diff --git a/libc3/compare.c b/libc3/compare.c
index c438433..b3ee036 100644
--- a/libc3/compare.c
+++ b/libc3/compare.c
@@ -230,7 +230,7 @@ s8 compare_ident (const s_ident *a, const s_ident *b)
return -1;
if (!b)
return 1;
- if ((r = compare_sym(a->module_name, b->module_name)))
+ if ((r = compare_sym(a->module, b->module)))
return r;
return compare_sym(a->sym, b->sym);
}
diff --git a/libc3/configure b/libc3/configure
index 0500fe4..f393b56 100755
--- a/libc3/configure
+++ b/libc3/configure
@@ -68,7 +68,7 @@ LDFLAGS_COV="$LDFLAGS --coverage"
LIBS_COV="$LIBS"
# Debug config
-CFLAGS_DEBUG="$CFLAGS -DDEBUG -O0 -ggdb"
+CFLAGS_DEBUG="$CFLAGS -DDEBUG -O0 -g"
LDFLAGS_DEBUG="$LDFLAGS"
LIBS_DEBUG="$LIBS"
diff --git a/libc3/env.c b/libc3/env.c
index 4681835..331d412 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -186,7 +186,7 @@ bool env_eval_call (s_env *env, const s_call *call, s_tag *dest)
result = env_eval_call_fn(env, &c, dest);
else {
warnx("env_eval_call: could not resolve call %s.%s.",
- c.ident.module_name->str.ptr.ps8,
+ c.ident.module->str.ptr.ps8,
c.ident.sym->str.ptr.ps8);
result = false;
}
@@ -320,7 +320,7 @@ bool env_eval_call_resolve (s_env *env, s_call *call)
}
}
ident_resolve_module(&call->ident, env);
- if (! module_ensure_loaded(call->ident.module_name, &env->facts))
+ if (! module_ensure_loaded(call->ident.module, &env->facts))
return false;
return call_get(call, &env->facts);
}
@@ -514,7 +514,7 @@ bool env_eval_ident (s_env *env, const s_ident *ident, s_tag *dest)
if (! ((tag = frame_get(env->frame, tmp_ident.sym)) ||
(tag = ident_get(&tmp_ident, &env->facts, &tmp)))) {
warnx("unbound ident: %s.%s",
- tmp_ident.module_name->str.ptr.ps8,
+ tmp_ident.module->str.ptr.ps8,
tmp_ident.sym->str.ptr.ps8);
return false;
}
@@ -698,19 +698,18 @@ void env_longjmp (s_env *env, jmp_buf *jmp_buf)
longjmp(*jmp_buf, 1);
}
-bool env_module_load (s_env *env, const s_sym *name,
- s_facts *facts)
+bool env_module_load (const s_sym *module, s_env *env, s_facts *facts)
{
s_str path;
- s_tag tag_name;
+ s_tag tag_module_name;
s_tag tag_load_time;
s_tag tag_time;
assert(env);
- assert(name);
+ assert(module);
assert(facts);
- if (! module_name_path(&env->module_path, name, &path)) {
- warnx("env_module_load: %s: module_name_path",
- name->str.ptr.ps8);
+ if (! module_path(module, &env->module_path, &path)) {
+ warnx("env_module_load: %s: module_path",
+ module->str.ptr.ps8);
return false;
}
if (facts_load_file(facts, &path) < 0) {
@@ -720,24 +719,24 @@ bool env_module_load (s_env *env, const s_sym *name,
return false;
}
str_clean(&path);
- tag_init_sym(&tag_name, name);
+ tag_init_sym(&tag_module_name, module);
tag_init_sym(&tag_load_time, sym_1("load_time"));
tag_init_time(&tag_time);
- facts_replace_tags(facts, &tag_name, &tag_load_time, &tag_time);
+ facts_replace_tags(facts, &tag_module_name, &tag_load_time, &tag_time);
tag_clean(&tag_time);
return true;
}
-bool env_module_maybe_reload (s_env *env, const s_sym *name,
+bool env_module_maybe_reload (const s_sym *module, s_env *env,
s_facts *facts)
{
s_str path;
bool r = true;
s_tag tag_load_time;
s_tag tag_mtime;
- if (! module_load_time(name, facts, &tag_load_time))
+ if (! module_load_time(module, facts, &tag_load_time))
return false;
- if (! module_name_path(&env->module_path, name, &path)) {
+ if (! module_path(module, &env->module_path, &path)) {
return false;
}
if (! file_mtime(&path, &tag_mtime)) {
@@ -745,48 +744,89 @@ bool env_module_maybe_reload (s_env *env, const s_sym *name,
return false;
}
if (compare_tag(&tag_load_time, &tag_mtime) < 0)
- r = module_load(name, facts);
+ r = module_load(module, facts);
str_clean(&path);
tag_clean(&tag_mtime);
return r;
}
-s8 env_operator_arity (s_env *env, const s_ident *op)
+s_ident * env_operator_call_ident (s_env *env, const s_ident *op,
+ s_ident *dest, u8 arity)
{
s_facts_with_cursor cursor;
- s8 r = -1;
- s_tag tag_operator_var;
+ s_tag tag_arity;
+ s_tag tag_arity_u8;
+ s_tag tag_ident;
+ s_tag tag_module_name;
+ s_tag tag_operator;
+ s_tag tag_sym;
+ s_tag tag_symbol;
+ dest->module = op->module;
+ tag_init_1( &tag_arity, ":arity");
+ tag_init_u8( &tag_arity_u8, arity);
+ tag_init_var(&tag_ident);
+ tag_init_sym(&tag_module_name, op->module);
+ tag_init_sym(&tag_sym, op->sym);
+ tag_init_1( &tag_symbol, ":symbol");
+ facts_with(&env->facts, &cursor, (t_facts_spec) {
+ &tag_module_name,
+ &tag_operator, &tag_ident, NULL, /* module exports operator */
+ &tag_ident, &tag_symbol, &tag_sym,
+ &tag_arity, &tag_arity_u8,
+ NULL, NULL });
+ if (facts_with_cursor_next(&cursor)) {
+ if (tag_ident.type == TAG_IDENT) {
+ *dest = tag_ident.data.ident;
+ facts_with_cursor_clean(&cursor);
+ return dest;
+ }
+ }
+ warnx("operator %s not found in module %s",
+ op->sym->str.ptr.ps8,
+ op->module->str.ptr.ps8);
+ facts_with_cursor_clean(&cursor);
+ return NULL;
+}
+
+bool env_operator_find (s_env *env, const s_ident *op, u8 arity)
+{
+ s_facts_with_cursor cursor;
+ s_tag tag_arity;
+ s_tag tag_arity_u8;
s_tag tag_is_a;
+ s_tag tag_module;
+ s_tag tag_module_name;
s_tag tag_operator;
+ s_tag tag_operator_var;
s_tag tag_symbol;
s_tag tag_sym;
- s_tag tag_arity;
- s_tag tag_arity_var;
s_ident tmp;
assert(env);
assert(op);
tmp = *op;
ident_resolve_module(&tmp, env);
- tag_init_var(&tag_operator_var);
+ tag_init_1( &tag_arity, ":arity");
+ tag_init_u8( &tag_arity_u8, arity);
tag_init_1( &tag_is_a, ":is_a");
+ tag_init_1( &tag_module, ":module");
+ tag_init_sym(&tag_module_name, tmp.module);
tag_init_1( &tag_operator, ":operator");
+ tag_init_var(&tag_operator_var);
tag_init_1( &tag_symbol, ":symbol");
tag_init_sym(&tag_sym, tmp.sym);
- tag_init_1( &tag_arity, ":arity");
- tag_init_var(&tag_arity_var);
facts_with(&env->facts, &cursor, (t_facts_spec) {
+ &tag_module_name, &tag_is_a, &tag_module,
+ &tag_operator, &tag_operator_var, NULL,
&tag_operator_var, &tag_is_a, &tag_operator,
&tag_symbol, &tag_sym,
- &tag_arity, &tag_arity_var,
+ &tag_arity, &tag_arity_u8,
NULL, NULL });
if (facts_with_cursor_next(&cursor)) {
- if (tag_operator_var.type == TAG_IDENT &&
- tag_operator_var.data.ident.module == tmp.module &&
- tag_arity_var.type == TAG_U8)
- r = tag_arity.data.u8;
+ facts_with_cursor_clean(&cursor);
+ return true;
}
facts_with_cursor_clean(&cursor);
- return r;
+ return false;
}
bool env_operator_is_right_associative (s_env *env, const s_ident *op)
@@ -812,64 +852,46 @@ bool env_operator_is_right_associative (s_env *env, const s_ident *op)
return r;
}
-bool env_operator_is_unary (s_env *env, const s_ident *op)
+s8 env_operator_precedence (s_env *env, const s_ident *op)
{
s_facts_with_cursor cursor;
- s8 r;
- s_tag tag_ident;
+ s8 r = -1;
s_tag tag_is_a;
- s_tag tag_arity;
- s_tag tag_one;
+ s_tag tag_module;
+ s_tag tag_module_name;
s_tag tag_operator;
- s_ident tmp;
- assert(env);
- assert(op);
- tmp = *op;
- ident_resolve_module(&tmp, env);
- tag_init_ident(&tag_ident, &tmp);
- tag_init_1( &tag_is_a, ":is_a");
- tag_init_1( &tag_operator, ":operator");
- tag_init_1( &tag_arity, ":arity");
- tag_init_1( &tag_one, "1");
- facts_with(&env->facts, &cursor, (t_facts_spec) {
- &tag_ident, &tag_is_a, &tag_operator,
- &tag_arity, &tag_one,
- NULL, NULL });
- r = facts_with_cursor_next(&cursor) ? true : false;
- facts_with_cursor_clean(&cursor);
- return r;
-}
-
-s8 env_operator_precedence (s_env *env, const s_ident *op)
-{
- s_facts_with_cursor cursor;
- s_tag tag_ident;
s_tag tag_operator_precedence;
- s_tag tag_var;
+ s_tag tag_operator_precedence_var;
+ s_tag tag_operator_var;
+ s_tag tag_symbol;
+ s_tag tag_sym;
s_ident tmp;
assert(env);
assert(op);
tmp = *op;
ident_resolve_module(&tmp, env);
- tag_init_ident(&tag_ident, &tmp);
- tag_init_1( &tag_operator_precedence, ":operator_precedence");
- tag_init_var( &tag_var);
+ tag_init_1( &tag_is_a, ":is_a");
+ tag_init_1( &tag_module, ":module");
+ tag_init_sym(&tag_module_name, tmp.module);
+ tag_init_1( &tag_operator, ":operator");
+ tag_init_1( &tag_operator_precedence, ":operator_precedence");
+ tag_init_var(&tag_operator_precedence_var);
+ tag_init_var(&tag_operator_var);
+ tag_init_1( &tag_symbol, ":symbol");
+ tag_init_sym(&tag_sym, tmp.sym);
facts_with(&env->facts, &cursor, (t_facts_spec) {
- &tag_ident, &tag_operator_precedence, &tag_var,
+ &tag_module_name, &tag_is_a, &tag_module,
+ &tag_operator, &tag_operator_var, NULL,
+ &tag_operator_var, &tag_is_a, &tag_operator,
+ &tag_symbol, &tag_sym,
+ &tag_operator_precedence, &tag_operator_precedence_var,
NULL, NULL });
- if (! facts_with_cursor_next(&cursor))
- goto ko;
- if (tag_var.type != TAG_U8) {
- warnx("%s.%s: invalid operator_precedence type",
- tmp.module_name->str.ptr.ps8,
- tmp.sym->str.ptr.ps8);
- goto ko;
+ if (facts_with_cursor_next(&cursor) &&
+ tag_operator_precedence_var.type == TAG_U8) {
+ r = tag_operator_precedence_var.data.u8;
}
facts_with_cursor_clean(&cursor);
- return tag_var.data.u8;
- ko:
- facts_with_cursor_clean(&cursor);
- return -1;
+ return r;
}
void env_pop_error_handler (s_env *env)
diff --git a/libc3/env.h b/libc3/env.h
index bf80d67..1ce730c 100644
--- a/libc3/env.h
+++ b/libc3/env.h
@@ -53,11 +53,13 @@ bool env_eval_quote (s_env *env, const s_quote *quote,
bool env_eval_tag (s_env *env, const s_tag *tag, s_tag *dest);
bool env_eval_tuple (s_env *env, const s_tuple *tuple,
s_tag *dest);
-bool env_module_load (s_env *env, const s_sym *name,
+bool env_module_load (const s_sym *module, s_env *env,
s_facts *facts);
-bool env_module_maybe_reload (s_env *env, const s_sym *name,
+bool env_module_maybe_reload (const s_sym *module, s_env *env,
s_facts *facts);
-s8 env_operator_arity (s_env *env, const s_ident *op);
+s_ident * env_operator_call_ident (s_env *env, const s_ident *op,
+ s_ident *dest, u8 arity);
+bool env_operator_find (s_env *env, const s_ident *op, u8 arity);
bool env_operator_is_right_associative (s_env *env,
const s_ident *op);
s8 env_operator_precedence (s_env *env, const s_ident *op);
diff --git a/libc3/hash.c b/libc3/hash.c
index 57785c0..892c18d 100644
--- a/libc3/hash.c
+++ b/libc3/hash.c
@@ -176,8 +176,8 @@ void hash_update_ident (t_hash *hash, const s_ident *ident)
assert(hash);
assert(ident);
hash_update_u8(hash, '_');
- if (ident->module_name) {
- hash_update_sym(hash, ident->module_name);
+ if (ident->module) {
+ hash_update_sym(hash, ident->module);
hash_update_u8(hash, '.');
}
hash_update_sym(hash, ident->sym);
diff --git a/libc3/ident.c b/libc3/ident.c
index 3f57c10..00b94a8 100644
--- a/libc3/ident.c
+++ b/libc3/ident.c
@@ -39,7 +39,7 @@ bool ident_character_is_reserved (character c)
s_ident * ident_copy (const s_ident *src, s_ident *dest)
{
- dest->module_name = src->module_name;
+ dest->module = src->module;
dest->sym = src->sym;
return dest;
}
@@ -73,7 +73,7 @@ s_tag * ident_get (const s_ident *ident, s_facts *facts, s_tag *dest)
s_tag tag_sym;
s_tag tag_symbol;
s_tag tag_var;
- module = ident->module_name;
+ module = ident->module;
if (! module)
module = g_c3_env.current_module;
if (! module_ensure_loaded(module, facts))
@@ -177,12 +177,12 @@ bool ident_has_reserved_characters (const s_ident *ident)
return false;
}
-s_ident * ident_init (s_ident *ident, const s_sym *module_name,
+s_ident * ident_init (s_ident *ident, const s_sym *module,
const s_sym *sym)
{
assert(ident);
assert(sym);
- ident->module_name = module_name;
+ ident->module = module;
ident->sym = sym;
return ident;
}
@@ -216,9 +216,9 @@ void ident_resolve_module (s_ident *ident, const s_env *env)
{
assert(env);
assert(ident);
- if (! ident->module_name) {
+ if (! ident->module) {
assert(env->current_module);
- ident->module_name = env->current_module;
+ ident->module = env->current_module;
}
}
diff --git a/libc3/ident.h b/libc3/ident.h
index 49085ce..2a601e7 100644
--- a/libc3/ident.h
+++ b/libc3/ident.h
@@ -20,7 +20,7 @@
#define IDENT_MAX SYM_MAX
/* Stack-allocation compatible functions */
-s_ident * ident_init (s_ident *ident, const s_sym *module_name,
+s_ident * ident_init (s_ident *ident, const s_sym *module,
const s_sym *sym);
s_ident * ident_init_1 (s_ident *ident, const s8 *p);
diff --git a/libc3/module.c b/libc3/module.c
index 60d8a40..5db56be 100644
--- a/libc3/module.c
+++ b/libc3/module.c
@@ -24,13 +24,13 @@
#include "module.h"
#include "tag.h"
-bool module_ensure_loaded (const s_sym *name, s_facts *facts)
+bool module_ensure_loaded (const s_sym *module, s_facts *facts)
{
s_facts_with_cursor cursor;
s_tag tag_module_name;
s_tag tag_is_a;
s_tag tag_module;
- tag_init_sym(&tag_module_name, name);
+ tag_init_sym(&tag_module_name, module);
tag_init_1( &tag_is_a, ":is_a");
tag_init_1( &tag_module, ":module");
facts_with(facts, &cursor, (t_facts_spec) {
@@ -38,50 +38,50 @@ bool module_ensure_loaded (const s_sym *name, s_facts *facts)
&tag_is_a, &tag_module, /* module exists */
NULL, NULL });
if (! facts_with_cursor_next(&cursor)) {
- if (! module_load(name, facts)) {
+ if (! module_load(module, facts)) {
warnx("module not found: %s",
- name->str.ptr.ps8);
+ module->str.ptr.ps8);
facts_with_cursor_clean(&cursor);
return false;
}
}
facts_with_cursor_clean(&cursor);
- return module_maybe_reload(name, facts);
+ return module_maybe_reload(module, facts);
}
-bool module_load (const s_sym *name, s_facts *facts)
+bool module_load (const s_sym *module, s_facts *facts)
{
- return env_module_load(&g_c3_env, name, facts);
+ return env_module_load(module, &g_c3_env, facts);
}
-s_tag * module_load_time (const s_sym *name, s_facts *facts,
+s_tag * module_load_time (const s_sym *module, s_facts *facts,
s_tag *dest)
{
s_facts_with_cursor cursor;
- s_tag tag_name;
+ s_tag tag_module_name;
s_tag tag_load_time;
- s_tag tag_time;
- tag_init_sym(&tag_name, name);
+ s_tag tag_time_var;
+ tag_init_sym(&tag_module_name, module);
tag_init_1( &tag_load_time, ":load_time");
- tag_init_var(&tag_time);
+ tag_init_var(&tag_time_var);
facts_with(facts, &cursor, (t_facts_spec) {
- &tag_name, &tag_load_time, &tag_time, NULL, NULL });
+ &tag_module_name, &tag_load_time, &tag_time_var, NULL, NULL });
if (! facts_with_cursor_next(&cursor)) {
facts_with_cursor_clean(&cursor);
return NULL;
}
facts_with_cursor_clean(&cursor);
- *dest = tag_time;
+ *dest = tag_time_var;
return dest;
}
-bool module_maybe_reload (const s_sym *name, s_facts *facts)
+bool module_maybe_reload (const s_sym *module, s_facts *facts)
{
- return env_module_maybe_reload(&g_c3_env, name, facts);
+ return env_module_maybe_reload(module, &g_c3_env, facts);
}
-s_str * module_name_path (const s_str *prefix, const s_sym *name,
- s_str *dest)
+s_str * module_path (const s_sym *module, const s_str *prefix,
+ s_str *dest)
{
character b = -1;
character c;
@@ -90,9 +90,9 @@ s_str * module_name_path (const s_str *prefix, const s_sym *name,
sw out_size;
sw r;
assert(dest);
- assert(name);
- buf_init_str(&in, &name->str);
- out_size = module_name_path_size(prefix, name);
+ assert(module);
+ buf_init_str(&in, &module->str);
+ out_size = module_path_size(module, prefix);
buf_init_alloc(&out, out_size);
if ((r = buf_write_str(&out, prefix)) < 0)
goto error;
@@ -122,7 +122,7 @@ s_str * module_name_path (const s_str *prefix, const s_sym *name,
return NULL;
}
-sw module_name_path_size (const s_str *prefix, const s_sym *name)
+sw module_path_size (const s_sym *module, const s_str *prefix)
{
character b = 0;
character c;
@@ -130,8 +130,8 @@ sw module_name_path_size (const s_str *prefix, const s_sym *name)
sw r;
sw result = 0;
assert(prefix);
- assert(name);
- buf_init_str(&in, &name->str);
+ assert(module);
+ buf_init_str(&in, &module->str);
result += prefix->size;
result++;
while ((r = buf_read_character_utf8(&in, &c)) > 0) {
diff --git a/libc3/module.h b/libc3/module.h
index adaeed1..3e6b233 100644
--- a/libc3/module.h
+++ b/libc3/module.h
@@ -23,17 +23,16 @@
#include "types.h"
/* Modifiers */
-bool module_ensure_loaded (const s_sym *name, s_facts *facts);
-bool module_load (const s_sym *name, s_facts *facts);
-bool module_maybe_reload (const s_sym *name, s_facts *facts);
+bool module_ensure_loaded (const s_sym *module, s_facts *facts);
+bool module_load (const s_sym *module, s_facts *facts);
+bool module_maybe_reload (const s_sym *module, s_facts *facts);
/* Observers */
-s_tag * module_load_time (const s_sym *name, s_facts *facts,
+s_tag * module_load_time (const s_sym *module, s_facts *facts,
s_tag *dest);
-s_str * module_name_path (const s_str *prefix, const s_sym *name,
- s_str *dest);
-sw module_name_path_size (const s_str *prefix,
- const s_sym *name);
+s_str * module_path (const s_sym *module, const s_str *prefix,
+ s_str *dest);
+sw module_path_size (const s_sym *module, const s_str *prefix);
const s_sym * module_to_sym (const s_sym *module);
#endif /* MODULE_H */
diff --git a/libc3/operator.c b/libc3/operator.c
index 83648fe..bc30884 100644
--- a/libc3/operator.c
+++ b/libc3/operator.c
@@ -13,9 +13,15 @@
#include <assert.h>
#include "c3.h"
-s8 operator_arity (const s_ident *op)
+s_ident * operator_call_ident (const s_ident *op, u8 arity,
+ s_ident *dest)
{
- return env_operator_arity(&g_c3_env, op);
+ return env_operator_call_ident(&g_c3_env, op, dest, arity);
+}
+
+bool operator_find (const s_ident *op, u8 arity)
+{
+ return env_operator_find(&g_c3_env, op, arity);
}
bool operator_is_right_associative (const s_ident *op)
diff --git a/libc3/operator.h b/libc3/operator.h
index e609b7a..cba13d1 100644
--- a/libc3/operator.h
+++ b/libc3/operator.h
@@ -16,8 +16,10 @@
#include "types.h"
/* Observers */
-s8 operator_arity (const s_ident *op);
-bool operator_is_right_associative (const s_ident *op);
-s8 operator_precedence (const s_ident *op);
+s_ident * operator_call_ident (const s_ident *op, u8 arity,
+ s_ident *dest);
+bool operator_find (const s_ident *op, u8 arity);
+bool operator_is_right_associative (const s_ident *op);
+s8 operator_precedence (const s_ident *op);
#endif /* OPERATOR_H */
diff --git a/libc3/types.h b/libc3/types.h
index 297f936..9cabd76 100644
--- a/libc3/types.h
+++ b/libc3/types.h
@@ -274,7 +274,7 @@ struct fn {
};
struct ident {
- const s_sym *module_name;
+ const s_sym *module;
const s_sym *sym;
};