Commit 9809bcf993665fa6a6540e0c8ccb1e7120d91867

Thomas de Grivel 2023-10-21T14:57:54

fixed operators

diff --git a/lib/c3/0.1/c3.facts b/lib/c3/0.1/c3.facts
index bc6da1d..4afb051 100644
--- a/lib/c3/0.1/c3.facts
+++ b/lib/c3/0.1/c3.facts
@@ -6,112 +6,112 @@ replace {C3.operator00, :is_a, :operator}
 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_precedence, 13}
 replace {C3.operator00, :operator_associativity, :left}
 add {C3, :operator, C3.operator01}
 replace {C3.operator01, :is_a, :operator}
 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_precedence, 13}
 replace {C3.operator01, :operator_associativity, :left}
 add {C3, :operator, C3.operator02}
 replace {C3.operator02, :is_a, :operator}
 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_precedence, 12}
 replace {C3.operator02, :operator_associativity, :right}
 add {C3, :operator, C3.operator03}
 replace {C3.operator03, :is_a, :operator}
 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_precedence, 12}
 replace {C3.operator03, :operator_associativity, :right}
 add {C3, :operator, C3.operator04}
 replace {C3.operator04, :is_a, :operator}
 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_precedence, 12}
 replace {C3.operator04, :operator_associativity, :right}
 add {C3, :operator, C3.operator05}
 replace {C3.operator05, :is_a, :operator}
 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_precedence, 11}
 replace {C3.operator05, :operator_associativity, :left}
 add {C3, :operator, C3.operator06}
 replace {C3.operator06, :is_a, :operator}
 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_precedence, 11}
 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, :arity, 2}
 replace {C3.operator07, :cfn, cfn Tag "tag_mod" (Tag, Tag, Result)}
-replace {C3.operator07, :operator_precedence, 3}
+replace {C3.operator07, :operator_precedence, 11}
 replace {C3.operator07, :operator_associativity, :left}
 add {C3, :operator, C3.operator08}
 replace {C3.operator08, :is_a, :operator}
 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_precedence, 10}
 replace {C3.operator08, :operator_associativity, :left}
 add {C3, :operator, C3.operator09}
 replace {C3.operator09, :is_a, :operator}
 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_precedence, 10}
 replace {C3.operator09, :operator_associativity, :left}
 add {C3, :operator, C3.operator10}
 replace {C3.operator10, :is_a, :operator}
 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_precedence, 9}
 replace {C3.operator10, :operator_associativity, :left}
 add {C3, :operator, C3.operator11}
 replace {C3.operator11, :is_a, :operator}
 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_precedence, 9}
 replace {C3.operator11, :operator_associativity, :left}
 add {C3, :operator, C3.operator12}
 replace {C3.operator12, :is_a, :operator}
 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_precedence, 8}
 replace {C3.operator12, :operator_associativity, :left}
 add {C3, :operator, C3.operator13}
 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_precedence, 8}
 replace {C3.operator13, :operator_associativity, :left}
 add {C3, :operator, C3.operator14}
 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_precedence, 8}
 replace {C3.operator14, :operator_associativity, :left}
 add {C3, :operator, C3.operator15}
 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)}
-replace {C3.operator15, :operator_precedence, 6}
+replace {C3.operator15, :operator_precedence, 8}
 replace {C3.operator15, :operator_associativity, :left}
 add {C3, :operator, C3.operator16}
 replace {C3.operator16, :is_a, :operator}
@@ -132,35 +132,35 @@ replace {C3.operator18, :is_a, :operator}
 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_precedence, 6}
 replace {C3.operator18, :operator_associativity, :left}
 add {C3, :operator, C3.operator19}
 replace {C3.operator19, :is_a, :operator}
 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_precedence, 5}
 replace {C3.operator19, :operator_associativity, :left}
 add {C3, :operator, C3.operator20}
 replace {C3.operator20, :is_a, :operator}
 replace {C3.operator20, :symbol, :bor}
 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_precedence, 4}
 replace {C3.operator20, :operator_associativity, :left}
 add {C3, :operator, C3.operator21}
 replace {C3.operator21, :is_a, :operator}
 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_precedence, 3}
 replace {C3.operator21, :operator_associativity, :left}
 add {C3, :operator, C3.operator22}
 replace {C3.operator22, :is_a, :operator}
 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}
+replace {C3.operator22, :cfn, cfn :bool "tag_or" (Tag, Tag)}
+replace {C3.operator22, :operator_precedence, 2}
 replace {C3.operator22, :operator_associativity, :left}
 add {C3, :operator, C3.operator23}
 replace {C3.operator23, :is_a, :operator}
@@ -168,7 +168,7 @@ add {C3.operator23, :is_a, :special_operator}
 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}
+replace {C3.operator23, :operator_precedence, 1}
 replace {C3.operator23, :operator_associativity, :right}
 replace {C3.break, :cfn, cfn Void "c3_break" ()}
 replace {C3, :symbol, C3.first}
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 72509dd..761dfcb 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -356,7 +356,6 @@ sw buf_inspect_call_op (s_buf *buf, const s_call *call, s8 op_precedence)
   right = &list_next(call->arguments)->tag;
   if (left->type == TAG_CALL &&
       operator_find(&left->data.call.ident) &&
-      operator_arity(&left->data.call.ident) == 2 &&
       (precedence = operator_precedence(&left->data.call.ident))
       < op_precedence) {
     paren = true;
@@ -387,7 +386,6 @@ sw buf_inspect_call_op (s_buf *buf, const s_call *call, s8 op_precedence)
   result += r;
   if (right->type == TAG_CALL &&
       operator_find(&right->data.call.ident) &&
-      operator_arity(&right->data.call.ident) == 2 &&
       (precedence = operator_precedence(&right->data.call.ident))
       < op_precedence) {
     paren = true;
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 092ff93..fc7e296 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -674,11 +674,12 @@ sw buf_parse_call_op_rec (s_buf *buf, s_call *dest, u8 min_precedence)
     r = buf_parse_ident_peek(buf, &next_op);
     if (r <= 0)
       break;
-    if (! operator_resolve(&next_op, 2, &next_op))
+    if (! operator_resolve(&next_op, 2, &next_op) &&
+        ! operator_resolve(&next_op, 1, &next_op))
       break;
     next_op_precedence = operator_precedence(&next_op);
     while (r > 0 && operator_arity(&next_op) == 2 &&
-           (next_op_precedence >= op_precedence ||
+           (next_op_precedence > op_precedence ||
             (operator_is_right_associative(&next_op) &&
              next_op_precedence == op_precedence))) {
       call_init_op(&tmp2);
diff --git a/libc3/facts.c b/libc3/facts.c
index 381125d..ec64e5b 100644
--- a/libc3/facts.c
+++ b/libc3/facts.c
@@ -76,7 +76,6 @@ 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/test/ic3/op.in b/test/ic3/op.in
index edb8553..dc7e749 100644
--- a/test/ic3/op.in
+++ b/test/ic3/op.in
@@ -3,9 +3,11 @@ quote 1 + 20
 quote 1 + 20 / 3
 1 + 20 / 3
 quote 1 + 20 / 3 * 4
-1 + 2 / 3 * 4
+1 + 20 / 3 * 4
 quote 1 + 20 / 3 * 4 - 5
-1 + 2 / 3 * 4 - 5
+1 + 20 / 3 * 4 - 5
+quote 20 / 3 * 4 - 5
+20 / 3 * 4 - 5
 quote (1 + 20)
 (1 + 20)
 quote a = (1 + 20)
diff --git a/test/ic3/op.out.expected b/test/ic3/op.out.expected
index 4300433..7ff43c5 100644
--- a/test/ic3/op.out.expected
+++ b/test/ic3/op.out.expected
@@ -6,6 +6,8 @@
 25
 1 + 20 / 3 * 4 - 5
 20
+20 / 3 * 4 - 5
+19
 (1 + 20)
 21
 a = (1 + 20)