Commit ccd28cb1d6691752d55f8e380e032de76420e331

Thomas de Grivel 2024-01-22T21:35:40

array clean

diff --git a/lib/c3/0.1/gl/object.facts b/lib/c3/0.1/gl/object.facts
index 4c6d92d..2d28088 100644
--- a/lib/c3/0.1/gl/object.facts
+++ b/lib/c3/0.1/gl/object.facts
@@ -1,8 +1,8 @@
 %{module: C3.Facts.Dump,
   version: 1}
 replace {GL.Object, :is_a, :module}
-replace {GL.Object, :defstruct, [vertex: (GL.Vertex) {},
-                                 triangle: (GL.Triangle) {},
+replace {GL.Object, :defstruct, [vertex: (GL.Vertex[]) {},
+                                 triangle: (GL.Triangle[]) {},
                                  gl_mode: (U32) 0,
                                  gl_vao: (U32) 0,
                                  gl_vbo: (U32) 0,
diff --git a/libc3/data.c b/libc3/data.c
index b715187..553f9db 100644
--- a/libc3/data.c
+++ b/libc3/data.c
@@ -15,7 +15,8 @@
 sw data_buf_inspect (const s_sym *type, s_buf *buf, const void *data)
 {
   const s_struct_type *st;
-  if (type == &g_sym_Array)
+  if (type == &g_sym_Array ||
+      sym_is_array_type(type))
     return buf_inspect_array(buf, data);
   if (type == &g_sym_Bool)
     return buf_inspect_bool(buf, data);
@@ -79,9 +80,6 @@ sw data_buf_inspect (const s_sym *type, s_buf *buf, const void *data)
     return buf_inspect_var(buf, data);
   if (type == &g_sym_Void)
     return buf_inspect_void(buf, data);
-  /*
-  if (sym_is_array_type(type)) {
-  */
   st = struct_type_find(type);
   if (st) {
     s_struct s = {0};
@@ -99,7 +97,8 @@ sw data_buf_inspect (const s_sym *type, s_buf *buf, const void *data)
 sw data_buf_inspect_size (const s_sym *type, const void *data)
 {
   const s_struct_type *st;
-  if (type == &g_sym_Array)
+  if (type == &g_sym_Array ||
+      sym_is_array_type(type))
     return buf_inspect_array_size(data);
   if (type == &g_sym_Bool)
     return buf_inspect_bool_size(data);
@@ -163,9 +162,6 @@ sw data_buf_inspect_size (const s_sym *type, const void *data)
     return buf_inspect_var_size(data);
   if (type == &g_sym_Void)
     return buf_inspect_void_size(data);
-  /*
-  if (sym_is_array_type(type)) {
-  */
   st = struct_type_find(type);
   if (st) {
     s_struct s = {0};
@@ -184,7 +180,8 @@ bool data_clean (const s_sym *type, void *data)
 {
   const s_struct_type *st;
   assert(type);
-  if (type == &g_sym_Array) {
+  if (type == &g_sym_Array ||
+      sym_is_array_type(type)) {
     array_clean(data);
     return true;
   }
@@ -295,9 +292,6 @@ bool data_clean (const s_sym *type, void *data)
   if (type == &g_sym_Void) {
     return true;
   }
-  /*
-  if (sym_is_array_type(type)) {
-  */
   st = struct_type_find(type);
   if (st) {
     s_struct s = {0};
@@ -316,7 +310,8 @@ bool data_clean (const s_sym *type, void *data)
 bool data_compare (const s_sym *type, const void *a, const void *b)
 {
   const s_struct_type *st;
-  if (type == &g_sym_Array)
+  if (type == &g_sym_Array ||
+      sym_is_array_type(type))
     return compare_array(a, b);
   if (type == &g_sym_Bool)
     return compare_bool(*(bool *) a, *(bool *) b);
@@ -380,9 +375,6 @@ bool data_compare (const s_sym *type, const void *a, const void *b)
     return compare_ptr(a, b);
   if (type == &g_sym_Void)
     return 0;
-  /*
-  if (sym_is_array_type(type)) {
-  */
   st = struct_type_find(type);
   if (st) {
     s_struct sa = {0};
@@ -403,7 +395,8 @@ bool data_compare (const s_sym *type, const void *a, const void *b)
 bool data_hash_update (const s_sym *type, t_hash *hash, const void *data)
 {
   const s_struct_type *st;
-  if (type == &g_sym_Array)
+  if (type == &g_sym_Array ||
+      sym_is_array_type(type))
     return hash_update_array(hash, data);
   if (type == &g_sym_Bool)
     return hash_update_bool(hash, data);
@@ -467,9 +460,6 @@ bool data_hash_update (const s_sym *type, t_hash *hash, const void *data)
     return hash_update_var(hash, data);
   if (type == &g_sym_Void)
     return hash_update_void(hash, data);
-  /*
-  if (sym_is_array_type(type)) {
-  */
   st = struct_type_find(type);
   if (st) {
     s_struct s = {0};
@@ -487,7 +477,8 @@ bool data_hash_update (const s_sym *type, t_hash *hash, const void *data)
 void * data_init_cast (const s_sym *type, void *data, const s_tag *tag)
 {
   const s_struct_type *st;
-  if (type == &g_sym_Array)
+  if (type == &g_sym_Array ||
+      sym_is_array_type(type))
     return array_init_cast(data, tag);
   if (type == &g_sym_Bool)
     return bool_init_cast(data, tag);
@@ -571,7 +562,8 @@ void * data_init_cast (const s_sym *type, void *data, const s_tag *tag)
 void * data_init_copy (const s_sym *type, void *data, const void *src)
 {
   const s_struct_type *st;
-  if (type == &g_sym_Array)
+  if (type == &g_sym_Array ||
+      sym_is_array_type(type))
     return array_init_copy(data, src);
   if (type == &g_sym_Bool)
     return bool_init_copy(data, src);
diff --git a/libc3/sym.c b/libc3/sym.c
index 717e2f8..efedb03 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -571,7 +571,8 @@ bool sym_to_ffi_type (const s_sym *sym, ffi_type *result_type,
     *dest = result_type;
     return true;
   }
-  if (sym == &g_sym_Array) {
+  if (sym == &g_sym_Array ||
+      sym_is_array_type(sym)) {
     *dest = &ffi_type_pointer;
     return true;
   }
@@ -692,7 +693,8 @@ bool sym_to_ffi_type (const s_sym *sym, ffi_type *result_type,
 
 bool sym_to_tag_type (const s_sym *sym, e_tag_type *dest)
 {
-  if (sym == &g_sym_Array) {
+  if (sym == &g_sym_Array ||
+      sym_is_array_type(sym)) {
     *dest = TAG_ARRAY;
     return true;
   }
@@ -838,7 +840,8 @@ bool sym_to_tag_type (const s_sym *sym, e_tag_type *dest)
 bool sym_type_size (const s_sym *type, uw *dest)
 {
   const s_struct_type *st;
-  if (type == &g_sym_Array) {
+  if (type == &g_sym_Array ||
+      sym_is_array_type(type)) {
     *dest = sizeof(s_array);
     return true;
   }
diff --git a/libc3/window/cairo/demo/flies.c b/libc3/window/cairo/demo/flies.c
index bb32f73..9f9790c 100644
--- a/libc3/window/cairo/demo/flies.c
+++ b/libc3/window/cairo/demo/flies.c
@@ -61,7 +61,7 @@ bool flies_load (s_sequence *seq)
   tag_map(&seq->tag, 4);
   map = &seq->tag.data.map;
   tag_init_sym( map->key  + 0, sym_1("board"));
-  tag_init_array(map->value + 0, sym_1("U8"),
+  tag_init_array(map->value + 0, sym_1("U8[]"),
                  2, (uw[]) {BOARD_SIZE, BOARD_SIZE});
   tag_init_sym(map->key + 1, sym_1("in"));
   tag_init_uw( map->value + 1, 0);
diff --git a/libc3/window/cairo/demo/mandelbrot_f128.c b/libc3/window/cairo/demo/mandelbrot_f128.c
index 0ec4c5a..7d217a0 100644
--- a/libc3/window/cairo/demo/mandelbrot_f128.c
+++ b/libc3/window/cairo/demo/mandelbrot_f128.c
@@ -73,7 +73,7 @@ bool mandelbrot_f128_load (s_sequence *seq)
   tag_init_sym(    map->key + 3, sym_1("next_z"));
   tag_init_f128( map->value + 3, 0.01);
   tag_init_sym(    map->key + 4, sym_1("pixels"));
-  tag_init_array(map->value + 4, sym_1("U8"), 0, NULL);
+  tag_init_array(map->value + 4, sym_1("U8[]"), 0, NULL);
   tag_init_sym(    map->key + 5, sym_1("w"));
   tag_init_uw(   map->value + 5, 0);
   tag_init_sym(    map->key + 6, sym_1("x"));
diff --git a/libc3/window/sdl2/demo/flies.c b/libc3/window/sdl2/demo/flies.c
index 14a1a0f..e115b53 100644
--- a/libc3/window/sdl2/demo/flies.c
+++ b/libc3/window/sdl2/demo/flies.c
@@ -66,7 +66,7 @@ bool flies_load (s_sequence *seq)
   tag_map(&seq->tag, 4);
   map = &seq->tag.data.map;
   tag_init_sym(   map->key  + 0, sym_1("board"));
-  tag_init_array(map->value + 0, sym_1("U8"),
+  tag_init_array(map->value + 0, sym_1("U8[]"),
                  2, (uw[]) {BOARD_SIZE, BOARD_SIZE});
   tag_init_sym(    map->key + 1, sym_1("in"));
   tag_init_uw(   map->value + 1, 0);
diff --git a/libc3/window/sdl2/demo/mandelbrot_f128.c b/libc3/window/sdl2/demo/mandelbrot_f128.c
index 9a160b8..af6857e 100644
--- a/libc3/window/sdl2/demo/mandelbrot_f128.c
+++ b/libc3/window/sdl2/demo/mandelbrot_f128.c
@@ -40,7 +40,7 @@ bool mandelbrot_f128_load (s_sequence *seq)
   tag_init_sym(    map->key + 3, sym_1("next_z"));
   tag_init_f128( map->value + 3, 0.01);
   tag_init_sym(    map->key + 4, sym_1("pixels"));
-  tag_init_array(map->value + 4, sym_1("U8"), 0, NULL);
+  tag_init_array(map->value + 4, sym_1("U8[]"), 0, NULL);
   tag_init_sym(    map->key + 5, sym_1("w"));
   tag_init_uw(   map->value + 5, 0);
   tag_init_sym(    map->key + 6, sym_1("x"));
@@ -141,7 +141,7 @@ static bool mandelbrot_f128_resize (s_sequence *seq)
   dim[0] = win->h;
   dim[1] = win->w;
   dim[2] = 4;
-  if (! array_init(pixels, &g_sym_U8, 3, dim))
+  if (! array_init(pixels, sym_1("U8[]"), 3, dim))
     return false;
   if (! array_allocate(pixels))
     return false;
diff --git a/libc3/window/sdl2/gl_lines.c b/libc3/window/sdl2/gl_lines.c
index e1cadfb..c05066c 100644
--- a/libc3/window/sdl2/gl_lines.c
+++ b/libc3/window/sdl2/gl_lines.c
@@ -20,7 +20,7 @@ s_gl_lines * gl_lines_allocate (s_gl_lines *lines, uw lines_count)
   assert(lines);
   assert(lines_count);
   vertex_count = lines_count * 2;
-  if (! array_init(&lines->vertex, sym_1("GL.Vertex"), 1,
+  if (! array_init(&lines->vertex, sym_1("GL.Vertex[]"), 1,
                    &vertex_count) ||
       ! array_allocate(&lines->vertex))
     return NULL;
diff --git a/libc3/window/sdl2/gl_object.c b/libc3/window/sdl2/gl_object.c
index fa0215e..8c4ec28 100644
--- a/libc3/window/sdl2/gl_object.c
+++ b/libc3/window/sdl2/gl_object.c
@@ -21,10 +21,10 @@ s_gl_object * gl_object_allocate (s_gl_object *object, uw vertex_count,
   assert(object);
   assert(vertex_count);
   assert(triangle_count);
-  if (! array_init(&object->vertex, sym_1("GL.Vertex"), 1,
+  if (! array_init(&object->vertex, sym_1("GL.Vertex[]"), 1,
                    &vertex_count) ||
       ! array_allocate(&object->vertex) ||
-      ! array_init(&object->triangle, sym_1("GL.Triangle"), 1,
+      ! array_init(&object->triangle, sym_1("GL.Triangle[]"), 1,
                    &triangle_count) ||
       ! array_allocate(&object->triangle))
     return NULL;