Commit 26a03f17ef802e001b6941946684064aa56464d2

Thomas de Grivel 2023-09-07T12:13:27

wip segv =

diff --git a/ic3/ic3.c b/ic3/ic3.c
index 6530851..54abfce 100644
--- a/ic3/ic3.c
+++ b/ic3/ic3.c
@@ -101,11 +101,6 @@ int main (int argc, char **argv)
   buf_file_open_w(&out, stdout);
   while ((r = ic3_buf_ignore_spaces(&out, &in)) >= 0) {
     if ((r = buf_parse_tag(&in, &input)) > 0) {
-      if (buf_inspect_tag(&out, &input) < 0)
-        break;
-      buf_write_u8(&out, '\n');
-      if ((r = buf_flush(&out)) < 0)
-        break;
       if (! eval_tag(&input, &result)) {
         tag_clean(&input);
         continue;
diff --git a/libc3/compare.c b/libc3/compare.c
index c3fd876..c438433 100644
--- a/libc3/compare.c
+++ b/libc3/compare.c
@@ -773,6 +773,7 @@ s8 compare_tag (const s_tag *a, const s_tag *b) {
   case TAG_CFN: return compare_cfn(&a->data.cfn, &b->data.cfn);
   case TAG_CHARACTER: return compare_character(a->data.character,
                                                b->data.character);
+  case TAG_FACT: return compare_fact(&a->data.fact, &b->data.fact);
   case TAG_FN: return compare_fn(&a->data.fn, &b->data.fn);
   case TAG_IDENT: return compare_ident(&a->data.ident, &b->data.ident);
   case TAG_LIST: return compare_list(a->data.list, b->data.list);
diff --git a/libc3/facts.c b/libc3/facts.c
index f0fc124..115d5a8 100644
--- a/libc3/facts.c
+++ b/libc3/facts.c
@@ -74,44 +74,6 @@ s_fact * facts_add_tags (s_facts *facts, const s_tag *subject,
   return facts_add_fact(facts, &fact);
 }
 
-s_fact * facts_replace_fact (s_facts *facts, const s_fact *fact)
-{
-  assert(facts);
-  assert(fact);
-  return facts_replace_tags(facts, fact->subject, fact->predicate,
-                            fact->object);
-}
-
-s_fact * facts_replace_tags (s_facts *facts, const s_tag *subject,
-                             const s_tag *predicate,
-                             const s_tag *object)
-{
-  s_facts_cursor cursor;
-  s_list *list = NULL;
-  s_fact *f;
-  s_tag var;
-  assert(facts);
-  assert(subject);
-  assert(predicate);
-  assert(object);
-  tag_init_var(&var);
-  facts_lock_w(facts);
-  facts_with_tags(facts, &cursor, (s_tag *) subject,
-                  (s_tag *) predicate, &var);
-  while ((f = facts_cursor_next(&cursor))) {
-    list = list_new(NULL, list);
-    list->tag.data.fact = *f;
-  }
-  facts_cursor_clean(&cursor);
-  while (list) {
-    facts_remove_fact(facts, &list->tag.data.fact);
-    list = list_delete(list);
-  }
-  f = facts_add_tags(facts, subject, predicate, object);
-  facts_lock_unlock_w(facts);
-  return f;
-}
-
 void facts_clean (s_facts *facts)
 {
   if (facts->log)
@@ -576,6 +538,45 @@ bool facts_remove_fact (s_facts *facts, const s_fact *fact)
   return result;
 }
 
+
+s_fact * facts_replace_fact (s_facts *facts, const s_fact *fact)
+{
+  assert(facts);
+  assert(fact);
+  return facts_replace_tags(facts, fact->subject, fact->predicate,
+                            fact->object);
+}
+
+s_fact * facts_replace_tags (s_facts *facts, const s_tag *subject,
+                             const s_tag *predicate,
+                             const s_tag *object)
+{
+  s_facts_cursor cursor;
+  s_list *list = NULL;
+  s_fact *f;
+  s_tag var;
+  assert(facts);
+  assert(subject);
+  assert(predicate);
+  assert(object);
+  tag_init_var(&var);
+  facts_lock_w(facts);
+  facts_with_tags(facts, &cursor, (s_tag *) subject,
+                  (s_tag *) predicate, &var);
+  while ((f = facts_cursor_next(&cursor))) {
+    list = list_new(NULL, list);
+    list->tag.data.fact = *f;
+  }
+  while (list) {
+    facts_remove_fact(facts, &list->tag.data.fact);
+    list = list_delete(list);
+  }
+  facts_cursor_clean(&cursor);
+  f = facts_add_tags(facts, subject, predicate, object);
+  facts_lock_unlock_w(facts);
+  return f;
+}
+
 sw facts_save_file (s_facts *facts, const s8 *path)
 {
   s8 b[BUF_SIZE];
diff --git a/test/ic3/array.in b/test/ic3/array.in
index 2f9e4ef..2290442 100644
--- a/test/ic3/array.in
+++ b/test/ic3/array.in
@@ -1,3 +1,6 @@
+(u8) {0, 1}
+Array.data((u8) {0, 1}, (uw) {0})
+Array.data((u8) {0, 1}, (uw) {1})
 a = (u8) {0, 1}
 Array.data(a, (uw) {0})
 Array.data(a, (uw) {1})
@@ -5,6 +8,8 @@ quote a[0]
 quote a[1]
 a[0]
 a[1]
+(u8) {{0, 1},
+      {2, 3}}
 b = (u8) {{0, 1},
           {2, 3}}
 Array.data(b, (uw) {0, 0})