Commit 25015bd814af907cfdf5e146b24ce468f5419e75

Thomas de Grivel 2024-01-22T22:04:38

fix arrays

diff --git a/libc3/list.c b/libc3/list.c
index da452d2..d66a86c 100644
--- a/libc3/list.c
+++ b/libc3/list.c
@@ -264,15 +264,15 @@ s_array * list_to_array (const s_list *list, const s_sym *array_type,
   assert(array_type);
   assert(dest);
   len = list_length(list);
-  if (! sym_type_size(array_type, &size))
+  tmp.array_type = array_type;
+  tmp.element_type = sym_array_type(array_type);
+  if (! sym_type_size(tmp.element_type, &size))
     return NULL;
   if (! size) {
     err_puts("list_to_array: zero item size");
     assert(! "list_to_array: zero item size");
     return NULL;
   }
-  tmp.array_type = array_type;
-  tmp.element_type = sym_array_type(array_type);
   if (len) {
     tmp.dimension = 1;
     tmp.dimensions = calloc(1, sizeof(s_array_dimension));
diff --git a/test/ic3/array.in b/test/ic3/array.in
index ff0d302..3efa26d 100644
--- a/test/ic3/array.in
+++ b/test/ic3/array.in
@@ -1,12 +1,12 @@
-(U8) {0, 1}
-a = (U8) {0, 1}
+(U8[]) {0, 1}
+a = (U8[]) {0, 1}
 quote a[0]
 quote a[1]
 a[0]
 a[1]
-(U8) {{0, 1},
+(U8[]) {{0, 1},
       {2, 3}}
-b = (U8) {{0, 1},
+b = (U8[]) {{0, 1},
           {2, 3}}
 quote b[0][0]
 quote b[0][1]
@@ -16,7 +16,7 @@ b[0][0]
 b[0][1]
 b[1][0]
 b[1][1]
-c = (U8) {{{0, 1},
+c = (U8[]) {{{0, 1},
            {2, 3}},
           {{4, 5},
            {6, 7}}}
@@ -36,7 +36,7 @@ c[1][0][0]
 c[1][0][1]
 c[1][1][0]
 c[1][1][1]
-d = (U8) {{{{0, 1},
+d = (U8[]) {{{{0, 1},
             {2, 3}},
            {{4, 5},
             {6, 7}}},
@@ -76,41 +76,41 @@ d[1][1][0][0]
 d[1][1][0][1]
 d[1][1][1][0]
 d[1][1][1][1]
-e = (U8) { 1 + 1 }
+e = (U8[]) { 1 + 1 }
 e[0]
-f = (U8) { 1 + 1, 2 + 2 }
+f = (U8[]) { 1 + 1, 2 + 2 }
 f[0]
 f[1]
-g = (U8) { 1 + 1, 2 + 2, 3 + 3 }
+g = (U8[]) { 1 + 1, 2 + 2, 3 + 3 }
 g[0]
 g[1]
 g[2]
-h = (U8) { 255 + 1, 255 + 2, 255 + 3 }
+h = (U8[]) { 255 + 1, 255 + 2, 255 + 3 }
 h[0]
 h[1]
 h[2]
-i = (U16) { 255 + 1, 255 + 2, 255 + 3 }
+i = (U16[]) { 255 + 1, 255 + 2, 255 + 3 }
 i[0]
 i[1]
 i[2]
-j = (U32) { 255 + 1, 255 + 2, 255 + 3 }
+j = (U32[]) { 255 + 1, 255 + 2, 255 + 3 }
 j[0]
 j[1]
 j[2]
-k = (U64) { 255 + 1, 255 + 2, 255 + 3 }
+k = (U64[]) { 255 + 1, 255 + 2, 255 + 3 }
 k[0]
 k[1]
 k[2]
-quote (Integer) { 1000000000000000000000000000000001,
+quote (Integer[]) { 1000000000000000000000000000000001,
                   2000000000000000000000000000000002 }
-l = (Integer) { 1000000000000000000000000000000001,
+l = (Integer[]) { 1000000000000000000000000000000001,
                 2000000000000000000000000000000002 }
 l[0]
 l[1]
-quote (List) {[1, 2], [3, 4]}
-(List) {[1, 2], [3, 4]}
-m = (List) {[1, 2], [3, 4]}
+quote (List[]) {[1, 2], [3, 4]}
+(List[]) {[1, 2], [3, 4]}
+m = (List[]) {[1, 2], [3, 4]}
 m[0]
 m[1]
-quote (GL.Vertex) {}
-(GL.Vertex) {}
+quote (GL.Vertex[]) {}
+(GL.Vertex[]) {}
diff --git a/test/ic3/array.out.expected b/test/ic3/array.out.expected
index 738e88a..ae144e5 100644
--- a/test/ic3/array.out.expected
+++ b/test/ic3/array.out.expected
@@ -1,11 +1,11 @@
-(U8) {0, 1}
-(U8) {0, 1}
+(U8[]) {0, 1}
+(U8[]) {0, 1}
 a[0]
 a[1]
 0
 1
-(U8) {{0, 1}, {2, 3}}
-(U8) {{0, 1}, {2, 3}}
+(U8[]) {{0, 1}, {2, 3}}
+(U8[]) {{0, 1}, {2, 3}}
 b[0][0]
 b[0][1]
 b[1][0]
@@ -14,7 +14,7 @@ b[1][1]
 1
 2
 3
-(U8) {{{0, 1}, {2, 3}}, {{4, 5}, {6, 7}}}
+(U8[]) {{{0, 1}, {2, 3}}, {{4, 5}, {6, 7}}}
 c[0][0][0]
 c[0][0][1]
 c[0][1][0]
@@ -31,7 +31,7 @@ c[1][1][1]
 5
 6
 7
-(U8) {{{{0, 1}, {2, 3}}, {{4, 5}, {6, 7}}}, {{{8, 9}, {10, 11}}, {{12, 13}, {14, 15}}}}
+(U8[]) {{{{0, 1}, {2, 3}}, {{4, 5}, {6, 7}}}, {{{8, 9}, {10, 11}}, {{12, 13}, {14, 15}}}}
 d[0][0][0][0]
 d[0][0][0][1]
 d[0][0][1][0]
@@ -64,39 +64,39 @@ d[1][1][1][1]
 13
 14
 15
-(U8) {2}
+(U8[]) {2}
 2
-(U8) {2, 4}
+(U8[]) {2, 4}
 2
 4
-(U8) {2, 4, 6}
+(U8[]) {2, 4, 6}
 2
 4
 6
-(U8) {0, 1, 2}
+(U8[]) {0, 1, 2}
 0
 1
 2
-(U16) {256, 257, 258}
+(U16[]) {256, 257, 258}
 256
 257
 258
-(U32) {256, 257, 258}
+(U32[]) {256, 257, 258}
 256
 257
 258
-(U64) {256, 257, 258}
+(U64[]) {256, 257, 258}
 256
 257
 258
-(Integer) {1000000000000000000000000000000001, 2000000000000000000000000000000002}
-(Integer) {1000000000000000000000000000000001, 2000000000000000000000000000000002}
+(Integer[]) {1000000000000000000000000000000001, 2000000000000000000000000000000002}
+(Integer[]) {1000000000000000000000000000000001, 2000000000000000000000000000000002}
 1000000000000000000000000000000001
 2000000000000000000000000000000002
-(List) {[1, 2], [3, 4]}
-(List) {[1, 2], [3, 4]}
-(List) {[1, 2], [3, 4]}
+(List[]) {[1, 2], [3, 4]}
+(List[]) {[1, 2], [3, 4]}
+(List[]) {[1, 2], [3, 4]}
 [1, 2]
 [3, 4]
-(GL.Vertex) {}
-(GL.Vertex) {}
+(GL.Vertex[]) {}
+(GL.Vertex[]) {}