diff --git a/lib/c3/0.1/c3.facts b/lib/c3/0.1/c3.facts
index 41ff274..30dc597 100644
--- a/lib/c3/0.1/c3.facts
+++ b/lib/c3/0.1/c3.facts
@@ -3,111 +3,111 @@
replace {C3, :is_a, :module}
replace {C3, :operator, C3.operator00}
replace {C3.operator00, :is_a, :operator}
-replace {C3.operator00, :symbol, _"()"}
+replace {C3.operator00, :symbol, :"()"}
replace {C3.operator00, :arity, 1}
replace {C3.operator00, :cfn, cfn Tag "tag_paren" (Tag, Result)}
replace {C3.operator00, :operator_precedence, 1}
replace {C3.operator00, :operator_associativity, :left}
add {C3, :operator, C3.operator01}
replace {C3.operator01, :is_a, :operator}
-replace {C3.operator01, :symbol, _"[]"}
+replace {C3.operator01, :symbol, :"[]"}
replace {C3.operator01, :arity, 2}
replace {C3.operator01, :cfn, cfn Tag "tag_brackets" (Tag, Tag, Result)}
replace {C3.operator01, :operator_precedence, 1}
replace {C3.operator01, :operator_associativity, :left}
add {C3, :operator, C3.operator02}
replace {C3.operator02, :is_a, :operator}
-replace {C3.operator02, :symbol, !}
+replace {C3.operator02, :symbol, :!}
replace {C3.operator02, :arity, 1}
replace {C3.operator02, :cfn, cfn :bool "tag_not" (Tag)}
replace {C3.operator02, :operator_precedence, 2}
replace {C3.operator02, :operator_associativity, :right}
add {C3, :operator, C3.operator03}
replace {C3.operator03, :is_a, :operator}
-replace {C3.operator03, :symbol, ~}
+replace {C3.operator03, :symbol, :~}
replace {C3.operator03, :arity, 1}
replace {C3.operator03, :cfn, cfn Tag "tag_bnot" (Tag, Result)}
replace {C3.operator03, :operator_precedence, 2}
replace {C3.operator03, :operator_associativity, :right}
add {C3, :operator, C3.operator04}
replace {C3.operator04, :is_a, :operator}
-replace {C3.operator04, :symbol, -}
+replace {C3.operator04, :symbol, :-}
replace {C3.operator04, :arity, 1}
replace {C3.operator04, :cfn, cfn Tag "tag_neg" (Tag, Result)}
replace {C3.operator04, :operator_precedence, 2}
replace {C3.operator04, :operator_associativity, :right}
add {C3, :operator, C3.operator05}
replace {C3.operator05, :is_a, :operator}
-replace {C3.operator05, :symbol, *}
+replace {C3.operator05, :symbol, :*}
replace {C3.operator05, :arity, 2}
replace {C3.operator05, :cfn, cfn Tag "tag_mul" (Tag, Tag, Result)}
replace {C3.operator05, :operator_precedence, 3}
replace {C3.operator05, :operator_associativity, :left}
add {C3, :operator, C3.operator06}
replace {C3.operator06, :is_a, :operator}
-replace {C3.operator06, :symbol, /}
+replace {C3.operator06, :symbol, :/}
replace {C3.operator06, :arity, 2}
replace {C3.operator06, :cfn, cfn Tag "tag_div" (Tag, Tag, Result)}
replace {C3.operator06, :operator_precedence, 3}
replace {C3.operator06, :operator_associativity, :left}
add {C3, :operator, C3.operator07}
replace {C3.operator07, :is_a, :operator}
-replace {C3.operator07, :symbol, mod}
+replace {C3.operator07, :symbol, :mod}
replace {C3.operator07, :arity, 2}
replace {C3.operator07, :cfn, cfn Tag "tag_mod" (Tag, Tag, Result)}
replace {C3.operator07, :operator_precedence, 3}
replace {C3.operator07, :operator_associativity, :left}
add {C3, :operator, C3.operator08}
replace {C3.operator08, :is_a, :operator}
-replace {C3.operator08, :symbol, +}
+replace {C3.operator08, :symbol, :+}
replace {C3.operator08, :arity, 2}
replace {C3.operator08, :cfn, cfn Tag "tag_add" (Tag, Tag, Result)}
replace {C3.operator08, :operator_precedence, 4}
replace {C3.operator08, :operator_associativity, :left}
add {C3, :operator, C3.operator09}
replace {C3.operator09, :is_a, :operator}
-replace {C3.operator09, :symbol, -}
+replace {C3.operator09, :symbol, :-}
replace {C3.operator09, :arity, 2}
replace {C3.operator09, :cfn, cfn Tag "tag_sub" (Tag, Tag, Result)}
replace {C3.operator09, :operator_precedence, 4}
replace {C3.operator09, :operator_associativity, :left}
add {C3, :operator, C3.operator10}
replace {C3.operator10, :is_a, :operator}
-replace {C3.operator10, :symbol, <<}
+replace {C3.operator10, :symbol, :<<}
replace {C3.operator10, :arity, 2}
replace {C3.operator10, :cfn, cfn Tag "tag_shift_left" (Tag, Tag, Result)}
replace {C3.operator10, :operator_precedence, 5}
replace {C3.operator10, :operator_associativity, :left}
add {C3, :operator, C3.operator11}
replace {C3.operator11, :is_a, :operator}
-replace {C3.operator11, :symbol, >>}
+replace {C3.operator11, :symbol, :>>}
replace {C3.operator11, :arity, 2}
replace {C3.operator11, :cfn, cfn Tag "tag_shift_right" (Tag, Tag, Result)}
replace {C3.operator11, :operator_precedence, 5}
replace {C3.operator11, :operator_associativity, :left}
add {C3, :operator, C3.operator12}
replace {C3.operator12, :is_a, :operator}
-replace {C3.operator12, :symbol, <}
+replace {C3.operator12, :symbol, :<}
replace {C3.operator12, :arity, 2}
replace {C3.operator12, :cfn, cfn :bool "tag_lt" (Tag, Tag)}
replace {C3.operator12, :operator_precedence, 6}
replace {C3.operator12, :operator_associativity, :left}
add {C3, :operator, C3.operator13}
-replace {C3.operator13, :symbol, <=}
+replace {C3.operator13, :symbol, :<=}
replace {C3.operator13, :is_a, :operator}
replace {C3.operator13, :arity, 2}
replace {C3.operator13, :cfn, cfn :bool "tag_lte" (Tag, Tag)}
replace {C3.operator13, :operator_precedence, 6}
replace {C3.operator13, :operator_associativity, :left}
add {C3, :operator, C3.operator14}
-replace {C3.operator14, :symbol, >}
+replace {C3.operator14, :symbol, :>}
replace {C3.operator14, :is_a, :operator}
replace {C3.operator14, :arity, 2}
replace {C3.operator14, :cfn, cfn :bool "tag_gt" (Tag, Tag)}
replace {C3.operator14, :operator_precedence, 6}
replace {C3.operator14, :operator_associativity, :left}
add {C3, :operator, C3.operator15}
-replace {C3.operator15, :symbol, >=}
+replace {C3.operator15, :symbol, :>=}
replace {C3.operator15, :is_a, :operator}
replace {C3.operator15, :arity, 2}
replace {C3.operator15, :cfn, cfn :bool "tag_gte" (Tag, Tag)}
@@ -115,49 +115,49 @@ replace {C3.operator15, :operator_precedence, 6}
replace {C3.operator15, :operator_associativity, :left}
add {C3, :operator, C3.operator16}
replace {C3.operator16, :is_a, :operator}
-replace {C3.operator16, :symbol, ==}
+replace {C3.operator16, :symbol, :==}
replace {C3.operator16, :arity, 2}
replace {C3.operator16, :cfn, cfn :bool "tag_eq" (Tag, Tag)}
replace {C3.operator16, :operator_precedence, 7}
replace {C3.operator16, :operator_associativity, :left}
add {C3, :operator, C3.operator17}
replace {C3.operator17, :is_a, :operator}
-replace {C3.operator17, :symbol, !=}
+replace {C3.operator17, :symbol, :!=}
replace {C3.operator17, :arity, 2}
replace {C3.operator17, :cfn, cfn :bool "tag_not_eq" (Tag, Tag)}
replace {C3.operator17, :operator_precedence, 7}
replace {C3.operator17, :operator_associativity, :left}
add {C3, :operator, C3.operator18}
replace {C3.operator18, :is_a, :operator}
-replace {C3.operator18, :symbol, &}
+replace {C3.operator18, :symbol, :&}
replace {C3.operator18, :arity, 2}
replace {C3.operator18, :cfn, cfn :bool "tag_band" (Tag, Tag)}
replace {C3.operator18, :operator_precedence, 8}
replace {C3.operator18, :operator_associativity, :left}
add {C3, :operator, C3.operator19}
replace {C3.operator19, :is_a, :operator}
-replace {C3.operator19, :symbol, ^}
+replace {C3.operator19, :symbol, :^}
replace {C3.operator19, :arity, 2}
replace {C3.operator19, :cfn, cfn :bool "tag_bxor" (Tag, Tag)}
replace {C3.operator19, :operator_precedence, 9}
replace {C3.operator19, :operator_associativity, :left}
add {C3, :operator, C3.operator20}
replace {C3.operator20, :is_a, :operator}
-replace {C3.operator20, :symbol, |}
+replace {C3.operator20, :symbol, :|}
replace {C3.operator20, :arity, 2}
replace {C3.operator20, :cfn, cfn :bool "tag_bor" (Tag, Tag)}
replace {C3.operator20, :operator_precedence, 10}
replace {C3.operator20, :operator_associativity, :left}
add {C3, :operator, C3.operator21}
replace {C3.operator21, :is_a, :operator}
-replace {C3.operator21, :symbol, &&}
+replace {C3.operator21, :symbol, :&&}
replace {C3.operator21, :arity, 2}
replace {C3.operator21, :cfn, cfn :bool "tag_and" (Tag, Tag)}
replace {C3.operator21, :operator_precedence, 11}
replace {C3.operator21, :operator_associativity, :left}
add {C3, :operator, C3.operator22}
replace {C3.operator22, :is_a, :operator}
-replace {C3.operator22, :symbol, ||}
+replace {C3.operator22, :symbol, :||}
replace {C3.operator22, :arity, 2}
replace {C3.operator22, :cfn, cfn :bool "tag_and" (Tag, Tag)}
replace {C3.operator22, :operator_precedence, 12}
@@ -165,7 +165,7 @@ replace {C3.operator22, :operator_associativity, :left}
add {C3, :operator, C3.operator23}
replace {C3.operator23, :is_a, :operator}
add {C3.operator23, :is_a, :special_operator}
-replace {C3.operator23, :symbol, =}
+replace {C3.operator23, :symbol, :=}
replace {C3.operator23, :arity, 2}
replace {C3.operator23, :cfn, cfn Tag "tag_equal" (Tag, Tag, Result)}
replace {C3.operator23, :operator_precedence, 13}
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 09b49d6..1d4f9aa 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -723,7 +723,7 @@ sw buf_inspect_fact_size (const s_fact *fact)
return result;
}
-sw buf_inspect_fact_spec (s_buf *buf, p_facts_spec spec)
+sw buf_inspect_facts_spec (s_buf *buf, p_facts_spec spec)
{
sw r;
sw result = 0;
@@ -743,6 +743,12 @@ sw buf_inspect_fact_spec (s_buf *buf, p_facts_spec spec)
return r;
result += r;
}
+ if ((r = buf_write_1(buf, ", ")) < 0)
+ return r;
+ result += r;
+ if ((r = buf_inspect_tag(buf, spec[1])) < 0)
+ return r;
+ result += r;
if ((r = buf_write_1(buf, "}")) < 0)
return r;
result += r;
diff --git a/libc3/buf_inspect.h b/libc3/buf_inspect.h
index 87abb32..846a103 100644
--- a/libc3/buf_inspect.h
+++ b/libc3/buf_inspect.h
@@ -78,7 +78,7 @@ sw buf_inspect_f64 (s_buf *buf, const f64 *x);
sw buf_inspect_f64_size (const f64 *x);
sw buf_inspect_fact (s_buf *buf, const s_fact *fact);
sw buf_inspect_fact_size (const s_fact *fact);
-sw buf_inspect_fact_spec (s_buf *buf, p_facts_spec spec);
+sw buf_inspect_facts_spec (s_buf *buf, p_facts_spec spec);
sw buf_inspect_fn (s_buf *buf, const s_fn *fn);
sw buf_inspect_fn_algo (s_buf *buf, const s_list *algo);
sw buf_inspect_fn_algo_size (const s_list *algo);
diff --git a/libc3/env.c b/libc3/env.c
index ec8d1e9..fcf9c82 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -791,6 +791,7 @@ s_ident * env_operator_call_ident (s_env *env, const s_ident *op,
bool env_operator_find (s_env *env, const s_ident *op, u8 arity)
{
s_facts_with_cursor cursor;
+ p_facts_spec spec;
s_tag tag_arity;
s_tag tag_arity_u8;
s_tag tag_is_a;
@@ -814,22 +815,23 @@ bool env_operator_find (s_env *env, const s_ident *op, u8 arity)
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_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_u8,
- NULL, NULL });
+ spec = (p_facts_spec) & (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_u8,
+ NULL, NULL };
+ facts_with(&env->facts, &cursor, spec);
if (facts_with_cursor_next(&cursor)) {
facts_with_cursor_clean(&cursor);
return true;
}
- if (false)
- warnx("operator %s not found in module %s",
- tmp.sym->str.ptr.ps8,
- tmp.module->str.ptr.ps8);
- facts_with_cursor_clean(&cursor);
+#ifdef DEBUG_OPERATOR_FIND
+ warnx("env_operator_find: operator %s not found in module %s",
+ tmp.sym->str.ptr.ps8,
+ tmp.module->str.ptr.ps8);
+#endif
return false;
}
@@ -875,9 +877,10 @@ bool env_operator_is_right_associative (s_env *env, const s_ident *op)
facts_with_cursor_clean(&cursor);
return false;
}
- warnx("operator %s not found in module %s",
- op->sym->str.ptr.ps8,
- op->module->str.ptr.ps8);
+ warnx("env_operator_is_right_associative: "
+ "operator %s not found in module %s",
+ tmp.sym->str.ptr.ps8,
+ tmp.module->str.ptr.ps8);
facts_with_cursor_clean(&cursor);
return false;
}
@@ -920,6 +923,11 @@ s8 env_operator_precedence (s_env *env, const s_ident *op)
tag_operator_precedence_var.type == TAG_U8) {
r = tag_operator_precedence_var.data.u8;
}
+ else
+ warnx("env_operator_precedence: "
+ "operator %s not found in module %s",
+ tmp.sym->str.ptr.ps8,
+ tmp.module->str.ptr.ps8);
facts_with_cursor_clean(&cursor);
return r;
}
diff --git a/libc3/facts.c b/libc3/facts.c
index 115d5a8..1916662 100644
--- a/libc3/facts.c
+++ b/libc3/facts.c
@@ -76,6 +76,7 @@ s_fact * facts_add_tags (s_facts *facts, const s_tag *subject,
void facts_clean (s_facts *facts)
{
+ facts_dump_file(facts, "debug.facts");
if (facts->log)
facts_close(facts);
skiplist_delete__fact(facts->index_osp);
diff --git a/libc3/facts_with.c b/libc3/facts_with.c
index a7c163e..30c50eb 100644
--- a/libc3/facts_with.c
+++ b/libc3/facts_with.c
@@ -13,6 +13,9 @@
#include <assert.h>
#include <err.h>
#include <stdlib.h>
+#include "buf.h"
+#include "buf_inspect.h"
+#include "env.h"
#include "facts_cursor.h"
#include "facts_spec.h"
#include "facts_with.h"
@@ -33,6 +36,13 @@ s_facts_with_cursor * facts_with (s_facts *facts,
cursor->levels = calloc(facts_count,
sizeof(s_facts_with_cursor_level));
cursor->spec = facts_spec_new_expand(spec);
+ /*
+ buf_inspect_facts_spec(&g_c3_env.err, spec);
+ buf_write_1(&g_c3_env.err, "\n");
+ buf_inspect_facts_spec(&g_c3_env.err, cursor->spec);
+ buf_write_1(&g_c3_env.err, "\n");
+ buf_flush(&g_c3_env.err);
+ */
/* facts_spec_sort(cursor->spec); */
}
else {
diff --git a/libc3/facts_with_cursor.c b/libc3/facts_with_cursor.c
index 24abd7c..38c9b4c 100644
--- a/libc3/facts_with_cursor.c
+++ b/libc3/facts_with_cursor.c
@@ -51,9 +51,9 @@ s_fact * facts_with_cursor_next (s_facts_with_cursor *cursor)
level = &cursor->levels[cursor->facts_count - 1];
#ifdef DEBUG_FACTS
buf_write_1(&g_c3_env.err, "[debug] cursor->level=");
- buf_inspect_u64(&g_c3_env.err, cursor->level);
+ buf_inspect_uw(&g_c3_env.err, &cursor->level);
buf_write_1(&g_c3_env.err, " level->spec=");
- buf_inspect_fact_spec(&g_c3_env.err, level->spec);
+ buf_inspect_facts_spec(&g_c3_env.err, level->spec);
buf_write_1(&g_c3_env.err, " ");
buf_inspect_fact(&g_c3_env.err, level->fact);
#endif
@@ -92,9 +92,9 @@ s_fact * facts_with_cursor_next (s_facts_with_cursor *cursor)
}
#ifdef DEBUG_FACTS
buf_write_1(&g_c3_env.err, "[debug] cursor->level=");
- buf_inspect_u64(&g_c3_env.err, cursor->level);
+ buf_inspect_uw(&g_c3_env.err, &cursor->level);
buf_write_1(&g_c3_env.err, " level->spec=");
- buf_inspect_fact_spec(&g_c3_env.err, level->spec);
+ buf_inspect_facts_spec(&g_c3_env.err, level->spec);
buf_write_1(&g_c3_env.err, " ");
buf_inspect_fact(&g_c3_env.err, level->fact);
#endif
diff --git a/libc3/sym.c b/libc3/sym.c
index f5adfde..b225a80 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -318,9 +318,7 @@ bool sym_to_tag_type (const s_sym *sym, e_tag_type *dest)
*dest = TAG_TUPLE;
return true;
}
- /*
+ warnx("sym_to_tag_type: unknown type: %s", sym->str.ptr.ps8);
assert(! "sym_to_tag_type: unknown type");
- errx(1, "sym_to_tag_type: unknown type: %s", sym->str.ptr.ps8);
- */
return false;
}
diff --git a/libc3/tag.c b/libc3/tag.c
index dda268f..4294e50 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -4784,8 +4784,7 @@ bool tag_is_number (const s_tag *tag)
bool tag_is_unbound_var (const s_tag *tag)
{
- return (tag &&
- tag->type == TAG_VAR);
+ return (tag && tag->type == TAG_VAR);
}
s_tag * tag_list (s_tag *tag, s_list *x)
diff --git a/libc3/types.h b/libc3/types.h
index 9cabd76..2fadc4b 100644
--- a/libc3/types.h
+++ b/libc3/types.h
@@ -77,7 +77,6 @@ typedef enum {
TAG_F64,
TAG_FACT,
TAG_FN,
- TAG_IDENT,
TAG_INTEGER,
TAG_SW,
TAG_S64,
@@ -95,7 +94,8 @@ typedef enum {
TAG_STR,
TAG_SYM,
TAG_TUPLE,
- TAG_VAR
+ TAG_VAR,
+ TAG_IDENT
} e_tag_type;
/* structs */
@@ -506,9 +506,9 @@ struct facts_with_cursor_level {
struct facts_with_cursor {
s_facts *facts;
s_binding *bindings;
- size_t facts_count;
+ uw facts_count;
s_facts_with_cursor_level *levels;
- size_t level;
+ uw level;
p_facts_spec spec;
pthread_mutex_t mutex;
};