Commit 0add2f6ef1b839ae03bc70429440f36a19f13d86

Thomas de Grivel 2024-01-20T11:22:55

wip sym_array_type

diff --git a/libc3/sym.c b/libc3/sym.c
index c4f0a66..90d068d 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -312,6 +312,127 @@ s_sym_list * sym_list_new (const s_sym *sym, s_sym *free_sym,
   return sym_list;
 }
 
+bool sym_must_clean (const s_sym *sym, bool *must_clean)
+{
+  if (sym_is_array_type(sym)) {
+    *must_clean = sym_must_clean(sym_array_type(sym));
+    return true;
+  }
+  if (sym == &g_sym_Bool) {
+    *must_clean = false;
+    return true;
+  }
+  if (sym == &g_sym_Character) {
+    *must_clean = false;
+    return true;
+  }
+  if (sym == &g_sym_F32) {
+    *must_clean = false;
+    return true;
+  }
+  if (sym == &g_sym_F64) {
+    *must_clean = false;
+    return true;
+  }
+  if (sym == &g_sym_F128) {
+    *must_clean = false;
+    return true;
+  }
+  if (sym == &g_sym_Fn) {
+    *must_clean = true;
+    return true;
+  }
+  if (sym == &g_sym_Integer) {
+    *must_clean = true;
+    return true;
+  }
+  if (sym == &g_sym_List) {
+    *must_clean = true;
+    return true;
+  }
+  if (sym == &g_sym_Map) {
+    *must_clean = true;
+    return true;
+  }
+  if (sym == &g_sym_Ptr) {
+    *must_clean = true;
+    return true;
+  }
+  if (sym == &g_sym_PtrFree) {
+    *must_clean = true;
+    return true;
+  }
+  if (sym == &g_sym_S8) {
+    *must_clean = false;
+    return true;
+  }
+  if (sym == &g_sym_S16) {
+    *must_clean = false;
+    return true;
+  }
+  if (sym == &g_sym_S32) {
+    *must_clean = false;
+    return true;
+  }
+  if (sym == &g_sym_S64) {
+    *must_clean = false;
+    return true;
+  }
+  if (sym == &g_sym_Str) {
+    *must_clean = true;
+    return true;
+  }
+  if (sym == &g_sym_Struct) {
+    *must_clean = true;
+    return true;
+  }
+  if (sym == &g_sym_Sym) {
+    *must_clean = true;
+    return true;
+  }
+  if (sym == &g_sym_Sw) {
+    *must_clean = false;
+    return true;
+  }
+  if (sym == &g_sym_Tag) {
+    *must_clean = true;
+    return true;
+  }
+  if (sym == &g_sym_U8) {
+    *must_clean = false;
+    return true;
+  }
+  if (sym == &g_sym_U16) {
+    *must_clean = false;
+    return true;
+  }
+  if (sym == &g_sym_U32) {
+    *must_clean = false;
+    return true;
+  }
+  if (sym == &g_sym_U64) {
+    *must_clean = false;
+    return true;
+  }
+  if (sym == &g_sym_Uw) {
+    *must_clean = false;
+    return true;
+  }
+  if (sym == &g_sym_Void) {
+    *must_clean = false;
+    return true;
+  }
+  if (struct_type_exists(sym)) {
+    *must_clean = struct_type_must_clean(sym);
+    return true;
+  }
+  err_write_1("sym_must_clean: unknown type: ");
+  err_inspect_sym(&sym);
+  err_write_1("\n");
+  assert(! "sym_must_clean: unknown type");
+  return false;
+}
+
 const s_sym * sym_new (const s_str *src)
 {
   s_sym *sym;
diff --git a/libc3/sym.h b/libc3/sym.h
index dae91bc..187721b 100644
--- a/libc3/sym.h
+++ b/libc3/sym.h
@@ -93,10 +93,12 @@ void          sym_delete_all (void);
 const s_sym * sym_new (const s_str *src);
 
 /* Observers */
+bool          sym_array_type (const s_sym *sym, s_sym *dest);
 bool          sym_character_is_reserved (character c);
 const s_sym * sym_find (const s_str *src);
 bool          sym_has_reserved_characters (const s_sym *sym);
 s_str *       sym_inspect (const s_sym *sym, s_str *dest);
+bool          sym_is_array_type (const s_sym *sym);
 bool          sym_is_module (const s_sym *sym);
 bool          sym_to_ffi_type (const s_sym *sym, ffi_type *result_type,
                                ffi_type **dest);
diff --git a/libc3/tag.c b/libc3/tag.c
index 494ced7..14dfd0d 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -520,128 +520,6 @@ bool * tag_lte (const s_tag *a, const s_tag *b, bool *dest)
   return dest;
 }
 
-bool sym_must_clean (const s_sym *sym, bool *must_clean)
-{
-  if (sym_is_array_type(sym)) {
-    *must_clean = sym_must_clean(sym_array_type(sym));
-    return true;
-  }
-  if (sym == &g_sym_Bool) {
-    *must_clean = false;
-    return true;
-  }
-  if (sym == &g_sym_Character) {
-    *must_clean = false;
-    return true;
-  }
-  if (sym == &g_sym_F32) {
-    *must_clean = false;
-    return true;
-  }
-  if (sym == &g_sym_F64) {
-    *must_clean = false;
-    return true;
-  }
-  if (sym == &g_sym_F128) {
-    *must_clean = false;
-    return true;
-  }
-  if (sym == &g_sym_Fn) {
-    *must_clean = true;
-    return true;
-  }
-  if (sym == &g_sym_Integer) {
-    *must_clean = true;
-    return true;
-  }
-  if (sym == &g_sym_List) {
-    *must_clean = true;
-    return true;
-  }
-  if (sym == &g_sym_Map) {
-    *must_clean = true;
-    return true;
-  }
-  if (sym == &g_sym_Ptr) {
-    *must_clean = true;
-    return true;
-  }
-  if (sym == &g_sym_PtrFree) {
-    *must_clean = true;
-    return true;
-  }
-  if (sym == &g_sym_S8) {
-    *must_clean = false;
-    return true;
-  }
-  if (sym == &g_sym_S16) {
-    *must_clean = false;
-    return true;
-  }
-  if (sym == &g_sym_S32) {
-    *must_clean = false;
-    return true;
-  }
-  if (sym == &g_sym_S64) {
-    *must_clean = false;
-    return true;
-  }
-  if (sym == &g_sym_Str) {
-    *must_clean = true;
-    return true;
-  }
-  if (sym == &g_sym_Struct) {
-    *must_clean = true;
-    return true;
-  }
-  if (sym == &g_sym_Sym) {
-    *must_clean = true;
-    return true;
-  }
-  if (sym == &g_sym_Sw) {
-    *must_clean = false;
-    return true;
-  }
-  if (sym == &g_sym_Tag) {
-    *must_clean = true;
-    return true;
-  }
-  if (sym == &g_sym_U8) {
-    *must_clean = false;
-    return true;
-  }
-  if (sym == &g_sym_U16) {
-    *must_clean = false;
-    return true;
-  }
-  if (sym == &g_sym_U32) {
-    *must_clean = false;
-    return true;
-  }
-  if (sym == &g_sym_U64) {
-    *must_clean = false;
-    return true;
-  }
-  if (sym == &g_sym_Uw) {
-    *must_clean = false;
-    return true;
-  }
-  if (sym == &g_sym_Void) {
-    *must_clean = false;
-    return true;
-  }
-  if (struct_type_exists(sym)) {
-    *must_clean = struct_type_must_clean(sym);
-    return true;
-  }
-  err_write_1("sym_to_ffi_type: unknown type: ");
-  err_inspect_sym(&sym);
-  err_write_1("\n");
-  assert(! "sym_to_ffi_type: unknown type");
-  return false;
-}
-
-
 s_tag * tag_neg (const s_tag *tag, s_tag *result)
 {
   s_integer tmp;