Commit 14ab6c357d9f254d111efd8045d81f010deec609

Thomas de Grivel 2024-03-07T15:08:19

wip ic3> (Complex) 0

diff --git a/lib/c3/0.1/complex.facts b/lib/c3/0.1/complex.facts
index 5c40dec..613354c 100644
--- a/lib/c3/0.1/complex.facts
+++ b/lib/c3/0.1/complex.facts
@@ -2,4 +2,4 @@
   version: 1}
 replace {Complex, :is_a, :module}
 replace {Complex, :symbol, Complex.cast}
-replace {Complex.cast, :cfn, cfn Complex "complex_init_cast" (Result, Tag)}
+replace {Complex.cast, :cfn, cfn Complex "complex_new_cast" (Tag)}
diff --git a/libc3/complex.c b/libc3/complex.c
index 5ccb6aa..9555196 100644
--- a/libc3/complex.c
+++ b/libc3/complex.c
@@ -232,6 +232,20 @@ s_complex * complex_new_add (const s_complex *a, const s_complex *b)
   return c;
 }
 
+s_complex * complex_new_cast (const s_tag *src)
+{
+  s_complex *c;
+  assert(src);
+  c = alloc(sizeof(s_complex));
+  if (! c)
+    return NULL;
+  if (! complex_init_cast(c, src)) {
+    free(c);
+    return NULL;
+  }
+  return c;
+}
+
 s_complex * complex_new_div (const s_complex *a, const s_complex *b)
 {
   s_complex *c;
diff --git a/libc3/sym.c b/libc3/sym.c
index eeb81d9..8837f9e 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -459,6 +459,10 @@ bool sym_must_clean (const s_sym *sym, bool *must_clean)
     *must_clean = false;
     return true;
   }
+  if (sym == &g_sym_Complex) {
+    *must_clean = true;
+    return true;
+  }
   if (sym == &g_sym_F32) {
     *must_clean = false;
     return true;
@@ -621,6 +625,10 @@ bool sym_to_ffi_type (const s_sym *sym, ffi_type *result_type,
     *dest = &ffi_type_uint32;
     return true;
   }
+  if (sym == &g_sym_Complex) {
+    *dest = &ffi_type_pointer;
+    return true;
+  }
   if (sym == &g_sym_F32) {
     *dest = &ffi_type_float;
     return true;
@@ -751,6 +759,10 @@ bool sym_to_tag_type (const s_sym *sym, e_tag_type *dest)
     *dest = TAG_CHARACTER;
     return true;
   }
+  if (sym == &g_sym_Complex) {
+    *dest = TAG_COMPLEX;
+    return true;
+  }
   if (sym == &g_sym_F32) {
     *dest = TAG_F32;
     return true;
@@ -898,6 +910,10 @@ bool sym_type_size (const s_sym *type, uw *dest)
     *dest = sizeof(character);
     return true;
   }
+  if (type == &g_sym_Complex) {
+    *dest = sizeof(s_complex);
+    return true;
+  }
   if (type == &g_sym_F32) {
     *dest = sizeof(f32);
     return true;