Commit 0bf362fc18a9b49ec44fb6c4f639bc562179bf82

Thomas de Grivel 2023-09-22T16:22:08

u* arrays

diff --git a/lib/c3/0.1/u16.facts b/lib/c3/0.1/u16.facts
new file mode 100644
index 0000000..d39c249
--- /dev/null
+++ b/lib/c3/0.1/u16.facts
@@ -0,0 +1,7 @@
+%{module: C3.Facts.Dump,
+  version: 1}
+add {U16, :is_a, :module}
+add {U16, :symbol, U16.cast}
+add {U16, :symbol, U16.size}
+replace {U16.cast, :cfn, cfn :u16 "u16_cast" (:tag)}
+replace {U16.size, :value, 2}
diff --git a/lib/c3/0.1/u32.facts b/lib/c3/0.1/u32.facts
new file mode 100644
index 0000000..8097e29
--- /dev/null
+++ b/lib/c3/0.1/u32.facts
@@ -0,0 +1,7 @@
+%{module: C3.Facts.Dump,
+  version: 1}
+add {U32, :is_a, :module}
+add {U32, :symbol, U32.cast}
+add {U32, :symbol, U32.size}
+replace {U32.cast, :cfn, cfn :u32 "u32_cast" (:tag)}
+replace {U32.size, :value, 4}
diff --git a/lib/c3/0.1/u64.facts b/lib/c3/0.1/u64.facts
new file mode 100644
index 0000000..350c9d4
--- /dev/null
+++ b/lib/c3/0.1/u64.facts
@@ -0,0 +1,7 @@
+%{module: C3.Facts.Dump,
+  version: 1}
+add {U64, :is_a, :module}
+add {U64, :symbol, U64.cast}
+add {U64, :symbol, U64.size}
+replace {U64.cast, :cfn, cfn :u64 "u64_cast" (:tag)}
+replace {U64.size, :value, 8}
diff --git a/lib/c3/0.1/uw.facts b/lib/c3/0.1/uw.facts
new file mode 100644
index 0000000..1198f79
--- /dev/null
+++ b/lib/c3/0.1/uw.facts
@@ -0,0 +1,7 @@
+%{module: C3.Facts.Dump,
+  version: 1}
+add {Uw, :is_a, :module}
+add {Uw, :symbol, Uw.cast}
+add {Uw, :symbol, Uw.size}
+replace {Uw.cast, :cfn, cfn :uw "uw_cast" (:tag)}
+replace {Uw.size, :value, 8}
diff --git a/libc3/array.c b/libc3/array.c
index e12d7f6..d78c862 100644
--- a/libc3/array.c
+++ b/libc3/array.c
@@ -116,14 +116,16 @@ s_tag * array_data_tag (s_tag *a, const s_tag *address, s_tag *dest)
   sw size;
   assert(a->type == TAG_ARRAY);
   assert(address->type == TAG_ARRAY);
-  a_data = array_data(&a->data.array,
-                      address->data.array.data);
-  tag_init(dest);
-  dest->type = array_type_to_tag_type(a->data.array.type);
-  dest_data = tag_to_pointer(dest, dest->type);
-  size = tag_type_size(dest->type);
-  memcpy(dest_data, a_data, size);
-  return dest;
+  if ((a_data = array_data(&a->data.array,
+                           address->data.array.data))) {
+    tag_init(dest);
+    dest->type = array_type_to_tag_type(a->data.array.type);
+    dest_data = tag_to_pointer(dest, dest->type);
+    size = tag_type_size(dest->type);
+    memcpy(dest_data, a_data, size);
+    return dest;
+  }
+  return NULL;
 }
 
 s_array * array_init (s_array *a, const s_sym *type, uw dimension,