Commit 54f742257a76b6e75d30ee4240f6d701a805f90b

Thomas de Grivel 2024-02-20T16:33:16

fix buf_parse_special_operator

diff --git a/.ic3_history b/.ic3_history
index 251e4c1..c82d322 100644
--- a/.ic3_history
+++ b/.ic3_history
@@ -1,5 +1,3 @@
-List.map([g, l], greet)
-List.reverse(List.map([g, l], greet))
 List.reverse([1, 2, 3])
 123 & 123
 123 | 123
@@ -97,3 +95,5 @@ if 1 2 3 4
 if 1 2 3
 if 1 2
 if
+if_then_else true 1 2
+if_then_else false 1 2
diff --git a/lib/c3/0.1/c3.facts b/lib/c3/0.1/c3.facts
index a718a8d..1e2320a 100644
--- a/lib/c3/0.1/c3.facts
+++ b/lib/c3/0.1/c3.facts
@@ -203,17 +203,3 @@ add {C3, :symbol, C3.if_then_else}
 replace {C3.if_then_else, :arity, 3}
 replace {C3.if_then_else, :is_a, :special_operator}
 replace {C3.if_then_else, :cfn, cfn Tag "c3_if_then_else" (Tag, Tag, Tag, Result)}
-add {C3, :symbol, C3.if}
-replace {C3.if, :arity, [4, 2]}
-replace {C3.if, :is_a, :macro}
-add {C3.if, :is_a, :special_operator}
-replace {C3.if, :fn, macro { (cond, then, :else, else) do
-                               quote if_then_else unquote(cond)
-                                 unquote(then)
-                                 unquote(else)
-                             end
-                             (cond, then) do
-                               quote if_then_else unquote(cond)
-                                 unquote(then)
-                                 unquote(void)
-                             end }}
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 87fa22f..73716c2 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -43,8 +43,6 @@ sw buf_parse_array_data_rec (s_buf *buf, s_array *dest, uw *address,
                              s_tag **tag, uw dimension);
 sw buf_parse_array_dimensions_rec (s_buf *buf, s_array *dest,
                                    uw *address,uw dimension);
-sw buf_parse_special_operator_arguments (s_buf *buf, u8 arity,
-                                         s_call *dest);
 sw buf_peek_array_dimension_count (s_buf *buf, s_array *dest);
 
 sw buf_parse_array (s_buf *buf, s_array *dest)
@@ -2491,8 +2489,9 @@ sw buf_parse_quote (s_buf *buf, s_quote *dest)
 
 sw buf_parse_special_operator (s_buf *buf, s_call *dest)
 {
-  const s_list *a;
+  s_list **args_last;
   s_tag arity;
+  uw i;
   sw r;
   sw result = 0;
   s_buf_save save;
@@ -2511,66 +2510,17 @@ sw buf_parse_special_operator (s_buf *buf, s_call *dest)
     r = 0;
     goto restore;
   }
-  if (arity.type == TAG_U8) {
-    if (! arity.data.u8) {
-      err_write_1("buf_parse_special_operator: ");
-      err_inspect_ident(&tmp.ident);
-      err_write_1("invalid arity: ");
-      err_inspect_tag(&arity);
-      r = -2;
-      goto restore;
-    }
-    if ((r = buf_parse_special_operator_arguments(buf, arity.data.u8,
-                                                  &tmp)) <= 0)
-      goto restore;
-  }
-  else if (arity.type == TAG_LIST) {
-    a = arity.data.list;
-    while (a) {
-      if (a->tag.type != TAG_U8 || ! a->tag.data.u8) {
-        err_write_1("buf_parse_special_operator: ");
-        err_inspect_ident(&tmp.ident);
-        err_write_1("invalid arity: ");
-        err_inspect_tag(&a->tag);
-        r = -2;
-        goto restore;
-      }
-      if ((r = buf_parse_special_operator_arguments(buf, a->tag.data.u8,
-                                                    &tmp)) < 0)
-        goto restore;
-      if (r > 0)
-        break;
-      a = list_next(a);
-    }
+  if (arity.type != TAG_U8 || ! arity.data.u8) {
+    err_write_1("buf_parse_special_operator: ");
+    err_inspect_ident(&tmp.ident);
+    err_write_1("invalid arity: ");
+    err_inspect_tag(&arity);
+    r = -2;
+    goto restore;
   }
-  result += r;
-  r = result;
-  *dest = tmp;
-  goto clean;
- restore:
-  call_clean(&tmp);
-  buf_save_restore_rpos(buf, &save);
- clean:
-  buf_save_clean(buf, &save);
-  return r;
-}
-
-sw buf_parse_special_operator_arguments (s_buf *buf, u8 arity,
-                                         s_call *dest)
-{
-  s_list **args_last;
-  uw i;
-  sw r;
-  sw result = 0;
-  s_buf_save save;
-  s_call tmp;
-  assert(buf);
-  assert(dest);
-  buf_save_init(buf, &save);
-  tmp = *dest;
   args_last = &tmp.arguments;
   i = 0;
-  while (i < arity) {
+  while (i < arity.data.u8) {
     if ((r = buf_parse_comments(buf)) < 0)
       goto restore;
     result += r;