diff --git a/libc3/compare.c b/libc3/compare.c
index ba6c23f..88cfa54 100644
--- a/libc3/compare.c
+++ b/libc3/compare.c
@@ -13,7 +13,9 @@
*/
#include <assert.h>
#include <err.h>
+#include <string.h>
#include "compare.h"
+#include "list.h"
#include "tag.h"
#define COMPARE_DEF(type) \
@@ -124,6 +126,69 @@ s8 compare_fact_osp (const s_fact *a, const s_fact *b)
return r;
}
+s8 compare_integer (const s_integer *a, const s_integer *b)
+{
+ sw r;
+ assert(a);
+ assert(b);
+ r = mp_cmp(&a->mp_int, &b->mp_int);
+ switch (r) {
+ case MP_LT: return -1;
+ case MP_EQ: return 0;
+ case MP_GT: return 1;
+ }
+ errx(1, "integer_compare: %s", mp_error_to_string(r));
+ return -1;
+}
+
+s8 compare_integer_s64 (const s_integer *a, s64 b)
+{
+ assert(a);
+ if (b >= 0)
+ return compare_integer_u64(a, b);
+ if (a->mp_int.sign != MP_NEG)
+ return 1;
+ if (a->mp_int.used > 1)
+ return -1;
+ if (a->mp_int.dp[0] < (u64) -b)
+ return 1;
+ if (a->mp_int.dp[0] > (u64) -b)
+ return -1;
+ return 0;
+}
+
+s8 compare_integer_u64 (const s_integer *a, u64 b)
+{
+ sw r;
+ assert(a);
+ r = mp_cmp_d(&a->mp_int, b);
+ switch (r) {
+ case MP_LT: return -1;
+ case MP_EQ: return 0;
+ case MP_GT: return 1;
+ }
+ errx(1, "integer_compare: %s", mp_error_to_string(r));
+ return -1;
+}
+
+/* FIXME: dotted lists and circular lists */
+s8 compare_list (const s_list *a, const s_list *b)
+{
+ s8 r;
+ while (1) {
+ if (a == b)
+ return 0;
+ if (!a)
+ return -1;
+ if (!b)
+ return 1;
+ if ((r = compare_tag(&a->tag, &b->tag)))
+ return r;
+ a = list_next(a);
+ b = list_next(b);
+ }
+}
+
s8 compare_ptr (const void *a, const void *b)
{
if (a < b)
@@ -133,6 +198,17 @@ s8 compare_ptr (const void *a, const void *b)
return 1;
}
+s8 compare_quote (const p_quote a, const p_quote b)
+{
+ if (a == b)
+ return 0;
+ if (! a)
+ return -1;
+ if (! b)
+ return 1;
+ return compare_tag(a, b);
+}
+
COMPARE_DEF(s8)
COMPARE_DEF(s16)
@@ -141,6 +217,47 @@ COMPARE_DEF(s32)
COMPARE_DEF(s64)
+s8 compare_s64_u64 (s64 a, u64 b)
+{
+ if (b >= 0x8000000000000000)
+ return -1;
+ if (a < (s64) b)
+ return -1;
+ if (a > (s64) b)
+ return 1;
+ return 0;
+}
+
+s8 compare_str (const s_str *a, const s_str *b)
+{
+ int r;
+ assert(a);
+ assert(b);
+ if (a == b)
+ return 0;
+ if (a->size < b->size)
+ return -1;
+ if (a->size > b->size)
+ return 1;
+ r = memcmp(a->ptr.p, b->ptr.p, a->size);
+ if (r < 0)
+ return -1;
+ if (r > 0)
+ return 1;
+ return 0;
+}
+
+s8 compare_sym (const s_sym *a, const s_sym *b)
+{
+ if (a == b)
+ return 0;
+ if (!a)
+ return -1;
+ if (!b)
+ return 1;
+ return compare_str(&a->str, &b->str);
+}
+
s8 compare_tag (const s_tag *a, const s_tag *b) {
if (tag_is_bound_var(a))
a = a->data.var;
@@ -197,6 +314,245 @@ s8 compare_tag (const s_tag *a, const s_tag *b) {
return 0;
}
+s8 compare_tag_number (const s_tag *a, const s_tag *b)
+{
+ assert(a);
+ assert(b);
+ switch (a->type.type) {
+ case TAG_INTEGER:
+ switch (b->type.type) {
+ case TAG_INTEGER:
+ return compare_integer(&a->data.integer, &b->data.integer);
+ case TAG_S8:
+ return compare_integer_s64(&a->data.integer, b->data.s8);
+ case TAG_S16:
+ return compare_integer_s64(&a->data.integer, b->data.s16);
+ case TAG_S32:
+ return compare_integer_s64(&a->data.integer, b->data.s32);
+ case TAG_S64:
+ return compare_integer_s64(&a->data.integer, b->data.s64);
+ case TAG_U8:
+ return compare_integer_u64(&a->data.integer, b->data.u8);
+ case TAG_U16:
+ return compare_integer_u64(&a->data.integer, b->data.u16);
+ case TAG_U32:
+ return compare_integer_u64(&a->data.integer, b->data.u32);
+ case TAG_U64:
+ return compare_integer_u64(&a->data.integer, b->data.u64);
+ default: ;
+ }
+ break;
+ case TAG_S8:
+ switch (b->type.type) {
+ case TAG_INTEGER:
+ return -compare_integer_s64(&b->data.integer, a->data.s8);
+ case TAG_S8:
+ return compare_s8(a->data.s8, b->data.s8);
+ case TAG_S16:
+ return compare_s16(a->data.s8, b->data.s16);
+ case TAG_S32:
+ return compare_s32(a->data.s8, b->data.s32);
+ case TAG_S64:
+ return compare_s64(a->data.s8, b->data.s64);
+ case TAG_U8:
+ return compare_s16(a->data.s8, b->data.u8);
+ case TAG_U16:
+ return compare_s32(a->data.s8, b->data.u16);
+ case TAG_U32:
+ return compare_s64(a->data.s8, b->data.u32);
+ case TAG_U64:
+ return compare_s64_u64(a->data.s8, b->data.u64);
+ default: ;
+ }
+ break;
+ case TAG_S16:
+ switch (b->type.type) {
+ case TAG_INTEGER:
+ return -compare_integer_s64(&b->data.integer, a->data.s16);
+ case TAG_S8:
+ return compare_s16(a->data.s16, b->data.s8);
+ case TAG_S16:
+ return compare_s16(a->data.s16, b->data.s16);
+ case TAG_S32:
+ return compare_s32(a->data.s16, b->data.s32);
+ case TAG_S64:
+ return compare_s64(a->data.s16, b->data.s64);
+ case TAG_U8:
+ return compare_s16(a->data.s16, b->data.u8);
+ case TAG_U16:
+ return compare_s32(a->data.s16, b->data.u16);
+ case TAG_U32:
+ return compare_s64(a->data.s16, b->data.u32);
+ case TAG_U64:
+ return compare_s64_u64(a->data.s16, b->data.u64);
+ default: ;
+ }
+ break;
+ case TAG_S32:
+ switch (b->type.type) {
+ case TAG_INTEGER:
+ return -compare_integer_s64(&b->data.integer, a->data.s32);
+ case TAG_S8:
+ return compare_s32(a->data.s32, b->data.s8);
+ case TAG_S16:
+ return compare_s32(a->data.s32, b->data.s16);
+ case TAG_S32:
+ return compare_s32(a->data.s32, b->data.s32);
+ case TAG_S64:
+ return compare_s64(a->data.s32, b->data.s64);
+ case TAG_U8:
+ return compare_s32(a->data.s32, b->data.u8);
+ case TAG_U16:
+ return compare_s32(a->data.s32, b->data.u16);
+ case TAG_U32:
+ return compare_s64(a->data.s32, b->data.u32);
+ case TAG_U64:
+ return compare_s64_u64(a->data.s32, b->data.u64);
+ default: ;
+ }
+ break;
+ case TAG_S64:
+ switch (b->type.type) {
+ case TAG_INTEGER:
+ return -compare_integer_s64(&b->data.integer, a->data.s64);
+ case TAG_S8:
+ return compare_s64(a->data.s64, b->data.s8);
+ case TAG_S16:
+ return compare_s64(a->data.s64, b->data.s16);
+ case TAG_S32:
+ return compare_s64(a->data.s64, b->data.s32);
+ case TAG_S64:
+ return compare_s64(a->data.s64, b->data.s64);
+ case TAG_U8:
+ return compare_s64(a->data.s64, b->data.u8);
+ case TAG_U16:
+ return compare_s64(a->data.s64, b->data.u16);
+ case TAG_U32:
+ return compare_s64(a->data.s64, b->data.u32);
+ case TAG_U64:
+ return compare_s64_u64(a->data.s64, b->data.u64);
+ default: ;
+ }
+ break;
+ case TAG_U8:
+ switch (b->type.type) {
+ case TAG_INTEGER:
+ return -compare_integer_u64(&b->data.integer, a->data.u8);
+ case TAG_S8:
+ return compare_s16(a->data.u8, b->data.s8);
+ case TAG_S16:
+ return compare_s16(a->data.u8, b->data.s16);
+ case TAG_S32:
+ return compare_s32(a->data.u8, b->data.s32);
+ case TAG_S64:
+ return compare_s64(a->data.u8, b->data.s64);
+ case TAG_U8:
+ return compare_u8(a->data.u8, b->data.u8);
+ case TAG_U16:
+ return compare_u16(a->data.u8, b->data.u16);
+ case TAG_U32:
+ return compare_u32(a->data.u8, b->data.u32);
+ case TAG_U64:
+ return compare_u64(a->data.u8, b->data.u64);
+ default: ;
+ }
+ break;
+ case TAG_U16:
+ switch (b->type.type) {
+ case TAG_INTEGER:
+ return -compare_integer_u64(&b->data.integer, a->data.u16);
+ case TAG_S8:
+ return compare_s32(a->data.u16, b->data.s8);
+ case TAG_S16:
+ return compare_s32(a->data.u16, b->data.s16);
+ case TAG_S32:
+ return compare_s32(a->data.u16, b->data.s32);
+ case TAG_S64:
+ return compare_s64(a->data.u16, b->data.s64);
+ case TAG_U8:
+ return compare_u16(a->data.u16, b->data.u8);
+ case TAG_U16:
+ return compare_u16(a->data.u16, b->data.u16);
+ case TAG_U32:
+ return compare_u32(a->data.u16, b->data.u32);
+ case TAG_U64:
+ return compare_u64(a->data.u16, b->data.u64);
+ default: ;
+ }
+ break;
+ case TAG_U32:
+ switch (b->type.type) {
+ case TAG_INTEGER:
+ return -compare_integer_u64(&b->data.integer, a->data.u32);
+ case TAG_S8:
+ return compare_s64(a->data.u32, b->data.s8);
+ case TAG_S16:
+ return compare_s64(a->data.u32, b->data.s16);
+ case TAG_S32:
+ return compare_s64(a->data.u32, b->data.s32);
+ case TAG_S64:
+ return compare_s64(a->data.u32, b->data.s64);
+ case TAG_U8:
+ return compare_u32(a->data.u32, b->data.u8);
+ case TAG_U16:
+ return compare_u32(a->data.u32, b->data.u16);
+ case TAG_U32:
+ return compare_u32(a->data.u32, b->data.u32);
+ case TAG_U64:
+ return compare_u64(a->data.u32, b->data.u64);
+ default: ;
+ }
+ break;
+ case TAG_U64:
+ switch (b->type.type) {
+ case TAG_INTEGER:
+ return -compare_integer_u64(&b->data.integer, a->data.u64);
+ case TAG_S8:
+ return -compare_s64_u64(b->data.s8, a->data.u64);
+ case TAG_S16:
+ return -compare_s64_u64(b->data.s16, a->data.u64);
+ case TAG_S32:
+ return -compare_s64_u64(b->data.s32, a->data.u64);
+ case TAG_S64:
+ return -compare_s64_u64(b->data.s64, a->data.u64);
+ case TAG_U8:
+ return compare_u64(a->data.u64, b->data.u8);
+ case TAG_U16:
+ return compare_u16(a->data.u64, b->data.u16);
+ case TAG_U32:
+ return compare_u32(a->data.u64, b->data.u32);
+ case TAG_U64:
+ return compare_u64(a->data.u64, b->data.u64);
+ default: ;
+ }
+ break;
+ default: ;
+ }
+ assert(! "tag_number_compare: not a number");
+ errx(1, "tag_number_compare: not a number");
+ return 0;
+}
+
+s8 compare_tuple (const s_tuple *a, const s_tuple *b)
+{
+ uw i = 0;
+ s8 r;
+ assert(a);
+ assert(b);
+ if (a == b)
+ return 0;
+ if (a->count < b->count)
+ return -1;
+ if (a->count > b->count)
+ return 1;
+ while (i < a->count) {
+ if ((r = compare_tag(a->tag + i, b->tag + i)))
+ return r;
+ i++;
+ }
+ return 0;
+}
+
COMPARE_DEF(u8)
COMPARE_DEF(u16)
diff --git a/libc3/facts.c b/libc3/facts.c
index 559ee73..5a47243 100644
--- a/libc3/facts.c
+++ b/libc3/facts.c
@@ -93,7 +93,7 @@ sw facts_dump (const s_facts *facts, s_buf *buf)
tag_init_var(&predicate);
tag_init_var(&object);
if ((r = buf_write_1(buf,
- "%{module: C3.Facts,\n"
+ "%{module: C3.Facts.Dump,\n"
" version: 0x0000000000000001,\n"
" count: 0x")) < 0)
return r;
@@ -289,23 +289,18 @@ s_facts * facts_new (s_buf *log)
sw facts_open_buf (s_facts *facts, s_buf *buf)
{
- u64 count;
- u64 digest;
- u64 dump_pos;
- u64 log_pos;
sw r;
if ((r = buf_read_1(buf,
- "%{module: C3.Facts.Open,\n"
- " version: 0x0000000000000001}"
- if ((r = facts_load(facts, buf)) < 0)
- return r;
- if ((r = buf_seek(buf, log_pos, SEEK_SET)) < 0)
+ "%{module: C3.Facts.Save,\n"
+ " version: 0x0000000000000001}")) < 0)
return r;
if ((r = facts_load(facts, buf)) < 0)
return r;
+ if ((r = facts_open_log(facts, buf)) < 0)
+ return r;
return 0;
}
-
+
sw facts_open_file (s_facts *facts, const s8 *path)
{
FILE *fp;
@@ -319,7 +314,7 @@ sw facts_open_file (s_facts *facts, const s8 *path)
warn("fopen: %s", path);
return -1;
}
- if (facts_count(facts))
+ if (facts_count(facts)) {
/* TODO: clear facts
facts_close(facts);
facts_remove_all(facts);
@@ -329,19 +324,29 @@ sw facts_open_file (s_facts *facts, const s8 *path)
}
out = buf_new_alloc(BUF_SIZE);
buf_file_open_w(out, fp);
- if ((r = facts_save_header(facts, out, 0xda39a3ee5e6b4b0d, 100,
- 100)) != 100) {
- warnx("facts_open_file: invalid header (%x)", r);
+ if ((r = facts_save_header(out)) < 0)
+ return r;
+ if ((r = facts_dump(facts, out)) < 0)
+ return r;
buf_flush(out);
facts->log = out;
return r;
}
- fp = fopen(path, "wb"
+ fp = fopen(path, "wb");
return -1;
}
buf_file_open_r(&in, fp);
if ((r = facts_open_buf(facts, &in)) < 0)
return r;
+ fclose(fp);
+ if (! (fp = fopen(path, "wb"))) {
+ warn("fopen: %s", path);
+ return -1;
+ }
+ out = buf_new_alloc(BUF_SIZE);
+ buf_file_open_w(out, fp);
+ facts->log = out;
+ return r;
}
s_tag * facts_ref_tag (s_facts *facts, const s_tag *tag)
@@ -377,17 +382,10 @@ e_bool facts_remove_fact (s_facts *facts, const s_fact *fact)
return false;
}
-sw buf_seek (s_buf *buf, s64 pos, u8 rel);
-{
-}
-
sw facts_save_file (s_facts *facts, const s8 *path)
{
s_buf *buf;
- u64 digest = 0;
- u64 dump_pos = 0;
FILE *fp;
- u64 log_pos = 0;
sw r;
sw result = 0;
assert(facts);
@@ -399,21 +397,12 @@ sw facts_save_file (s_facts *facts, const s8 *path)
return -1;
}
buf_file_open_w(buf, fp);
- if ((r = facts_save_header(facts, buf, digest, dump_pos,
- log_pos)) < 0)
+ if ((r = facts_save_header(buf)) < 0)
goto ko;
result += r;
- dump_pos = result;
if ((r = facts_dump(facts, buf)) < 0)
goto ko;
result += r;
- log_pos = result;
- buf_seek(buf, 0, SEEK_SET);
- if ((r = facts_save_header(facts, buf, digest, dump_pos,
- log_pos)) < 0)
- goto ko;
- buf_flush(buf);
- fseek(fp, log_pos, SEEK_SET);
facts->log = buf;
return result;
ko:
@@ -421,45 +410,13 @@ sw facts_save_file (s_facts *facts, const s8 *path)
return r;
}
-sw facts_save_header (const s_facts *facts, s_buf *buf, u64 digest,
- u64 dump_pos, u64 log_pos)
+sw facts_save_header (s_buf *buf)
{
sw r;
sw result = 0;
if ((r = buf_write_1(buf,
- "%{module: C3.Facts,\n"
- " version: 0x0000000000000001,\n"
- " count: 0x")) < 0)
- return r;
- result += r;
- if ((r = buf_inspect_u64_hex(buf, facts_count(facts))) < 0)
- return r;
- result += r;
- if ((r = buf_write_1(buf, ",\n digest: 0x")) < 0)
- return r;
- result += r;
- if ((r = buf_inspect_u64_hex(buf, digest)) < 0)
- return r;
- result += r;
- if ((r = buf_write_1(buf, ",\n dump: 0x")) < 0)
- return r;
- result += r;
- if ((r = buf_inspect_u64_hex(buf, dump_pos)) < 0)
- return r;
- result += r;
- if ((r = buf_write_1(buf, ",\n log: 0x")) < 0)
- return r;
- result += r;
- if ((r = buf_inspect_u64_hex(buf, log_pos)) < 0)
- return r;
- result += r;
- if ((r = buf_write_1(buf, ",\n log_count: 0x")) < 0)
- return r;
- result += r;
- if ((r = buf_inspect_u64_hex(buf, facts->log_count)) < 0)
- return r;
- result += r;
- if ((r = buf_write_1(buf, "}\n")) < 0)
+ "%{module: C3.Facts.Save,\n"
+ " version: 0x0000000000000001}\n")) < 0)
return r;
result += r;
return result;
diff --git a/libc3/facts.h b/libc3/facts.h
index 3d0736a..000d317 100644
--- a/libc3/facts.h
+++ b/libc3/facts.h
@@ -37,6 +37,7 @@ void facts_close (s_facts *facts);
sw facts_load (s_facts *facts, s_buf *buf);
sw facts_load_file (s_facts *facts, const s8 *path);
sw facts_open_file (s_facts *facts, const s8 *path);
+sw facts_open_log (s_facts *facts, s_buf *buf);
s_tag * facts_ref_tag (s_facts *facts, const s_tag *tag);
e_bool facts_remove_fact (s_facts *facts, const s_fact *fact);
sw facts_save_file (s_facts *facts, const s8 *path);
@@ -49,7 +50,6 @@ s_fact * facts_find_fact (const s_facts *facts, const s_fact *fact);
s_tag * facts_find_tag (const s_facts *facts, const s_tag *tag);
sw facts_log_add (s_buf *log, const s_fact *fact);
sw facts_log_remove (s_buf *log, const s_fact *fact);
-sw facts_save_header (const s_facts *facts, s_buf *buf,
- u64 digest, u64 dump_pos, u64 log_pos);
+sw facts_save_header (s_buf *buf);
#endif /* FACTS_H */
diff --git a/libc3/facts_spec.c b/libc3/facts_spec.c
index 0bf0c14..4d1d15c 100644
--- a/libc3/facts_spec.c
+++ b/libc3/facts_spec.c
@@ -13,6 +13,7 @@
*/
#include <assert.h>
#include <stdlib.h>
+#include "compare.h"
#include "fact.h"
#include "facts_spec.h"
#include "facts_spec_cursor.h"
@@ -67,7 +68,7 @@ p_facts_spec facts_spec_sort (p_facts_spec spec)
while (j < count - i - 1) {
a = spec + j * 4;
b = spec + (j + 1) * 4;
- if (fact_compare_unbound_var_count((s_fact *) a,
+ if (compare_fact_unbound_var_count((s_fact *) a,
(s_fact *) b) > 0) {
s_tag *swap[3];
swap[0] = a[0];
diff --git a/libc3/hash.c b/libc3/hash.c
index 415c877..697cd61 100644
--- a/libc3/hash.c
+++ b/libc3/hash.c
@@ -14,11 +14,13 @@
#include <assert.h>
#include <err.h>
#include <stdlib.h>
+#include <string.h>
#include "hash.h"
+#include "list.h"
#include "str.h"
-#define HASH_UPDATE_DEF(type) \
- void hash_update_##type (t_hash *hash, type x) ! \
+#define HASH_UPDATE_DEF(type) \
+ void hash_update_##type (t_hash *hash, type x) \
{ \
hash_update(hash, &x, sizeof(x)); \
} \
@@ -29,14 +31,14 @@ void hash_init (t_hash *hash)
SHA1Init(hash);
}
-uw hash_to_uw (p_hash hash)
+uw hash_to_uw (t_hash *hash)
{
u8 digest[SHA1_DIGEST_LENGTH];
SHA1Final(digest, hash);
return *((uw *) digest);
}
-u64 hash_to_u64 (p_hash hash)
+u64 hash_to_u64 (t_hash *hash)
{
u8 digest[SHA1_DIGEST_LENGTH];
SHA1Final(digest, hash);
@@ -57,7 +59,7 @@ void hash_update_bool (t_hash *hash, e_bool x)
}
-void hash_update_call (t_hash *hash, const s_call *call);
+void hash_update_call (t_hash *hash, const s_call *call)
{
assert(hash);
assert(call);
@@ -84,38 +86,72 @@ void hash_update_ident (t_hash *hash, const s_ident *ident)
hash_update_sym(hash, ident->sym);
}
+void hash_update_integer (t_hash *hash, const s_integer *i)
+{
+ int j = 0;
+ mp_digit *digit;
+ const s8 type[] = "integer";
+ assert(hash);
+ assert(i);
+ digit = i->mp_int.dp;
+ hash_update(hash, type, 7);
+ hash_update(hash, &i->mp_int.used, sizeof(i->mp_int.used));
+ while (j < i->mp_int.used) {
+ hash_update(hash, digit, sizeof(*digit));
+ digit++;
+ j++;
+ }
+}
+
/* FIXME: circular lists */
void hash_update_list (t_hash *hash, const s_list *list)
{
const s_list *last;
- const u8 type = 2;
+ const s8 type[] = "list";
+ hash_update(hash, &type, sizeof(type));
if (list) {
while (list) {
- hash_update(hash, &type, sizeof(type));
hash_update_tag(hash, &list->tag);
last = list;
list = list_next(list);
}
- return hash_update_tag(hash, &last->next);
+ hash_update_tag(hash, &last->next);
}
- return hash;
}
-HASH_UPDATE_DEF(s8);
-HASH_UPDATE_DEF(s16);
-HASH_UPDATE_DEF(s32);
-HASH_UPDATE_DEF(s64);
+void hash_update_quote (t_hash *hash, const p_quote x)
+{
+ const s8 type[] = "quote";
+ hash_update(hash, type, strlen(type));
+ hash_update_tag(hash, x);
+}
+
+HASH_UPDATE_DEF(s8)
+HASH_UPDATE_DEF(s16)
+HASH_UPDATE_DEF(s32)
+HASH_UPDATE_DEF(s64)
-void hash_update_sym (t_hash *hash, const s_sym *sym);
+void hash_update_str (t_hash *hash, const s_str *str)
{
+ s8 type[] = "str";
assert(hash);
- assert(src);
+ assert(str);
+ hash_update(hash, type, strlen(type));
+ hash_update(hash, &str->size, sizeof(str->size));
+ hash_update(hash, str->ptr.p, str->size);
+}
+
+void hash_update_sym (t_hash *hash, const s_sym *sym)
+{
+ assert(hash);
+ assert(sym);
hash_update_u8(hash, ':');
- hash_update_str(hash, &src->str);
+ hash_update_str(hash, &sym->str);
}
void hash_update_tag (t_hash *hash, const s_tag *tag)
{
+ assert(hash);
assert(tag);
hash_update_u64(hash, tag->type.type);
switch (tag->type.type) {
@@ -150,12 +186,21 @@ void hash_update_tag (t_hash *hash, const s_tag *tag)
case TAG_VAR:
assert(! "var hash update");
errx(1, "var hash update");
- return NULL;
}
- return hash;
}
-HASH_UPDATE_DEF(u8);
-HASH_UPDATE_DEF(u16);
-HASH_UPDATE_DEF(u32);
-HASH_UPDATE_DEF(u64);
+void hash_update_tuple (t_hash *hash, const s_tuple *tuple)
+{
+ uw i = 0;
+ assert(tuple);
+ hash_update(hash, &tuple->count, sizeof(tuple->count));
+ while (i < tuple->count) {
+ hash_update_tag(hash, tuple->tag + i);
+ i++;
+ }
+}
+
+HASH_UPDATE_DEF(u8)
+HASH_UPDATE_DEF(u16)
+HASH_UPDATE_DEF(u32)
+HASH_UPDATE_DEF(u64)
diff --git a/libc3/hash.h b/libc3/hash.h
index c2e16dd..78c4e08 100644
--- a/libc3/hash.h
+++ b/libc3/hash.h
@@ -38,6 +38,7 @@ HASH_UPDATE_PROTOTYPE(s16);
HASH_UPDATE_PROTOTYPE(s32);
HASH_UPDATE_PROTOTYPE(s64);
void hash_update_str (t_hash *hash, const s_str *src);
+void hash_update_sym (t_hash *hash, const s_sym *sym);
void hash_update_tag (t_hash *hash, const s_tag *tag);
void hash_update_tuple (t_hash *hash, const s_tuple *tuple);
HASH_UPDATE_PROTOTYPE(u8);
diff --git a/libc3/integer.c b/libc3/integer.c
index 7238065..cc65fd1 100644
--- a/libc3/integer.c
+++ b/libc3/integer.c
@@ -16,6 +16,7 @@
#include <stdlib.h>
#include "buf.h"
#include "buf_parse.h"
+#include "compare.h"
#include "integer.h"
s_integer * integer_abs (const s_integer *a, s_integer *dest)
@@ -108,51 +109,6 @@ void integer_clean (s_integer *dest)
mp_clear(&dest->mp_int);
}
-s8 integer_compare (const s_integer *a, const s_integer *b)
-{
- sw r;
- assert(a);
- assert(b);
- r = mp_cmp(&a->mp_int, &b->mp_int);
- switch (r) {
- case MP_LT: return -1;
- case MP_EQ: return 0;
- case MP_GT: return 1;
- }
- errx(1, "integer_compare: %s", mp_error_to_string(r));
- return -1;
-}
-
-s8 integer_compare_s64 (const s_integer *a, s64 b)
-{
- assert(a);
- if (b >= 0)
- return integer_compare_u64(a, b);
- if (a->mp_int.sign != MP_NEG)
- return 1;
- if (a->mp_int.used > 1)
- return -1;
- if (a->mp_int.dp[0] < (u64) -b)
- return 1;
- if (a->mp_int.dp[0] > (u64) -b)
- return -1;
- return 0;
-}
-
-s8 integer_compare_u64 (const s_integer *a, u64 b)
-{
- sw r;
- assert(a);
- r = mp_cmp_d(&a->mp_int, b);
- switch (r) {
- case MP_LT: return -1;
- case MP_EQ: return 0;
- case MP_GT: return 1;
- }
- errx(1, "integer_compare: %s", mp_error_to_string(r));
- return -1;
-}
-
s_integer * integer_copy (const s_integer *a, s_integer *dest)
{
sw r;
@@ -188,20 +144,6 @@ s_integer * integer_gcd (const s_integer *a, const s_integer *b,
return dest;
}
-t_hash_context * integer_hash_update (t_hash_context *context,
- const s_integer *i)
-{
- int j = 0;
- mp_digit *digit;
- assert(i);
- digit = i->mp_int.dp;
- while (j < i->mp_int.used) {
- hash_update(context, digit, sizeof(*digit));
- j++;
- }
- return context;
-}
-
s_integer * integer_init (s_integer *dest)
{
sw r;
diff --git a/libc3/list.c b/libc3/list.c
index e660c08..8aeaaa7 100644
--- a/libc3/list.c
+++ b/libc3/list.c
@@ -42,24 +42,6 @@ void list_clean (s_list *list)
}
}
-/* FIXME: does not work on dotted lists or circular lists */
-s8 list_compare (const s_list *a, const s_list *b)
-{
- s8 r;
- while (1) {
- if (a == b)
- return 0;
- if (!a)
- return -1;
- if (!b)
- return 1;
- if ((r = tag_compare(&a->tag, &b->tag)))
- return r;
- a = list_next(a);
- b = list_next(b);
- }
-}
-
/* FIXME: does not work on circular lists */
s_list * list_copy (const s_list *src, s_list **dest)
{
diff --git a/libc3/quote.c b/libc3/quote.c
index b8e10ea..7da20e9 100644
--- a/libc3/quote.c
+++ b/libc3/quote.c
@@ -31,20 +31,3 @@ p_quote quote_init (p_quote *quote, const s_tag *tag)
{
return *quote = tag_new_copy(tag);
}
-
-s8 quote_compare (const p_quote a, const p_quote b)
-{
- if (a == b)
- return 0;
- if (! a)
- return -1;
- if (! b)
- return 1;
- return tag_compare(a, b);
-}
-
-t_hash_context * quote_hash_update (t_hash_context *context,
- const p_quote x)
-{
- return tag_hash_update(context, x);
-}
diff --git a/libc3/s16.c b/libc3/s16.c
deleted file mode 100644
index 21d4539..0000000
--- a/libc3/s16.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* c3
- * Copyright 2022 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software excepted
- * on Apple computers granted the above copyright notice and
- * this permission paragraph are included in all copies and
- * substantial portions of this software.
- *
- * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
- * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
- * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
- * THIS SOFTWARE.
- */
-#include "s16.h"
-
-s8 s16_compare (s16 a, s16 b)
-{
- if (a < b)
- return -1;
- if (a > b)
- return 1;
- return 0;
-}
-
-t_hash_context * s16_hash_update (t_hash_context *context, s16 x)
-{
- return hash_update(context, &x, sizeof(x));
-}
diff --git a/libc3/s16.h b/libc3/s16.h
deleted file mode 100644
index a979c05..0000000
--- a/libc3/s16.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* c3
- * Copyright 2022 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software excepted
- * on Apple computers granted the above copyright notice and
- * this permission paragraph are included in all copies and
- * substantial portions of this software.
- *
- * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
- * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
- * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
- * THIS SOFTWARE.
- */
-#ifndef S16_H
-#define S16_H
-
-#include "hash.h"
-#include "types.h"
-
-s8 s16_compare (s16 a, s16 b);
-t_hash_context * s16_hash_update (t_hash_context *context, s16 i);
-
-#endif /* S16_H */
diff --git a/libc3/s32.c b/libc3/s32.c
deleted file mode 100644
index 49b4f0b..0000000
--- a/libc3/s32.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* c3
- * Copyright 2022 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software excepted
- * on Apple computers granted the above copyright notice and
- * this permission paragraph are included in all copies and
- * substantial portions of this software.
- *
- * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
- * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
- * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
- * THIS SOFTWARE.
- */
-#include "s32.h"
-
-s8 s32_compare (s32 a, s32 b)
-{
- if (a < b)
- return -1;
- if (a > b)
- return 1;
- return 0;
-}
-
-t_hash_context * s32_hash_update (t_hash_context *context, s32 x)
-{
- return hash_update(context, &x, sizeof(x));
-}
diff --git a/libc3/s32.h b/libc3/s32.h
deleted file mode 100644
index cebc0c4..0000000
--- a/libc3/s32.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* c3
- * Copyright 2022 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software excepted
- * on Apple computers granted the above copyright notice and
- * this permission paragraph are included in all copies and
- * substantial portions of this software.
- *
- * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
- * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
- * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
- * THIS SOFTWARE.
- */
-#ifndef S32_H
-#define S32_H
-
-#include "hash.h"
-#include "types.h"
-
-s8 s32_compare (s32 a, s32 b);
-t_hash_context * s32_hash_update (t_hash_context *context, s32 i);
-
-#endif /* S32_H */
diff --git a/libc3/s64.c b/libc3/s64.c
deleted file mode 100644
index 8587eae..0000000
--- a/libc3/s64.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/* c3
- * Copyright 2022 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software excepted
- * on Apple computers granted the above copyright notice and
- * this permission paragraph are included in all copies and
- * substantial portions of this software.
- *
- * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
- * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
- * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
- * THIS SOFTWARE.
- */
-#include "s64.h"
-
-s8 s64_compare (s64 a, s64 b)
-{
- if (a < b)
- return -1;
- if (a > b)
- return 1;
- return 0;
-}
-
-s8 s64_compare_u64 (s64 a, u64 b)
-{
- if (b >= 0x8000000000000000)
- return -1;
- if (a < (s64) b)
- return -1;
- if (a > (s64) b)
- return 1;
- return 0;
-}
-
-t_hash_context * s64_hash_update (t_hash_context *context, s64 x)
-{
- return hash_update(context, &x, sizeof(x));
-}
diff --git a/libc3/s64.h b/libc3/s64.h
deleted file mode 100644
index 4fc6cdb..0000000
--- a/libc3/s64.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* c3
- * Copyright 2022 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software excepted
- * on Apple computers granted the above copyright notice and
- * this permission paragraph are included in all copies and
- * substantial portions of this software.
- *
- * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
- * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
- * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
- * THIS SOFTWARE.
- */
-#ifndef S64_H
-#define S64_H
-
-#include "hash.h"
-#include "types.h"
-
-s8 s64_compare (s64 a, s64 b);
-s8 s64_compare_u64 (s64 a, u64 b);
-t_hash_context * s64_hash_update (t_hash_context *context, s64 i);
-
-#endif /* S64_H */
diff --git a/libc3/s8.c b/libc3/s8.c
deleted file mode 100644
index a60f8f7..0000000
--- a/libc3/s8.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* c3
- * Copyright 2022 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software excepted
- * on Apple computers granted the above copyright notice and
- * this permission paragraph are included in all copies and
- * substantial portions of this software.
- *
- * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
- * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
- * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
- * THIS SOFTWARE.
- */
-#include "s8.h"
-
-s8 s8_compare (s8 a, s8 b)
-{
- if (a < b)
- return -1;
- if (a > b)
- return 1;
- return 0;
-}
-
-t_hash_context * s8_hash_update (t_hash_context *context, s8 x)
-{
- return hash_update(context, &x, sizeof(x));
-}
diff --git a/libc3/s8.h b/libc3/s8.h
deleted file mode 100644
index f18cba3..0000000
--- a/libc3/s8.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* c3
- * Copyright 2022 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software excepted
- * on Apple computers granted the above copyright notice and
- * this permission paragraph are included in all copies and
- * substantial portions of this software.
- *
- * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
- * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
- * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
- * THIS SOFTWARE.
- */
-#ifndef S8_H
-#define S8_H
-
-#include "hash.h"
-#include "types.h"
-
-s8 s8_compare (s8 a, s8 b);
-t_hash_context * s8_hash_update (t_hash_context *context, s8 i);
-
-#endif /* S8_H */
diff --git a/libc3/set.c.in b/libc3/set.c.in
index f4479e1..c609aef 100644
--- a/libc3/set.c.in
+++ b/libc3/set.c.in
@@ -14,6 +14,7 @@
/* Gen from set.c.in NAME=_NAME$ TYPE=_TYPE$ */
#include <assert.h>
#include <stdlib.h>
+#include "compare.h"
#include "_NAME$.h"
#include "set___NAME$.h"
#include "set_item___NAME$.h"
@@ -24,7 +25,7 @@ set_add___NAME$ (s_set___NAME$ *set, const _TYPE$ *data)
uw hash;
assert(set);
assert(data);
- hash = _NAME$_hash(data);
+ hash = _NAME$_hash_uw(data);
return set_add_h___NAME$(set, data, hash);
}
@@ -74,7 +75,7 @@ set_get___NAME$ (const s_set___NAME$ *set, const _TYPE$ *data)
uw hash;
assert(set);
assert(data);
- hash = _NAME$_hash(data);
+ hash = _NAME$_hash_uw(data);
return set_get_h___NAME$(set, data, hash);
}
@@ -86,7 +87,7 @@ set_get_h___NAME$ (const s_set___NAME$ *set, const _TYPE$ *data, uw hash)
assert(data);
i = set_get_hash___NAME$(set, hash);
while (i) {
- if (_NAME$_compare(&i->data, data) == 0)
+ if (compare__NAME$(&i->data, data) == 0)
return i;
i = set_get_hash_next___NAME$(i);
}
diff --git a/libc3/set__fact.c b/libc3/set__fact.c
index 2c6ce3e..4b5b9e8 100644
--- a/libc3/set__fact.c
+++ b/libc3/set__fact.c
@@ -14,6 +14,7 @@
/* Gen from set.c.in NAME=fact TYPE=s_fact */
#include <assert.h>
#include <stdlib.h>
+#include "compare.h"
#include "fact.h"
#include "set__fact.h"
#include "set_item__fact.h"
@@ -24,7 +25,7 @@ set_add__fact (s_set__fact *set, const s_fact *data)
uw hash;
assert(set);
assert(data);
- hash = fact_hash(data);
+ hash = fact_hash_uw(data);
return set_add_h__fact(set, data, hash);
}
@@ -74,7 +75,7 @@ set_get__fact (const s_set__fact *set, const s_fact *data)
uw hash;
assert(set);
assert(data);
- hash = fact_hash(data);
+ hash = fact_hash_uw(data);
return set_get_h__fact(set, data, hash);
}
@@ -86,7 +87,7 @@ set_get_h__fact (const s_set__fact *set, const s_fact *data, uw hash)
assert(data);
i = set_get_hash__fact(set, hash);
while (i) {
- if (fact_compare(&i->data, data) == 0)
+ if (compare_fact(&i->data, data) == 0)
return i;
i = set_get_hash_next__fact(i);
}
diff --git a/libc3/set__tag.c b/libc3/set__tag.c
index 7736e86..ca8dba1 100644
--- a/libc3/set__tag.c
+++ b/libc3/set__tag.c
@@ -14,6 +14,7 @@
/* Gen from set.c.in NAME=tag TYPE=s_tag */
#include <assert.h>
#include <stdlib.h>
+#include "compare.h"
#include "tag.h"
#include "set__tag.h"
#include "set_item__tag.h"
@@ -24,7 +25,7 @@ set_add__tag (s_set__tag *set, const s_tag *data)
uw hash;
assert(set);
assert(data);
- hash = tag_hash(data);
+ hash = tag_hash_uw(data);
return set_add_h__tag(set, data, hash);
}
@@ -74,7 +75,7 @@ set_get__tag (const s_set__tag *set, const s_tag *data)
uw hash;
assert(set);
assert(data);
- hash = tag_hash(data);
+ hash = tag_hash_uw(data);
return set_get_h__tag(set, data, hash);
}
@@ -86,7 +87,7 @@ set_get_h__tag (const s_set__tag *set, const s_tag *data, uw hash)
assert(data);
i = set_get_hash__tag(set, hash);
while (i) {
- if (tag_compare(&i->data, data) == 0)
+ if (compare_tag(&i->data, data) == 0)
return i;
i = set_get_hash_next__tag(i);
}
diff --git a/libc3/skiplist.c.in b/libc3/skiplist.c.in
index a7d0e02..7038e05 100644
--- a/libc3/skiplist.c.in
+++ b/libc3/skiplist.c.in
@@ -14,6 +14,7 @@
#include <assert.h>
#include <stdlib.h>
#include <strings.h>
+#include "compare.h"
#include "_NAME$.h"
#include "skiplist_node___NAME$.h"
#include "skiplist___NAME$.h"
@@ -113,7 +114,7 @@ skiplist_init___NAME$ (s_skiplist___NAME$ *skiplist, u8 max_height, f64 spacing)
{
assert(skiplist);
skiplist->head = skiplist_node_new___NAME$(NULL, max_height);
- skiplist->compare = _NAME$_compare;
+ skiplist->compare = compare__NAME$;
skiplist->length = 0;
skiplist->max_height = max_height;
skiplist_height_table_init___NAME$(skiplist, spacing);
diff --git a/libc3/skiplist__fact.c b/libc3/skiplist__fact.c
index ca98ec3..34e57ea 100644
--- a/libc3/skiplist__fact.c
+++ b/libc3/skiplist__fact.c
@@ -14,6 +14,7 @@
#include <assert.h>
#include <stdlib.h>
#include <strings.h>
+#include "compare.h"
#include "fact.h"
#include "skiplist_node__fact.h"
#include "skiplist__fact.h"
@@ -113,7 +114,7 @@ skiplist_init__fact (s_skiplist__fact *skiplist, u8 max_height, f64 spacing)
{
assert(skiplist);
skiplist->head = skiplist_node_new__fact(NULL, max_height);
- skiplist->compare = fact_compare;
+ skiplist->compare = compare_fact;
skiplist->length = 0;
skiplist->max_height = max_height;
skiplist_height_table_init__fact(skiplist, spacing);
diff --git a/libc3/sources.mk b/libc3/sources.mk
index bdc330a..6de8184 100644
--- a/libc3/sources.mk
+++ b/libc3/sources.mk
@@ -1,3 +1,3 @@
# sources.mk generated by update_sources
-SOURCES = arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c ptr.c quote.c s16.c s32.c s64.c s8.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c
-LO_SOURCES = arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c ptr.c quote.c s16.c s32.c s64.c s8.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c ../libtommath/bn_cutoffs.c ../libtommath/bn_deprecated.c ../libtommath/bn_mp_2expt.c ../libtommath/bn_mp_abs.c ../libtommath/bn_mp_add.c ../libtommath/bn_mp_add_d.c ../libtommath/bn_mp_addmod.c ../libtommath/bn_mp_and.c ../libtommath/bn_mp_clamp.c ../libtommath/bn_mp_clear.c ../libtommath/bn_mp_clear_multi.c ../libtommath/bn_mp_cmp.c ../libtommath/bn_mp_cmp_d.c ../libtommath/bn_mp_cmp_mag.c ../libtommath/bn_mp_cnt_lsb.c ../libtommath/bn_mp_complement.c ../libtommath/bn_mp_copy.c ../libtommath/bn_mp_count_bits.c ../libtommath/bn_mp_decr.c ../libtommath/bn_mp_div.c ../libtommath/bn_mp_div_2.c ../libtommath/bn_mp_div_2d.c ../libtommath/bn_mp_div_3.c ../libtommath/bn_mp_div_d.c ../libtommath/bn_mp_dr_is_modulus.c ../libtommath/bn_mp_dr_reduce.c ../libtommath/bn_mp_dr_setup.c ../libtommath/bn_mp_error_to_string.c ../libtommath/bn_mp_exch.c ../libtommath/bn_mp_expt_u32.c ../libtommath/bn_mp_exptmod.c ../libtommath/bn_mp_exteuclid.c ../libtommath/bn_mp_fread.c ../libtommath/bn_mp_from_sbin.c ../libtommath/bn_mp_from_ubin.c ../libtommath/bn_mp_fwrite.c ../libtommath/bn_mp_gcd.c ../libtommath/bn_mp_get_double.c ../libtommath/bn_mp_get_i32.c ../libtommath/bn_mp_get_i64.c ../libtommath/bn_mp_get_l.c ../libtommath/bn_mp_get_ll.c ../libtommath/bn_mp_get_mag_u32.c ../libtommath/bn_mp_get_mag_u64.c ../libtommath/bn_mp_get_mag_ul.c ../libtommath/bn_mp_get_mag_ull.c ../libtommath/bn_mp_grow.c ../libtommath/bn_mp_incr.c ../libtommath/bn_mp_init.c ../libtommath/bn_mp_init_copy.c ../libtommath/bn_mp_init_i32.c ../libtommath/bn_mp_init_i64.c ../libtommath/bn_mp_init_l.c ../libtommath/bn_mp_init_ll.c ../libtommath/bn_mp_init_multi.c ../libtommath/bn_mp_init_set.c ../libtommath/bn_mp_init_size.c ../libtommath/bn_mp_init_u32.c ../libtommath/bn_mp_init_u64.c ../libtommath/bn_mp_init_ul.c ../libtommath/bn_mp_init_ull.c ../libtommath/bn_mp_invmod.c ../libtommath/bn_mp_is_square.c ../libtommath/bn_mp_iseven.c ../libtommath/bn_mp_isodd.c ../libtommath/bn_mp_kronecker.c ../libtommath/bn_mp_lcm.c ../libtommath/bn_mp_log_u32.c ../libtommath/bn_mp_lshd.c ../libtommath/bn_mp_mod.c ../libtommath/bn_mp_mod_2d.c ../libtommath/bn_mp_mod_d.c ../libtommath/bn_mp_montgomery_calc_normalization.c ../libtommath/bn_mp_montgomery_reduce.c ../libtommath/bn_mp_montgomery_setup.c ../libtommath/bn_mp_mul.c ../libtommath/bn_mp_mul_2.c ../libtommath/bn_mp_mul_2d.c ../libtommath/bn_mp_mul_d.c ../libtommath/bn_mp_mulmod.c ../libtommath/bn_mp_neg.c ../libtommath/bn_mp_or.c ../libtommath/bn_mp_pack.c ../libtommath/bn_mp_pack_count.c ../libtommath/bn_mp_prime_fermat.c ../libtommath/bn_mp_prime_frobenius_underwood.c ../libtommath/bn_mp_prime_is_prime.c ../libtommath/bn_mp_prime_miller_rabin.c ../libtommath/bn_mp_prime_next_prime.c ../libtommath/bn_mp_prime_rabin_miller_trials.c ../libtommath/bn_mp_prime_rand.c ../libtommath/bn_mp_prime_strong_lucas_selfridge.c ../libtommath/bn_mp_radix_size.c ../libtommath/bn_mp_radix_smap.c ../libtommath/bn_mp_rand.c ../libtommath/bn_mp_read_radix.c ../libtommath/bn_mp_reduce.c ../libtommath/bn_mp_reduce_2k.c ../libtommath/bn_mp_reduce_2k_l.c ../libtommath/bn_mp_reduce_2k_setup.c ../libtommath/bn_mp_reduce_2k_setup_l.c ../libtommath/bn_mp_reduce_is_2k.c ../libtommath/bn_mp_reduce_is_2k_l.c ../libtommath/bn_mp_reduce_setup.c ../libtommath/bn_mp_root_u32.c ../libtommath/bn_mp_rshd.c ../libtommath/bn_mp_sbin_size.c ../libtommath/bn_mp_set.c ../libtommath/bn_mp_set_i32.c ../libtommath/bn_mp_set_i64.c ../libtommath/bn_mp_set_l.c ../libtommath/bn_mp_set_ll.c ../libtommath/bn_mp_set_u32.c ../libtommath/bn_mp_set_u64.c ../libtommath/bn_mp_set_ul.c ../libtommath/bn_mp_set_ull.c ../libtommath/bn_mp_shrink.c ../libtommath/bn_mp_signed_rsh.c ../libtommath/bn_mp_sqr.c ../libtommath/bn_mp_sqrmod.c ../libtommath/bn_mp_sqrt.c ../libtommath/bn_mp_sqrtmod_prime.c ../libtommath/bn_mp_sub.c ../libtommath/bn_mp_sub_d.c ../libtommath/bn_mp_submod.c ../libtommath/bn_mp_to_radix.c ../libtommath/bn_mp_to_sbin.c ../libtommath/bn_mp_to_ubin.c ../libtommath/bn_mp_ubin_size.c ../libtommath/bn_mp_unpack.c ../libtommath/bn_mp_xor.c ../libtommath/bn_mp_zero.c ../libtommath/bn_prime_tab.c ../libtommath/bn_s_mp_add.c ../libtommath/bn_s_mp_balance_mul.c ../libtommath/bn_s_mp_exptmod.c ../libtommath/bn_s_mp_exptmod_fast.c ../libtommath/bn_s_mp_get_bit.c ../libtommath/bn_s_mp_invmod_fast.c ../libtommath/bn_s_mp_invmod_slow.c ../libtommath/bn_s_mp_karatsuba_mul.c ../libtommath/bn_s_mp_karatsuba_sqr.c ../libtommath/bn_s_mp_montgomery_reduce_fast.c ../libtommath/bn_s_mp_mul_digs.c ../libtommath/bn_s_mp_mul_digs_fast.c ../libtommath/bn_s_mp_mul_high_digs.c ../libtommath/bn_s_mp_mul_high_digs_fast.c ../libtommath/bn_s_mp_prime_is_divisible.c ../libtommath/bn_s_mp_rand_jenkins.c ../libtommath/bn_s_mp_reverse.c ../libtommath/bn_s_mp_sqr.c ../libtommath/bn_s_mp_sqr_fast.c ../libtommath/bn_s_mp_sub.c ../libtommath/bn_s_mp_toom_mul.c ../libtommath/bn_s_mp_toom_sqr.c
+SOURCES = arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c ptr.c quote.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c
+LO_SOURCES = arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c ptr.c quote.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c ../libtommath/bn_cutoffs.c ../libtommath/bn_deprecated.c ../libtommath/bn_mp_2expt.c ../libtommath/bn_mp_abs.c ../libtommath/bn_mp_add.c ../libtommath/bn_mp_add_d.c ../libtommath/bn_mp_addmod.c ../libtommath/bn_mp_and.c ../libtommath/bn_mp_clamp.c ../libtommath/bn_mp_clear.c ../libtommath/bn_mp_clear_multi.c ../libtommath/bn_mp_cmp.c ../libtommath/bn_mp_cmp_d.c ../libtommath/bn_mp_cmp_mag.c ../libtommath/bn_mp_cnt_lsb.c ../libtommath/bn_mp_complement.c ../libtommath/bn_mp_copy.c ../libtommath/bn_mp_count_bits.c ../libtommath/bn_mp_decr.c ../libtommath/bn_mp_div.c ../libtommath/bn_mp_div_2.c ../libtommath/bn_mp_div_2d.c ../libtommath/bn_mp_div_3.c ../libtommath/bn_mp_div_d.c ../libtommath/bn_mp_dr_is_modulus.c ../libtommath/bn_mp_dr_reduce.c ../libtommath/bn_mp_dr_setup.c ../libtommath/bn_mp_error_to_string.c ../libtommath/bn_mp_exch.c ../libtommath/bn_mp_expt_u32.c ../libtommath/bn_mp_exptmod.c ../libtommath/bn_mp_exteuclid.c ../libtommath/bn_mp_fread.c ../libtommath/bn_mp_from_sbin.c ../libtommath/bn_mp_from_ubin.c ../libtommath/bn_mp_fwrite.c ../libtommath/bn_mp_gcd.c ../libtommath/bn_mp_get_double.c ../libtommath/bn_mp_get_i32.c ../libtommath/bn_mp_get_i64.c ../libtommath/bn_mp_get_l.c ../libtommath/bn_mp_get_ll.c ../libtommath/bn_mp_get_mag_u32.c ../libtommath/bn_mp_get_mag_u64.c ../libtommath/bn_mp_get_mag_ul.c ../libtommath/bn_mp_get_mag_ull.c ../libtommath/bn_mp_grow.c ../libtommath/bn_mp_incr.c ../libtommath/bn_mp_init.c ../libtommath/bn_mp_init_copy.c ../libtommath/bn_mp_init_i32.c ../libtommath/bn_mp_init_i64.c ../libtommath/bn_mp_init_l.c ../libtommath/bn_mp_init_ll.c ../libtommath/bn_mp_init_multi.c ../libtommath/bn_mp_init_set.c ../libtommath/bn_mp_init_size.c ../libtommath/bn_mp_init_u32.c ../libtommath/bn_mp_init_u64.c ../libtommath/bn_mp_init_ul.c ../libtommath/bn_mp_init_ull.c ../libtommath/bn_mp_invmod.c ../libtommath/bn_mp_is_square.c ../libtommath/bn_mp_iseven.c ../libtommath/bn_mp_isodd.c ../libtommath/bn_mp_kronecker.c ../libtommath/bn_mp_lcm.c ../libtommath/bn_mp_log_u32.c ../libtommath/bn_mp_lshd.c ../libtommath/bn_mp_mod.c ../libtommath/bn_mp_mod_2d.c ../libtommath/bn_mp_mod_d.c ../libtommath/bn_mp_montgomery_calc_normalization.c ../libtommath/bn_mp_montgomery_reduce.c ../libtommath/bn_mp_montgomery_setup.c ../libtommath/bn_mp_mul.c ../libtommath/bn_mp_mul_2.c ../libtommath/bn_mp_mul_2d.c ../libtommath/bn_mp_mul_d.c ../libtommath/bn_mp_mulmod.c ../libtommath/bn_mp_neg.c ../libtommath/bn_mp_or.c ../libtommath/bn_mp_pack.c ../libtommath/bn_mp_pack_count.c ../libtommath/bn_mp_prime_fermat.c ../libtommath/bn_mp_prime_frobenius_underwood.c ../libtommath/bn_mp_prime_is_prime.c ../libtommath/bn_mp_prime_miller_rabin.c ../libtommath/bn_mp_prime_next_prime.c ../libtommath/bn_mp_prime_rabin_miller_trials.c ../libtommath/bn_mp_prime_rand.c ../libtommath/bn_mp_prime_strong_lucas_selfridge.c ../libtommath/bn_mp_radix_size.c ../libtommath/bn_mp_radix_smap.c ../libtommath/bn_mp_rand.c ../libtommath/bn_mp_read_radix.c ../libtommath/bn_mp_reduce.c ../libtommath/bn_mp_reduce_2k.c ../libtommath/bn_mp_reduce_2k_l.c ../libtommath/bn_mp_reduce_2k_setup.c ../libtommath/bn_mp_reduce_2k_setup_l.c ../libtommath/bn_mp_reduce_is_2k.c ../libtommath/bn_mp_reduce_is_2k_l.c ../libtommath/bn_mp_reduce_setup.c ../libtommath/bn_mp_root_u32.c ../libtommath/bn_mp_rshd.c ../libtommath/bn_mp_sbin_size.c ../libtommath/bn_mp_set.c ../libtommath/bn_mp_set_i32.c ../libtommath/bn_mp_set_i64.c ../libtommath/bn_mp_set_l.c ../libtommath/bn_mp_set_ll.c ../libtommath/bn_mp_set_u32.c ../libtommath/bn_mp_set_u64.c ../libtommath/bn_mp_set_ul.c ../libtommath/bn_mp_set_ull.c ../libtommath/bn_mp_shrink.c ../libtommath/bn_mp_signed_rsh.c ../libtommath/bn_mp_sqr.c ../libtommath/bn_mp_sqrmod.c ../libtommath/bn_mp_sqrt.c ../libtommath/bn_mp_sqrtmod_prime.c ../libtommath/bn_mp_sub.c ../libtommath/bn_mp_sub_d.c ../libtommath/bn_mp_submod.c ../libtommath/bn_mp_to_radix.c ../libtommath/bn_mp_to_sbin.c ../libtommath/bn_mp_to_ubin.c ../libtommath/bn_mp_ubin_size.c ../libtommath/bn_mp_unpack.c ../libtommath/bn_mp_xor.c ../libtommath/bn_mp_zero.c ../libtommath/bn_prime_tab.c ../libtommath/bn_s_mp_add.c ../libtommath/bn_s_mp_balance_mul.c ../libtommath/bn_s_mp_exptmod.c ../libtommath/bn_s_mp_exptmod_fast.c ../libtommath/bn_s_mp_get_bit.c ../libtommath/bn_s_mp_invmod_fast.c ../libtommath/bn_s_mp_invmod_slow.c ../libtommath/bn_s_mp_karatsuba_mul.c ../libtommath/bn_s_mp_karatsuba_sqr.c ../libtommath/bn_s_mp_montgomery_reduce_fast.c ../libtommath/bn_s_mp_mul_digs.c ../libtommath/bn_s_mp_mul_digs_fast.c ../libtommath/bn_s_mp_mul_high_digs.c ../libtommath/bn_s_mp_mul_high_digs_fast.c ../libtommath/bn_s_mp_prime_is_divisible.c ../libtommath/bn_s_mp_rand_jenkins.c ../libtommath/bn_s_mp_reverse.c ../libtommath/bn_s_mp_sqr.c ../libtommath/bn_s_mp_sqr_fast.c ../libtommath/bn_s_mp_sub.c ../libtommath/bn_s_mp_toom_mul.c ../libtommath/bn_s_mp_toom_sqr.c
diff --git a/libc3/sources.sh b/libc3/sources.sh
index 205275e..fb8d1ad 100644
--- a/libc3/sources.sh
+++ b/libc3/sources.sh
@@ -1,3 +1,3 @@
# sources.sh generated by update_sources
-SOURCES='arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c ptr.c quote.c s16.c s32.c s64.c s8.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c '
-LO_SOURCES='arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c ptr.c quote.c s16.c s32.c s64.c s8.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c ../libtommath/bn_cutoffs.c ../libtommath/bn_deprecated.c ../libtommath/bn_mp_2expt.c ../libtommath/bn_mp_abs.c ../libtommath/bn_mp_add.c ../libtommath/bn_mp_add_d.c ../libtommath/bn_mp_addmod.c ../libtommath/bn_mp_and.c ../libtommath/bn_mp_clamp.c ../libtommath/bn_mp_clear.c ../libtommath/bn_mp_clear_multi.c ../libtommath/bn_mp_cmp.c ../libtommath/bn_mp_cmp_d.c ../libtommath/bn_mp_cmp_mag.c ../libtommath/bn_mp_cnt_lsb.c ../libtommath/bn_mp_complement.c ../libtommath/bn_mp_copy.c ../libtommath/bn_mp_count_bits.c ../libtommath/bn_mp_decr.c ../libtommath/bn_mp_div.c ../libtommath/bn_mp_div_2.c ../libtommath/bn_mp_div_2d.c ../libtommath/bn_mp_div_3.c ../libtommath/bn_mp_div_d.c ../libtommath/bn_mp_dr_is_modulus.c ../libtommath/bn_mp_dr_reduce.c ../libtommath/bn_mp_dr_setup.c ../libtommath/bn_mp_error_to_string.c ../libtommath/bn_mp_exch.c ../libtommath/bn_mp_expt_u32.c ../libtommath/bn_mp_exptmod.c ../libtommath/bn_mp_exteuclid.c ../libtommath/bn_mp_fread.c ../libtommath/bn_mp_from_sbin.c ../libtommath/bn_mp_from_ubin.c ../libtommath/bn_mp_fwrite.c ../libtommath/bn_mp_gcd.c ../libtommath/bn_mp_get_double.c ../libtommath/bn_mp_get_i32.c ../libtommath/bn_mp_get_i64.c ../libtommath/bn_mp_get_l.c ../libtommath/bn_mp_get_ll.c ../libtommath/bn_mp_get_mag_u32.c ../libtommath/bn_mp_get_mag_u64.c ../libtommath/bn_mp_get_mag_ul.c ../libtommath/bn_mp_get_mag_ull.c ../libtommath/bn_mp_grow.c ../libtommath/bn_mp_incr.c ../libtommath/bn_mp_init.c ../libtommath/bn_mp_init_copy.c ../libtommath/bn_mp_init_i32.c ../libtommath/bn_mp_init_i64.c ../libtommath/bn_mp_init_l.c ../libtommath/bn_mp_init_ll.c ../libtommath/bn_mp_init_multi.c ../libtommath/bn_mp_init_set.c ../libtommath/bn_mp_init_size.c ../libtommath/bn_mp_init_u32.c ../libtommath/bn_mp_init_u64.c ../libtommath/bn_mp_init_ul.c ../libtommath/bn_mp_init_ull.c ../libtommath/bn_mp_invmod.c ../libtommath/bn_mp_is_square.c ../libtommath/bn_mp_iseven.c ../libtommath/bn_mp_isodd.c ../libtommath/bn_mp_kronecker.c ../libtommath/bn_mp_lcm.c ../libtommath/bn_mp_log_u32.c ../libtommath/bn_mp_lshd.c ../libtommath/bn_mp_mod.c ../libtommath/bn_mp_mod_2d.c ../libtommath/bn_mp_mod_d.c ../libtommath/bn_mp_montgomery_calc_normalization.c ../libtommath/bn_mp_montgomery_reduce.c ../libtommath/bn_mp_montgomery_setup.c ../libtommath/bn_mp_mul.c ../libtommath/bn_mp_mul_2.c ../libtommath/bn_mp_mul_2d.c ../libtommath/bn_mp_mul_d.c ../libtommath/bn_mp_mulmod.c ../libtommath/bn_mp_neg.c ../libtommath/bn_mp_or.c ../libtommath/bn_mp_pack.c ../libtommath/bn_mp_pack_count.c ../libtommath/bn_mp_prime_fermat.c ../libtommath/bn_mp_prime_frobenius_underwood.c ../libtommath/bn_mp_prime_is_prime.c ../libtommath/bn_mp_prime_miller_rabin.c ../libtommath/bn_mp_prime_next_prime.c ../libtommath/bn_mp_prime_rabin_miller_trials.c ../libtommath/bn_mp_prime_rand.c ../libtommath/bn_mp_prime_strong_lucas_selfridge.c ../libtommath/bn_mp_radix_size.c ../libtommath/bn_mp_radix_smap.c ../libtommath/bn_mp_rand.c ../libtommath/bn_mp_read_radix.c ../libtommath/bn_mp_reduce.c ../libtommath/bn_mp_reduce_2k.c ../libtommath/bn_mp_reduce_2k_l.c ../libtommath/bn_mp_reduce_2k_setup.c ../libtommath/bn_mp_reduce_2k_setup_l.c ../libtommath/bn_mp_reduce_is_2k.c ../libtommath/bn_mp_reduce_is_2k_l.c ../libtommath/bn_mp_reduce_setup.c ../libtommath/bn_mp_root_u32.c ../libtommath/bn_mp_rshd.c ../libtommath/bn_mp_sbin_size.c ../libtommath/bn_mp_set.c ../libtommath/bn_mp_set_i32.c ../libtommath/bn_mp_set_i64.c ../libtommath/bn_mp_set_l.c ../libtommath/bn_mp_set_ll.c ../libtommath/bn_mp_set_u32.c ../libtommath/bn_mp_set_u64.c ../libtommath/bn_mp_set_ul.c ../libtommath/bn_mp_set_ull.c ../libtommath/bn_mp_shrink.c ../libtommath/bn_mp_signed_rsh.c ../libtommath/bn_mp_sqr.c ../libtommath/bn_mp_sqrmod.c ../libtommath/bn_mp_sqrt.c ../libtommath/bn_mp_sqrtmod_prime.c ../libtommath/bn_mp_sub.c ../libtommath/bn_mp_sub_d.c ../libtommath/bn_mp_submod.c ../libtommath/bn_mp_to_radix.c ../libtommath/bn_mp_to_sbin.c ../libtommath/bn_mp_to_ubin.c ../libtommath/bn_mp_ubin_size.c ../libtommath/bn_mp_unpack.c ../libtommath/bn_mp_xor.c ../libtommath/bn_mp_zero.c ../libtommath/bn_prime_tab.c ../libtommath/bn_s_mp_add.c ../libtommath/bn_s_mp_balance_mul.c ../libtommath/bn_s_mp_exptmod.c ../libtommath/bn_s_mp_exptmod_fast.c ../libtommath/bn_s_mp_get_bit.c ../libtommath/bn_s_mp_invmod_fast.c ../libtommath/bn_s_mp_invmod_slow.c ../libtommath/bn_s_mp_karatsuba_mul.c ../libtommath/bn_s_mp_karatsuba_sqr.c ../libtommath/bn_s_mp_montgomery_reduce_fast.c ../libtommath/bn_s_mp_mul_digs.c ../libtommath/bn_s_mp_mul_digs_fast.c ../libtommath/bn_s_mp_mul_high_digs.c ../libtommath/bn_s_mp_mul_high_digs_fast.c ../libtommath/bn_s_mp_prime_is_divisible.c ../libtommath/bn_s_mp_rand_jenkins.c ../libtommath/bn_s_mp_reverse.c ../libtommath/bn_s_mp_sqr.c ../libtommath/bn_s_mp_sqr_fast.c ../libtommath/bn_s_mp_sub.c ../libtommath/bn_s_mp_toom_mul.c ../libtommath/bn_s_mp_toom_sqr.c '
+SOURCES='arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c ptr.c quote.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c '
+LO_SOURCES='arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c ptr.c quote.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c ../libtommath/bn_cutoffs.c ../libtommath/bn_deprecated.c ../libtommath/bn_mp_2expt.c ../libtommath/bn_mp_abs.c ../libtommath/bn_mp_add.c ../libtommath/bn_mp_add_d.c ../libtommath/bn_mp_addmod.c ../libtommath/bn_mp_and.c ../libtommath/bn_mp_clamp.c ../libtommath/bn_mp_clear.c ../libtommath/bn_mp_clear_multi.c ../libtommath/bn_mp_cmp.c ../libtommath/bn_mp_cmp_d.c ../libtommath/bn_mp_cmp_mag.c ../libtommath/bn_mp_cnt_lsb.c ../libtommath/bn_mp_complement.c ../libtommath/bn_mp_copy.c ../libtommath/bn_mp_count_bits.c ../libtommath/bn_mp_decr.c ../libtommath/bn_mp_div.c ../libtommath/bn_mp_div_2.c ../libtommath/bn_mp_div_2d.c ../libtommath/bn_mp_div_3.c ../libtommath/bn_mp_div_d.c ../libtommath/bn_mp_dr_is_modulus.c ../libtommath/bn_mp_dr_reduce.c ../libtommath/bn_mp_dr_setup.c ../libtommath/bn_mp_error_to_string.c ../libtommath/bn_mp_exch.c ../libtommath/bn_mp_expt_u32.c ../libtommath/bn_mp_exptmod.c ../libtommath/bn_mp_exteuclid.c ../libtommath/bn_mp_fread.c ../libtommath/bn_mp_from_sbin.c ../libtommath/bn_mp_from_ubin.c ../libtommath/bn_mp_fwrite.c ../libtommath/bn_mp_gcd.c ../libtommath/bn_mp_get_double.c ../libtommath/bn_mp_get_i32.c ../libtommath/bn_mp_get_i64.c ../libtommath/bn_mp_get_l.c ../libtommath/bn_mp_get_ll.c ../libtommath/bn_mp_get_mag_u32.c ../libtommath/bn_mp_get_mag_u64.c ../libtommath/bn_mp_get_mag_ul.c ../libtommath/bn_mp_get_mag_ull.c ../libtommath/bn_mp_grow.c ../libtommath/bn_mp_incr.c ../libtommath/bn_mp_init.c ../libtommath/bn_mp_init_copy.c ../libtommath/bn_mp_init_i32.c ../libtommath/bn_mp_init_i64.c ../libtommath/bn_mp_init_l.c ../libtommath/bn_mp_init_ll.c ../libtommath/bn_mp_init_multi.c ../libtommath/bn_mp_init_set.c ../libtommath/bn_mp_init_size.c ../libtommath/bn_mp_init_u32.c ../libtommath/bn_mp_init_u64.c ../libtommath/bn_mp_init_ul.c ../libtommath/bn_mp_init_ull.c ../libtommath/bn_mp_invmod.c ../libtommath/bn_mp_is_square.c ../libtommath/bn_mp_iseven.c ../libtommath/bn_mp_isodd.c ../libtommath/bn_mp_kronecker.c ../libtommath/bn_mp_lcm.c ../libtommath/bn_mp_log_u32.c ../libtommath/bn_mp_lshd.c ../libtommath/bn_mp_mod.c ../libtommath/bn_mp_mod_2d.c ../libtommath/bn_mp_mod_d.c ../libtommath/bn_mp_montgomery_calc_normalization.c ../libtommath/bn_mp_montgomery_reduce.c ../libtommath/bn_mp_montgomery_setup.c ../libtommath/bn_mp_mul.c ../libtommath/bn_mp_mul_2.c ../libtommath/bn_mp_mul_2d.c ../libtommath/bn_mp_mul_d.c ../libtommath/bn_mp_mulmod.c ../libtommath/bn_mp_neg.c ../libtommath/bn_mp_or.c ../libtommath/bn_mp_pack.c ../libtommath/bn_mp_pack_count.c ../libtommath/bn_mp_prime_fermat.c ../libtommath/bn_mp_prime_frobenius_underwood.c ../libtommath/bn_mp_prime_is_prime.c ../libtommath/bn_mp_prime_miller_rabin.c ../libtommath/bn_mp_prime_next_prime.c ../libtommath/bn_mp_prime_rabin_miller_trials.c ../libtommath/bn_mp_prime_rand.c ../libtommath/bn_mp_prime_strong_lucas_selfridge.c ../libtommath/bn_mp_radix_size.c ../libtommath/bn_mp_radix_smap.c ../libtommath/bn_mp_rand.c ../libtommath/bn_mp_read_radix.c ../libtommath/bn_mp_reduce.c ../libtommath/bn_mp_reduce_2k.c ../libtommath/bn_mp_reduce_2k_l.c ../libtommath/bn_mp_reduce_2k_setup.c ../libtommath/bn_mp_reduce_2k_setup_l.c ../libtommath/bn_mp_reduce_is_2k.c ../libtommath/bn_mp_reduce_is_2k_l.c ../libtommath/bn_mp_reduce_setup.c ../libtommath/bn_mp_root_u32.c ../libtommath/bn_mp_rshd.c ../libtommath/bn_mp_sbin_size.c ../libtommath/bn_mp_set.c ../libtommath/bn_mp_set_i32.c ../libtommath/bn_mp_set_i64.c ../libtommath/bn_mp_set_l.c ../libtommath/bn_mp_set_ll.c ../libtommath/bn_mp_set_u32.c ../libtommath/bn_mp_set_u64.c ../libtommath/bn_mp_set_ul.c ../libtommath/bn_mp_set_ull.c ../libtommath/bn_mp_shrink.c ../libtommath/bn_mp_signed_rsh.c ../libtommath/bn_mp_sqr.c ../libtommath/bn_mp_sqrmod.c ../libtommath/bn_mp_sqrt.c ../libtommath/bn_mp_sqrtmod_prime.c ../libtommath/bn_mp_sub.c ../libtommath/bn_mp_sub_d.c ../libtommath/bn_mp_submod.c ../libtommath/bn_mp_to_radix.c ../libtommath/bn_mp_to_sbin.c ../libtommath/bn_mp_to_ubin.c ../libtommath/bn_mp_ubin_size.c ../libtommath/bn_mp_unpack.c ../libtommath/bn_mp_xor.c ../libtommath/bn_mp_zero.c ../libtommath/bn_prime_tab.c ../libtommath/bn_s_mp_add.c ../libtommath/bn_s_mp_balance_mul.c ../libtommath/bn_s_mp_exptmod.c ../libtommath/bn_s_mp_exptmod_fast.c ../libtommath/bn_s_mp_get_bit.c ../libtommath/bn_s_mp_invmod_fast.c ../libtommath/bn_s_mp_invmod_slow.c ../libtommath/bn_s_mp_karatsuba_mul.c ../libtommath/bn_s_mp_karatsuba_sqr.c ../libtommath/bn_s_mp_montgomery_reduce_fast.c ../libtommath/bn_s_mp_mul_digs.c ../libtommath/bn_s_mp_mul_digs_fast.c ../libtommath/bn_s_mp_mul_high_digs.c ../libtommath/bn_s_mp_mul_high_digs_fast.c ../libtommath/bn_s_mp_prime_is_divisible.c ../libtommath/bn_s_mp_rand_jenkins.c ../libtommath/bn_s_mp_reverse.c ../libtommath/bn_s_mp_sqr.c ../libtommath/bn_s_mp_sqr_fast.c ../libtommath/bn_s_mp_sub.c ../libtommath/bn_s_mp_toom_mul.c ../libtommath/bn_s_mp_toom_sqr.c '
diff --git a/libc3/str.c b/libc3/str.c
index fb61530..cbdad35 100644
--- a/libc3/str.c
+++ b/libc3/str.c
@@ -43,25 +43,6 @@ s_str * str_copy (const s_str *src, s_str *dest)
return str_init_dup(dest, src);
}
-sw str_compare (const s_str *a, const s_str *b)
-{
- sw r;
- assert(a);
- assert(b);
- if (a == b)
- return 0;
- if (a->size < b->size)
- return -1;
- if (a->size > b->size)
- return 1;
- r = memcmp(a->ptr.p, b->ptr.p, a->size);
- if (r < 0)
- return -1;
- if (r > 0)
- return 1;
- return 0;
-}
-
void str_delete (s_str *str)
{
str_clean(str);
@@ -83,14 +64,6 @@ e_bool str_has_reserved_characters (const s_str *src)
return false;
}
-t_hash_context * str_hash_update (t_hash_context *context,
- const s_str *str)
-{
- assert(str);
- hash_update(context, &str->size, sizeof(str->size));
- return hash_update(context, str->ptr.p, str->size);
-}
-
s_str * str_init (s_str *str, s8 *free, uw size, const s8 *p)
{
assert(str);
diff --git a/libc3/sym.c b/libc3/sym.c
index 7ffc544..5b42998 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -18,6 +18,7 @@
#include "buf.h"
#include "buf_inspect.h"
#include "character.h"
+#include "compare.h"
#include "str.h"
#include "sym.h"
@@ -50,17 +51,6 @@ e_bool sym_character_is_reserved (character c)
c == '}');
}
-s8 sym_compare (const s_sym *a, const s_sym *b)
-{
- if (a == b)
- return 0;
- if (!a)
- return -1;
- if (!b)
- return 1;
- return str_compare(&a->str, &b->str);
-}
-
void sym_delete (s_sym *sym)
{
str_clean(&sym->str);
@@ -87,7 +77,7 @@ const s_sym * sym_find (const s_str *str)
sym_list = g_sym_list;
while (sym_list) {
s_sym *sym = sym_list->sym;
- if (str_compare(str, &sym->str) == 0)
+ if (compare_str(str, &sym->str) == 0)
return sym;
sym_list = sym_list->next;
}
diff --git a/libc3/sym.h b/libc3/sym.h
index 9eeae90..ebb389c 100644
--- a/libc3/sym.h
+++ b/libc3/sym.h
@@ -44,8 +44,6 @@ const s_sym * sym_find (const s_str *src);
e_bool sym_has_reserved_characters (const s_sym *sym);
-void sym_hash_update (const s_sym *sym, t_hash *hash);
-
s_str * sym_inspect (const s_sym *sym, s_str *dest);
/** @brief True iff sym is a module name (starts with a capital). */
diff --git a/libc3/tag.c b/libc3/tag.c
index 3579ccb..5be1c28 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -174,7 +174,7 @@ u64 tag_hash_u64 (const s_tag *tag)
t_hash hash;
assert(tag);
hash_init(&hash);
- tag_hash_update(tag, &hash);
+ hash_update_tag(&hash, tag);
return hash_to_u64(&hash);
}
@@ -183,7 +183,7 @@ uw tag_hash_uw (const s_tag *tag)
t_hash hash;
assert(tag);
hash_init(&hash);
- tag_hash_update(tag, &hash);
+ hash_update_tag(&hash, tag);
return hash_to_uw(&hash);
}
@@ -601,225 +601,6 @@ s_tag * tag_new_copy (const s_tag *src)
return tag_copy(src, dest);
}
-s8 tag_number_compare (const s_tag *a, const s_tag *b)
-{
- assert(a);
- assert(b);
- switch (a->type.type) {
- case TAG_INTEGER:
- switch (b->type.type) {
- case TAG_INTEGER:
- return integer_compare(&a->data.integer, &b->data.integer);
- case TAG_S8:
- return integer_compare_s64(&a->data.integer, b->data.s8);
- case TAG_S16:
- return integer_compare_s64(&a->data.integer, b->data.s16);
- case TAG_S32:
- return integer_compare_s64(&a->data.integer, b->data.s32);
- case TAG_S64:
- return integer_compare_s64(&a->data.integer, b->data.s64);
- case TAG_U8:
- return integer_compare_u64(&a->data.integer, b->data.u8);
- case TAG_U16:
- return integer_compare_u64(&a->data.integer, b->data.u16);
- case TAG_U32:
- return integer_compare_u64(&a->data.integer, b->data.u32);
- case TAG_U64:
- return integer_compare_u64(&a->data.integer, b->data.u64);
- default: ;
- }
- break;
- case TAG_S8:
- switch (b->type.type) {
- case TAG_INTEGER:
- return -integer_compare_s64(&b->data.integer, a->data.s8);
- case TAG_S8:
- return s8_compare(a->data.s8, b->data.s8);
- case TAG_S16:
- return s16_compare(a->data.s8, b->data.s16);
- case TAG_S32:
- return s32_compare(a->data.s8, b->data.s32);
- case TAG_S64:
- return s64_compare(a->data.s8, b->data.s64);
- case TAG_U8:
- return s16_compare(a->data.s8, b->data.u8);
- case TAG_U16:
- return s32_compare(a->data.s8, b->data.u16);
- case TAG_U32:
- return s64_compare(a->data.s8, b->data.u32);
- case TAG_U64:
- return s64_compare_u64(a->data.s8, b->data.u64);
- default: ;
- }
- break;
- case TAG_S16:
- switch (b->type.type) {
- case TAG_INTEGER:
- return -integer_compare_s64(&b->data.integer, a->data.s16);
- case TAG_S8:
- return s16_compare(a->data.s16, b->data.s8);
- case TAG_S16:
- return s16_compare(a->data.s16, b->data.s16);
- case TAG_S32:
- return s32_compare(a->data.s16, b->data.s32);
- case TAG_S64:
- return s64_compare(a->data.s16, b->data.s64);
- case TAG_U8:
- return s16_compare(a->data.s16, b->data.u8);
- case TAG_U16:
- return s32_compare(a->data.s16, b->data.u16);
- case TAG_U32:
- return s64_compare(a->data.s16, b->data.u32);
- case TAG_U64:
- return s64_compare_u64(a->data.s16, b->data.u64);
- default: ;
- }
- break;
- case TAG_S32:
- switch (b->type.type) {
- case TAG_INTEGER:
- return -integer_compare_s64(&b->data.integer, a->data.s32);
- case TAG_S8:
- return s32_compare(a->data.s32, b->data.s8);
- case TAG_S16:
- return s32_compare(a->data.s32, b->data.s16);
- case TAG_S32:
- return s32_compare(a->data.s32, b->data.s32);
- case TAG_S64:
- return s64_compare(a->data.s32, b->data.s64);
- case TAG_U8:
- return s32_compare(a->data.s32, b->data.u8);
- case TAG_U16:
- return s32_compare(a->data.s32, b->data.u16);
- case TAG_U32:
- return s64_compare(a->data.s32, b->data.u32);
- case TAG_U64:
- return s64_compare_u64(a->data.s32, b->data.u64);
- default: ;
- }
- break;
- case TAG_S64:
- switch (b->type.type) {
- case TAG_INTEGER:
- return -integer_compare_s64(&b->data.integer, a->data.s64);
- case TAG_S8:
- return s64_compare(a->data.s64, b->data.s8);
- case TAG_S16:
- return s64_compare(a->data.s64, b->data.s16);
- case TAG_S32:
- return s64_compare(a->data.s64, b->data.s32);
- case TAG_S64:
- return s64_compare(a->data.s64, b->data.s64);
- case TAG_U8:
- return s64_compare(a->data.s64, b->data.u8);
- case TAG_U16:
- return s64_compare(a->data.s64, b->data.u16);
- case TAG_U32:
- return s64_compare(a->data.s64, b->data.u32);
- case TAG_U64:
- return s64_compare_u64(a->data.s64, b->data.u64);
- default: ;
- }
- break;
- case TAG_U8:
- switch (b->type.type) {
- case TAG_INTEGER:
- return -integer_compare_u64(&b->data.integer, a->data.u8);
- case TAG_S8:
- return s16_compare(a->data.u8, b->data.s8);
- case TAG_S16:
- return s16_compare(a->data.u8, b->data.s16);
- case TAG_S32:
- return s32_compare(a->data.u8, b->data.s32);
- case TAG_S64:
- return s64_compare(a->data.u8, b->data.s64);
- case TAG_U8:
- return u8_compare(a->data.u8, b->data.u8);
- case TAG_U16:
- return u16_compare(a->data.u8, b->data.u16);
- case TAG_U32:
- return u32_compare(a->data.u8, b->data.u32);
- case TAG_U64:
- return u64_compare(a->data.u8, b->data.u64);
- default: ;
- }
- break;
- case TAG_U16:
- switch (b->type.type) {
- case TAG_INTEGER:
- return -integer_compare_u64(&b->data.integer, a->data.u16);
- case TAG_S8:
- return s32_compare(a->data.u16, b->data.s8);
- case TAG_S16:
- return s32_compare(a->data.u16, b->data.s16);
- case TAG_S32:
- return s32_compare(a->data.u16, b->data.s32);
- case TAG_S64:
- return s64_compare(a->data.u16, b->data.s64);
- case TAG_U8:
- return u16_compare(a->data.u16, b->data.u8);
- case TAG_U16:
- return u16_compare(a->data.u16, b->data.u16);
- case TAG_U32:
- return u32_compare(a->data.u16, b->data.u32);
- case TAG_U64:
- return u64_compare(a->data.u16, b->data.u64);
- default: ;
- }
- break;
- case TAG_U32:
- switch (b->type.type) {
- case TAG_INTEGER:
- return -integer_compare_u64(&b->data.integer, a->data.u32);
- case TAG_S8:
- return s64_compare(a->data.u32, b->data.s8);
- case TAG_S16:
- return s64_compare(a->data.u32, b->data.s16);
- case TAG_S32:
- return s64_compare(a->data.u32, b->data.s32);
- case TAG_S64:
- return s64_compare(a->data.u32, b->data.s64);
- case TAG_U8:
- return u32_compare(a->data.u32, b->data.u8);
- case TAG_U16:
- return u32_compare(a->data.u32, b->data.u16);
- case TAG_U32:
- return u32_compare(a->data.u32, b->data.u32);
- case TAG_U64:
- return u64_compare(a->data.u32, b->data.u64);
- default: ;
- }
- break;
- case TAG_U64:
- switch (b->type.type) {
- case TAG_INTEGER:
- return -integer_compare_u64(&b->data.integer, a->data.u64);
- case TAG_S8:
- return -s64_compare_u64(b->data.s8, a->data.u64);
- case TAG_S16:
- return -s64_compare_u64(b->data.s16, a->data.u64);
- case TAG_S32:
- return -s64_compare_u64(b->data.s32, a->data.u64);
- case TAG_S64:
- return -s64_compare_u64(b->data.s64, a->data.u64);
- case TAG_U8:
- return u64_compare(a->data.u64, b->data.u8);
- case TAG_U16:
- return u16_compare(a->data.u64, b->data.u16);
- case TAG_U32:
- return u32_compare(a->data.u64, b->data.u32);
- case TAG_U64:
- return u64_compare(a->data.u64, b->data.u64);
- default: ;
- }
- break;
- default: ;
- }
- assert(! "tag_number_compare: not a number");
- errx(1, "tag_number_compare: not a number");
- return 0;
-}
-
s_tag * tag_s8 (s_tag *tag, s8 x)
{
assert(tag);
diff --git a/libc3/tuple.c b/libc3/tuple.c
index 39d76da..13a13cd 100644
--- a/libc3/tuple.c
+++ b/libc3/tuple.c
@@ -29,26 +29,6 @@ void tuple_clean (s_tuple *tuple)
free(tuple->tag);
}
-s8 tuple_compare (const s_tuple *a, const s_tuple *b)
-{
- uw i = 0;
- s8 r;
- assert(a);
- assert(b);
- if (a == b)
- return 0;
- if (a->count < b->count)
- return -1;
- if (a->count > b->count)
- return 1;
- while (i < a->count) {
- if ((r = tag_compare(a->tag + i, b->tag + i)))
- return r;
- i++;
- }
- return 0;
-}
-
s_tuple * tuple_copy (const s_tuple *src, s_tuple *dest)
{
uw i = 0;
@@ -68,19 +48,6 @@ void tuple_delete (s_tuple *tuple)
free(tuple);
}
-t_hash_context * tuple_hash_update (t_hash_context *context,
- const s_tuple *tuple)
-{
- uw i = 0;
- assert(tuple);
- hash_update(context, &tuple->count, sizeof(tuple->count));
- while (i < tuple->count) {
- tag_hash_update(context, tuple->tag + i);
- i++;
- }
- return context;
-}
-
s_tuple * tuple_init (s_tuple *tuple, uw count)
{
uw i;