Commit 73e0d62901a2030d62dd93cff1549d9317331c52

Thomas de Grivel 2024-03-05T11:40:31

wip complex

diff --git a/libc3/sym.c b/libc3/sym.c
index a2424fb..a2fd14d 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -32,6 +32,7 @@ const s_sym g_sym_Call            = {{{NULL},  4, {"Call"}}};
 const s_sym g_sym_Cfn             = {{{NULL},  3, {"Cfn"}}};
 const s_sym g_sym_Character       = {{{NULL},  9, {"Character"}}};
 const s_sym g_sym_Char__star      = {{{NULL},  5, {"Char*"}}};
+const s_sym g_sym_Complex         = {{{NULL},  7, {"Complex"}}};
 const s_sym g_sym_F32             = {{{NULL},  3, {"F32"}}};
 const s_sym g_sym_F64             = {{{NULL},  3, {"F64"}}};
 const s_sym g_sym_F128            = {{{NULL},  3, {"F128"}}};
@@ -275,6 +276,7 @@ void sym_init_g_sym (void)
   sym_intern(&g_sym_Cfn, NULL);
   sym_intern(&g_sym_Character, NULL);
   sym_intern(&g_sym_Char__star, NULL);
+  sym_intern(&g_sym_Complex, NULL);
   sym_intern(&g_sym_F32, NULL);
   sym_intern(&g_sym_F64, NULL);
   sym_intern(&g_sym_F128, NULL);
diff --git a/libc3/sym.h b/libc3/sym.h
index 767f4fa..15bd1c6 100644
--- a/libc3/sym.h
+++ b/libc3/sym.h
@@ -37,6 +37,7 @@ extern const s_sym g_sym_Call;
 extern const s_sym g_sym_Cfn;
 extern const s_sym g_sym_Character;
 extern const s_sym g_sym_Char__star;
+extern const s_sym g_sym_Complex;
 extern const s_sym g_sym_F32;
 extern const s_sym g_sym_F64;
 extern const s_sym g_sym_F128;
diff --git a/libc3/tag.c b/libc3/tag.c
index 65eaadd..2dbd76c 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -700,6 +700,7 @@ bool tag_to_const_pointer (const s_tag *tag, const s_sym *type,
   case TAG_CALL:        *dest = &tag->data.call;        return true;
   case TAG_CFN:         *dest = &tag->data.cfn;         return true;
   case TAG_CHARACTER:   *dest = &tag->data.character;   return true;
+  case TAG_COMPLEX:     *dest = tag->data.complex;      return true;
   case TAG_F32:         *dest = &tag->data.f32;         return true;
   case TAG_F64:         *dest = &tag->data.f64;         return true;
   case TAG_F128:        *dest = &tag->data.f128;        return true;
@@ -788,6 +789,12 @@ bool tag_to_ffi_pointer (s_tag *tag, const s_sym *type, void **dest)
       return true;
     }
     goto invalid_cast;
+  case TAG_COMPLEX:
+    if (type == &g_sym_Complex) {
+      *dest = tag->data.complex;
+      return true;
+    }
+    goto invalid_cast;
   case TAG_F32:
     if (type == &g_sym_F32) {
       *dest = &tag->data.f32;
@@ -1024,6 +1031,7 @@ bool tag_to_pointer (s_tag *tag, const s_sym *type, void **dest)
   case TAG_CALL:        *dest = &tag->data.call;        return true;
   case TAG_CFN:         *dest = &tag->data.cfn;         return true;
   case TAG_CHARACTER:   *dest = &tag->data.character;   return true;
+  case TAG_COMPLEX:     *dest =  tag->data.complex;     return true;
   case TAG_F32:         *dest = &tag->data.f32;         return true;
   case TAG_F64:         *dest = &tag->data.f64;         return true;
   case TAG_F128:        *dest = &tag->data.f128;        return true;
@@ -1075,6 +1083,7 @@ const s_sym ** tag_type (const s_tag *tag, const s_sym **dest)
   case TAG_CALL:        *dest = &g_sym_Call;       return dest;
   case TAG_CFN:         *dest = &g_sym_Cfn;        return dest;
   case TAG_CHARACTER:   *dest = &g_sym_Character;  return dest;
+  case TAG_COMPLEX:     *dest = &g_sym_Complex;    return dest;
   case TAG_F32:         *dest = &g_sym_F32;        return dest;
   case TAG_F64:         *dest = &g_sym_F64;        return dest;
   case TAG_F128:        *dest = &g_sym_F128;       return dest;
diff --git a/libc3/tag_type.c b/libc3/tag_type.c
index 392a2eb..dae77d0 100644
--- a/libc3/tag_type.c
+++ b/libc3/tag_type.c
@@ -27,6 +27,7 @@ bool tag_type_size (e_tag_type type, uw *dest)
   case TAG_CALL:        *dest = sizeof(s_call);        return true;
   case TAG_CFN:         *dest = sizeof(s_cfn);         return true;
   case TAG_CHARACTER:   *dest = sizeof(character);     return true;
+  case TAG_COMPLEX:     *dest = sizeof(s_complex *);   return true;
   case TAG_F32:         *dest = sizeof(f32);           return true;
   case TAG_F64:         *dest = sizeof(f64);           return true;
   case TAG_F128:        *dest = sizeof(f128);          return true;
@@ -73,6 +74,7 @@ bool tag_type_to_ffi_type (e_tag_type type, ffi_type **dest)
   case TAG_CALL:        *dest = &ffi_type_pointer;    return true;
   case TAG_CFN:         *dest = &ffi_type_pointer;    return true;
   case TAG_CHARACTER:   *dest = &ffi_type_uint32;     return true;
+  case TAG_COMPLEX:     *dest = &ffi_type_pointer;    return true;
   case TAG_F32:         *dest = &ffi_type_float;      return true;
   case TAG_F64:         *dest = &ffi_type_double;     return true;
   case TAG_F128:        *dest = &ffi_type_longdouble; return true;
@@ -121,6 +123,7 @@ const char * tag_type_to_string (e_tag_type tag_type)
   case TAG_CALL:        return "Call";
   case TAG_CFN:         return "Cfn";
   case TAG_CHARACTER:   return "Character";
+  case TAG_COMPLEX:     return "Complex";
   case TAG_F32:         return "F32";
   case TAG_F64:         return "F64";
   case TAG_F128:        return "F128";