Commit 35c652a6a9deeda7e1aa48006d1edb471339f4cf

Thomas de Grivel 2023-07-23T19:44:38

wip buf_inspect_array

diff --git a/libc3/array.c b/libc3/array.c
index 783d86d..3b1c0fd 100644
--- a/libc3/array.c
+++ b/libc3/array.c
@@ -49,6 +49,7 @@ s_array * array_copy (const s_array *src, s_array *dest)
   memcpy(dest->dimensions, src->dimensions,
          src->dimension * sizeof(s_array_dimension));
   dest->size = src->size;
+  dest->type = src->type;
   dest->data = calloc(1, src->size);
   memcpy(dest->data, src->data, dest->size);
   return dest;
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 1e4b2bb..5ff7df1 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -981,8 +981,9 @@ sw buf_inspect_quote (s_buf *buf, const s_quote *quote)
   sw r;
   sw result = 0;
   s_buf_save save;
+  buf_save_init(buf, &save);
   if ((r = buf_write_1(buf, "quote ")) < 0)
-    return r;
+    goto clean;
   result += r;
   if ((r = buf_inspect_tag(buf, quote->tag)) < 0)
     goto restore;
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index e108627..4653ef8 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -78,6 +78,7 @@ sw buf_parse_array_data (s_buf *buf, s_array *dest)
   address = calloc(tmp.dimension, sizeof(sw));
   parse = tag_type_to_buf_parse(tmp.type);
   tmp.data = calloc(tmp.dimensions[0].count, tmp.dimensions[0].item_size);
+  tmp.size = tmp.dimensions[0].count * tmp.dimensions[0].item_size;
   data = tmp.data;
   if ((r = buf_parse_array_data_rec(buf, &tmp, 0, address,
                                     parse, &data)) <= 0) {
@@ -835,7 +836,7 @@ sw buf_parse_comments (s_buf *buf)
          c != '\n') {
     csize = r;
     if ((r = buf_ignore(buf, csize)) < 0)
-      return r;
+      goto clean;
     r1 += csize;
   }
   if ((r = buf_parse_comment(buf)) <= 0)
@@ -2112,7 +2113,8 @@ sw buf_parse_tag_primary (s_buf *buf, s_tag *dest)
     tag_integer_reduce(dest);
     goto end;
   }
-  if ((r = buf_parse_tag_list(buf, dest)) != 0 ||
+  if ((r = buf_parse_tag_array(buf, dest)) != 0 ||
+      (r = buf_parse_tag_list(buf, dest)) != 0 ||
       (r = buf_parse_tag_str(buf, dest)) != 0 ||
       (r = buf_parse_tag_tuple(buf, dest)) != 0 ||
       (r = buf_parse_tag_quote(buf, dest)) != 0 ||
@@ -2120,9 +2122,7 @@ sw buf_parse_tag_primary (s_buf *buf, s_tag *dest)
       (r = buf_parse_tag_fn(buf, dest)) != 0 ||
       (r = buf_parse_tag_call(buf, dest)) != 0 ||
       (r = buf_parse_tag_ident(buf, dest)) != 0 ||
-      (r = buf_parse_tag_sym(buf, dest)) != 0 ||
-      (r = buf_parse_tag_array(buf, dest)) != 0)
-      
+      (r = buf_parse_tag_sym(buf, dest)) != 0)
     goto end;
   goto restore;
  end:
diff --git a/test/ic3/array.in b/test/ic3/array.in
index 3926d77..a4e17ba 100644
--- a/test/ic3/array.in
+++ b/test/ic3/array.in
@@ -1,8 +1,6 @@
 (u8) {0, 1}
-
 (u8) {{0, 1},
       {2, 3}}
-
 (u8) {{{0, 1},
        {2, 3}},
       {{4, 5},
diff --git a/test/ic3/array.out.expected b/test/ic3/array.out.expected
index ebe727d..38cf4e8 100644
--- a/test/ic3/array.out.expected
+++ b/test/ic3/array.out.expected
@@ -1,3 +1,6 @@
 (u8) {0, 1}
+
 (u8) {{0, 1}, {2, 3}}
+
 (u8) {{{0, 1}, {2, 3}}, {{4, 5}, {6, 7}}}
+