Commit e972b8f88280383fce4cbcc72a59f74ee6fc7440

Thomas de Grivel 2023-07-16T15:15:44

wip

diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 3d8691f..5367830 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -176,68 +176,6 @@
   DEF_BUF_INSPECT_U_BASE(bits, hexadecimal)                            \
   DEF_BUF_INSPECT_U_BASE(bits, octal)
 
-f_buf_inspect buf_inspect (e_tag_type type)
-{
-  switch (type) {
-  case TAG_VOID:
-    return (f_buf_inspect) buf_inspect_void;
-  case TAG_ARRAY:
-  case TAG_BOOL:
-    return (f_buf_inspect) buf_inspect_bool;
-  case TAG_CALL:
-  case TAG_CALL_FN:
-  case TAG_CALL_MACRO:
-    return (f_buf_inspect) buf_inspect_call;
-  case TAG_CFN:
-    return (f_buf_inspect) buf_inspect_cfn;
-  case TAG_CHARACTER:
-    return (f_buf_inspect) buf_inspect_character;
-  case TAG_F32:
-    return (f_buf_inspect) buf_inspect_f32;
-  case TAG_F64:
-    return (f_buf_inspect) buf_inspect_f64;
-  case TAG_FN:
-    return (f_buf_inspect) buf_inspect_fn;
-  case TAG_IDENT:
-    return (f_buf_inspect) buf_inspect_ident;
-  case TAG_INTEGER:
-    return (f_buf_inspect) buf_inspect_integer;
-  case TAG_S64:
-    return (f_buf_inspect) buf_inspect_s64;
-  case TAG_S32:
-    return (f_buf_inspect) buf_inspect_s32;
-  case TAG_S16:
-    return (f_buf_inspect) buf_inspect_s16;
-  case TAG_S8:
-    return (f_buf_inspect) buf_inspect_s8;
-  case TAG_U8:
-    return (f_buf_inspect) buf_inspect_u8;
-  case TAG_U16:
-    return (f_buf_inspect) buf_inspect_u16;
-  case TAG_U32:
-    return (f_buf_inspect) buf_inspect_u32;
-  case TAG_U64:
-    return (f_buf_inspect) buf_inspect_u64;
-  case TAG_LIST:
-    return (f_buf_inspect) buf_inspect_list;
-  case TAG_PTAG:
-    return (f_buf_inspect) buf_inspect_ptag;
-  case TAG_QUOTE:
-    return (f_buf_inspect) buf_inspect_quote;
-  case TAG_STR:
-    return (f_buf_inspect) buf_inspect_str;
-  case TAG_SYM:
-    return (f_buf_inspect) buf_inspect_sym;
-  case TAG_TUPLE:
-    return (f_buf_inspect) buf_inspect_tuple;
-  case TAG_VAR:
-    return (f_buf_inspect) buf_inspect_var;
-  }
-  assert(! "buf_inspect: unknown tag type");
-  errx(1, "buf_inspect: unknown tag type");
-  return NULL;
-}
-
 sw buf_inspect_array (s_buf *buf, const s_array *a)
 {
   uw *address;
@@ -252,15 +190,15 @@ sw buf_inspect_array (s_buf *buf, const s_array *a)
     errx(1, "buf_inspect_array: array of array");
     return -1;
   }
-  inspect = buf_inspect(a->type);
+  inspect = tag_type_to_buf_inspect(a->type);
   if (! (address = calloc(a->dimension, sizeof(uw)))) {
-    err(1, "buf_inspect_array");
+    err(1, "buf_inspect_array: calloc");
     return -1;
   }
   while (i < a->dimension) {
     if (i < a->dimension - 1) {
       if (! address[i]) {
-        if ((r = buf_write_1(buf, "[")) < 0)
+        if ((r = buf_write_1(buf, "{")) < 0)
           return r;
         result += r;
       }
@@ -272,7 +210,7 @@ sw buf_inspect_array (s_buf *buf, const s_array *a)
     }
     if (i == a->dimension - 1) {
       while (address[i] == a->dimensions[i].count) {
-        if ((r = buf_write_1(buf, "],\n")) < 0)
+        if ((r = buf_write_1(buf, "}")) < 0)
           return r;
         result += r;
         if (! i)
diff --git a/libc3/buf_inspect.h b/libc3/buf_inspect.h
index 9a0a9b4..612eef3 100644
--- a/libc3/buf_inspect.h
+++ b/libc3/buf_inspect.h
@@ -49,10 +49,6 @@
   BUF_INSPECT_U_BASE_PROTOTYPES(bits, hexadecimal);                    \
   BUF_INSPECT_U_BASE_PROTOTYPES(bits, octal)
 
-typedef sw (* f_buf_inspect) (s_buf *buf, const void *x);
-
-f_buf_inspect buf_inspect (e_tag_type type);
-
 sw buf_inspect_array (s_buf *buf, const s_array *a);
 sw buf_inspect_array_size (const s_array *a);
 sw buf_inspect_bool (s_buf *buf, const bool *b);
diff --git a/libc3/tag.c b/libc3/tag.c
index 7571164..0f84662 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -2085,89 +2085,125 @@ sw tag_type_size (e_tag_type type)
   return -1;
 }
 
+f_buf_inspect tag_type_to_buf_inspect (e_tag_type type)
+{
+  switch (type) {
+  case TAG_VOID:
+    return (f_buf_inspect) buf_inspect_void;
+  case TAG_ARRAY:
+  case TAG_BOOL:
+    return (f_buf_inspect) buf_inspect_bool;
+  case TAG_CALL:
+  case TAG_CALL_FN:
+  case TAG_CALL_MACRO:
+    return (f_buf_inspect) buf_inspect_call;
+  case TAG_CFN:
+    return (f_buf_inspect) buf_inspect_cfn;
+  case TAG_CHARACTER:
+    return (f_buf_inspect) buf_inspect_character;
+  case TAG_F32:
+    return (f_buf_inspect) buf_inspect_f32;
+  case TAG_F64:
+    return (f_buf_inspect) buf_inspect_f64;
+  case TAG_FN:
+    return (f_buf_inspect) buf_inspect_fn;
+  case TAG_IDENT:
+    return (f_buf_inspect) buf_inspect_ident;
+  case TAG_INTEGER:
+    return (f_buf_inspect) buf_inspect_integer;
+  case TAG_S64:
+    return (f_buf_inspect) buf_inspect_s64;
+  case TAG_S32:
+    return (f_buf_inspect) buf_inspect_s32;
+  case TAG_S16:
+    return (f_buf_inspect) buf_inspect_s16;
+  case TAG_S8:
+    return (f_buf_inspect) buf_inspect_s8;
+  case TAG_U8:
+    return (f_buf_inspect) buf_inspect_u8;
+  case TAG_U16:
+    return (f_buf_inspect) buf_inspect_u16;
+  case TAG_U32:
+    return (f_buf_inspect) buf_inspect_u32;
+  case TAG_U64:
+    return (f_buf_inspect) buf_inspect_u64;
+  case TAG_LIST:
+    return (f_buf_inspect) buf_inspect_list;
+  case TAG_PTAG:
+    return (f_buf_inspect) buf_inspect_ptag;
+  case TAG_QUOTE:
+    return (f_buf_inspect) buf_inspect_quote;
+  case TAG_STR:
+    return (f_buf_inspect) buf_inspect_str;
+  case TAG_SYM:
+    return (f_buf_inspect) buf_inspect_sym;
+  case TAG_TUPLE:
+    return (f_buf_inspect) buf_inspect_tuple;
+  case TAG_VAR:
+    return (f_buf_inspect) buf_inspect_var;
+  }
+  assert(! "buf_inspect: unknown tag type");
+  errx(1, "buf_inspect: unknown tag type");
+  return NULL;
+}
+
 f_buf_parse tag_type_to_buf_parse (e_tag_type type)
 {
   switch (type) {
   case TAG_VOID:
     return (f_buf_parse) buf_parse_void;
-    break;
   case TAG_ARRAY:
     return (f_buf_parse) buf_parse_array;
-    break;
   case TAG_BOOL:
     return (f_buf_parse) buf_parse_bool;
-    break;
   case TAG_CALL:
   case TAG_CALL_FN:
   case TAG_CALL_MACRO:
     return (f_buf_parse) buf_parse_call;
-    break;
   case TAG_CFN:
     return (f_buf_parse) buf_parse_cfn;
-    break;
   case TAG_CHARACTER:
     return (f_buf_parse) buf_parse_character;
-    break;
   case TAG_F32:
     return (f_buf_parse) buf_parse_f32;
-    break;
   case TAG_F64:
     return (f_buf_parse) buf_parse_f64;
-    break;
   case TAG_FN:
     return (f_buf_parse) buf_parse_fn;
-    break;
   case TAG_IDENT:
     return (f_buf_parse) buf_parse_ident;
-    break;
   case TAG_INTEGER:
     return (f_buf_parse) buf_parse_integer;
-    break;
   case TAG_S64:
     return (f_buf_parse) buf_parse_s64;
-    break;
   case TAG_S32:
     return (f_buf_parse) buf_parse_s32;
-    break;
   case TAG_S16:
     return (f_buf_parse) buf_parse_s16;
-    break;
   case TAG_S8:
     return (f_buf_parse) buf_parse_s8;
-    break;
   case TAG_U8:
     return (f_buf_parse) buf_parse_u8;
-    break;
   case TAG_U16:
     return (f_buf_parse) buf_parse_u16;
-    break;
   case TAG_U32:
     return (f_buf_parse) buf_parse_u32;
-    break;
   case TAG_U64:
     return (f_buf_parse) buf_parse_u64;
-    break;
   case TAG_LIST:
     return (f_buf_parse) buf_parse_list;
-    break;
   case TAG_PTAG:
     return (f_buf_parse) buf_parse_ptag;
-    break;
   case TAG_QUOTE:
     return (f_buf_parse) buf_parse_quote;
-    break;
   case TAG_STR:
     return (f_buf_parse) buf_parse_str;
-    break;
   case TAG_SYM:
     return (f_buf_parse) buf_parse_sym;
-    break;
   case TAG_TUPLE:
     return (f_buf_parse) buf_parse_tuple;
-    break;
   case TAG_VAR:
     return (f_buf_parse) buf_parse_var;
-    break;
   }
   assert(! "tag_type_to_buf_parse: invalid tag type");
   err(1, "tag_type_to_buf_parse: invalid tag type");
diff --git a/libc3/tag.h b/libc3/tag.h
index 28644d5..e69f99a 100644
--- a/libc3/tag.h
+++ b/libc3/tag.h
@@ -97,11 +97,12 @@ e_bool        tag_is_number (const s_tag *tag);
 e_bool        tag_is_unbound_var (const s_tag *tag);
 s8            tag_number_compare (const s_tag *a, const s_tag *b);
 sw            tag_size (const s_tag *tag);
-sw            tag_type_size (e_tag_type type);
-f_buf_parse   tag_type_to_buf_parse (e_tag_type type);
 void *        tag_to_ffi_pointer (s_tag *tag, const s_sym *type);
 ffi_type      tag_to_ffi_type(const s_tag *tag);
 void *        tag_to_pointer (s_tag *tag, e_tag_type type);
+sw            tag_type_size (e_tag_type type);
+f_buf_inspect tag_type_to_buf_inspect (e_tag_type type);
+f_buf_parse   tag_type_to_buf_parse (e_tag_type type);
 s8 *          tag_type_to_string (e_tag_type type);
 const s_sym * tag_type_to_sym (e_tag_type tag_type);
 
diff --git a/libc3/types.h b/libc3/types.h
index 1d4a133..2fa5ba1 100644
--- a/libc3/types.h
+++ b/libc3/types.h
@@ -504,4 +504,7 @@ struct facts_with_cursor {
   pthread_mutex_t mutex;
 };
 
+/* Functions */
+typedef sw (* f_buf_inspect) (s_buf *buf, const void *x);
+
 #endif /* TYPES_H */
diff --git a/test/ic3/array.in b/test/ic3/array.in
index b02d0bb..3926d77 100644
--- a/test/ic3/array.in
+++ b/test/ic3/array.in
@@ -1,5 +1,8 @@
 (u8) {0, 1}
-(u8) {{0, 1}, {2, 3}}
+
+(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 81548b8..ebe727d 100644
--- a/test/ic3/array.out.expected
+++ b/test/ic3/array.out.expected
@@ -1,2 +1,3 @@
-(u8) [0, 1]
-(u8) [[0, 1], [2, 3]]
+(u8) {0, 1}
+(u8) {{0, 1}, {2, 3}}
+(u8) {{{0, 1}, {2, 3}}, {{4, 5}, {6, 7}}}