Commit 808b797f000d8c2bfd09478ed6f75104f3307ebd

Thomas de Grivel 2024-05-17T14:43:07

ic3> cow(1) + cow(1)

diff --git a/.ic3_history b/.ic3_history
index 08269ae..8ac1327 100644
--- a/.ic3_history
+++ b/.ic3_history
@@ -1,7 +1,3 @@
-Plop.a
-defmodule Plop do defoperator :operator_add :+ cfn Tag "tag_add" (Tag, Tag, Result) 10 :left end
-defmodule Plop do defoperator :operator_add :+ cfn Tag "tag_mul" (Tag, Tag, Result) 10 :left end
-defmodule Plop do
   defoperator :operator_add :+ cfn Tag "tag_mul" (Tag, Tag, Result) 10 :left
   def sq = fn (x) { x + x }
 end
@@ -97,3 +93,7 @@ cow 1
 a = cow 1
 a
 a + 1
+cow 1
+type(cow 1)
+cow 1 + cow 1
+cow(1) + cow(1)
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index f729efb..f907c22 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -1191,7 +1191,7 @@ sw buf_parse_cow (s_buf *buf, s_cow *cow)
   sw r;
   sw result = 0;
   s_buf_save save;
-  s_cow tmp;
+  s_cow tmp = {0};
   const s_sym *type;
   assert(buf);
   assert(cow);
@@ -1205,10 +1205,10 @@ sw buf_parse_cow (s_buf *buf, s_cow *cow)
       goto restore;
     result += r;
   }
-  if ((r = buf_read_1(buf, "cow")) <= 0)
+  if ((r = buf_read_1(buf, "cow(")) <= 0)
     goto restore;
   result += r;
-  if ((r = buf_ignore_spaces(buf)) <= 0)
+  if ((r = buf_ignore_spaces(buf)) < 0)
     goto restore;
   result += r;
   if (! cow_init(&tmp, type))
@@ -1216,6 +1216,12 @@ sw buf_parse_cow (s_buf *buf, s_cow *cow)
   if ((r = buf_parse_tag(buf, cow_read_write(&tmp))) <= 0)
     goto restore;
   result += r;
+  if ((r = buf_ignore_spaces(buf)) < 0)
+    goto restore;
+  result += r;
+  if ((r = buf_read_1(buf, ")")) <= 0)
+    goto restore;
+  result += r;
   if (tmp.type != &g_sym_Tag) {
     if (! tag_type(cow_read_write(&tmp), &type)) {
       r = -1;
@@ -1236,6 +1242,7 @@ sw buf_parse_cow (s_buf *buf, s_cow *cow)
   r = result;
   goto clean;
  restore:
+  cow_clean(&tmp);
   buf_save_restore_rpos(buf, &save);
  clean:
   buf_save_clean(buf, &save);
diff --git a/libc3/tag_add.c b/libc3/tag_add.c
index c5ba5d2..248dd82 100644
--- a/libc3/tag_add.c
+++ b/libc3/tag_add.c
@@ -25,6 +25,8 @@ s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest)
   assert(a);
   assert(b);
   assert(dest);
+  a = tag_resolve_cow(a);
+  b = tag_resolve_cow(b);
   switch (a->type) {
   case TAG_COMPLEX:
     switch (b->type) {