Commit 1346168e79a3b62f00531104edd182bd31ea60e0

Thomas de Grivel 2024-05-21T21:05:32

libc3_test ok, wip ic3_test

diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 3786730..f300e63 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -352,6 +352,7 @@ sw buf_inspect_bool_size (const bool *b)
 
 sw buf_inspect_call (s_buf *buf, const s_call *call)
 {
+  bool b;
   bool op;
   u8 op_arity;
   s8 op_precedence;
@@ -372,7 +373,9 @@ sw buf_inspect_call (s_buf *buf, const s_call *call)
   if (op_arity == 2 &&
       (op_precedence = operator_precedence(&call->ident)) > 0)
     return buf_inspect_call_op(buf, call, op_precedence);
-  if (ident_is_special_operator(&call->ident))
+  if (! ident_is_special_operator(&call->ident, &b))
+    return -1;
+  if (b)
     return buf_inspect_call_special_operator(buf, call);
   if ((r = buf_inspect_ident(buf, &call->ident)) < 0)
     return r;
@@ -671,6 +674,7 @@ sw buf_inspect_call_paren (s_buf *buf, const s_call *call)
 
 sw buf_inspect_call_size (const s_call *call)
 {
+  bool b;
   bool op;
   u8 op_arity;
   s8 op_precedence;
@@ -691,7 +695,9 @@ sw buf_inspect_call_size (const s_call *call)
   if (op_arity == 2 &&
       (op_precedence = operator_precedence(&call->ident)) > 0)
     return buf_inspect_call_op_size(call, op_precedence);
-  if (ident_is_special_operator(&call->ident))
+  if (! ident_is_special_operator(&call->ident, &b))
+    return -1;
+  if (b)
     return buf_inspect_call_special_operator_size(call);
   if ((r = buf_inspect_ident_size(&call->ident)) < 0)
     return r;
@@ -705,11 +711,26 @@ sw buf_inspect_call_size (const s_call *call)
 sw buf_inspect_call_special_operator (s_buf *buf, const s_call *call)
 {
   const s_list *args;
+  bool b;
   sw r;
   sw result = 0;
-  assert(ident_is_special_operator(&call->ident));
-  assert(special_operator_arity(&call->ident) ==
-         list_length(call->arguments));
+  if (! ident_is_special_operator(&call->ident, &b))
+    return -1;
+  if (! b) {
+    err_puts("buf_inspect_call_special_operator:"
+             " not a special operator");
+    assert(! "buf_inspect_call_special_operator:"
+             " not a special operator");
+    return -1;
+  }
+  if (special_operator_arity(&call->ident) !=
+      list_length(call->arguments)) {
+    err_puts("buf_inspect_call_special_operator:"
+             " invalid arity");
+    assert(! "buf_inspect_call_special_operator:"
+             " invalid arity");
+    return -1;
+  }
   args = call->arguments;
   if ((r = buf_inspect_ident(buf, &call->ident)) < 0)
     return r;
@@ -729,11 +750,26 @@ sw buf_inspect_call_special_operator (s_buf *buf, const s_call *call)
 sw buf_inspect_call_special_operator_size (const s_call *call)
 {
   const s_list *args;
+  bool b;
   sw r;
   sw result = 0;
-  assert(ident_is_special_operator(&call->ident));
-  assert(special_operator_arity(&call->ident) ==
-         list_length(call->arguments));
+  if (! ident_is_special_operator(&call->ident, &b))
+    return -1;
+  if (! b) {
+    err_puts("buf_inspect_call_special_operator_size:"
+             " not a special operator");
+    assert(! "buf_inspect_call_special_operator_size:"
+             " not a special operator");
+    return -1;
+  }
+  if (special_operator_arity(&call->ident) !=
+      list_length(call->arguments)) {
+    err_puts("buf_inspect_call_special_operator_size:"
+             " invalid arity");
+    assert(! "buf_inspect_call_special_operator_size:"
+             " invalid arity");
+    return -1;
+  }
   args = call->arguments;
   if ((r = buf_inspect_ident_size(&call->ident)) < 0)
     return r;
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 9b7c95f..6052dbd 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -2813,6 +2813,7 @@ sw buf_parse_quote (s_buf *buf, s_quote *dest)
 
 sw buf_parse_special_operator (s_buf *buf, s_call *dest)
 {
+  bool b;
   s_list **args_last;
   u8 arity;
   uw i;
@@ -2826,7 +2827,11 @@ sw buf_parse_special_operator (s_buf *buf, s_call *dest)
   if ((r = buf_parse_ident(buf, &tmp.ident)) <= 0)
     goto clean;
   result += r;
-  if (! ident_is_special_operator(&tmp.ident)) {
+  if (! ident_is_special_operator(&tmp.ident, &b)) {
+    r = -1;
+    goto restore;
+  }
+  if (! b) {
     r = 0;
     goto restore;
   }
diff --git a/libc3/ident.c b/libc3/ident.c
index be54bc3..d953d43 100644
--- a/libc3/ident.c
+++ b/libc3/ident.c
@@ -18,6 +18,7 @@
 #include "facts.h"
 #include "facts_with.h"
 #include "facts_with_cursor.h"
+#include "ident.h"
 #include "module.h"
 #include "str.h"
 #include "sym.h"
diff --git a/libc3/ident.h b/libc3/ident.h
index 7a1621e..6b3aa93 100644
--- a/libc3/ident.h
+++ b/libc3/ident.h
@@ -36,7 +36,7 @@ bool    ident_first_character_is_reserved (character c);
 s_tag * ident_get (const s_ident *ident, s_facts *facts, s_tag *dest);
 bool    ident_has_reserved_characters (const s_ident *ident);
 s_str * ident_inspect (const s_ident *ident, s_str *dest);
-bool    ident_is_special_operator (const s_ident *ident);
+bool *  ident_is_special_operator (const s_ident *ident, bool *dest);
 bool    ident_to_tag_type (const s_ident *ident, e_tag_type *dest);
 
 #endif /* LIBC3_IDENT_H */
diff --git a/test/facts_cursor_test.c b/test/facts_cursor_test.c
index 8079457..ec3db9b 100644
--- a/test/facts_cursor_test.c
+++ b/test/facts_cursor_test.c
@@ -179,7 +179,7 @@ TEST_CASE(facts_cursor_next)
   TEST_EQ(cursor_fact, NULL);
   facts_cursor_clean(&cursor);
   facts_cursor_init(&facts, &cursor, facts.index_spo, fact, fact);
-  TEST_EQ(facts_cursor_next(&cursor, &cursor_fact), fact);
+  TEST_EQ(facts_cursor_next(&cursor, &cursor_fact), &cursor_fact);
   FACT_TEST_EQ(cursor_fact, fact);
   TEST_EQ(facts_cursor_next(&cursor, &cursor_fact), &cursor_fact);
   TEST_EQ(cursor_fact, NULL);
@@ -229,6 +229,7 @@ TEST_CASE(facts_cursor_next)
   FACT_TEST_EQ(cursor_fact, fact + 5);
   TEST_EQ(facts_cursor_next(&cursor, &cursor_fact), &cursor_fact);
   FACT_TEST_EQ(cursor_fact, fact + 6);
+  TEST_EQ(facts_cursor_next(&cursor, &cursor_fact), &cursor_fact);
   TEST_EQ(cursor_fact, NULL);
   facts_cursor_clean(&cursor);
   facts_cursor_init(&facts, &cursor, facts.index_pos, fact, fact + 6);
diff --git a/test/facts_with_test.c b/test/facts_with_test.c
index 7d7c61c..eaf636f 100644
--- a/test/facts_with_test.c
+++ b/test/facts_with_test.c
@@ -59,8 +59,6 @@ TEST_CASE(facts_with_)
   fact_init(&fact, tag, tag + 1, tag + 2);
   TEST_EQ(facts_with_cursor_next(&cursor, &f), &f);
   FACT_TEST_EQ(&fact, f);
-  TEST_EQ(facts_with_cursor_next(&cursor, &f), &f);
-  TEST_ASSERT(f);
   fact_init(&fact, tag, tag + 1, tag + 3);
   TEST_EQ(facts_with_cursor_next(&cursor, &f), &f);
   FACT_TEST_EQ(&fact, f);