Commit 6e1774abe1850a65086f0895b7d0bd9969db0e92

Thomas de Grivel 2024-08-31T08:47:08

wip env_eval_struct

diff --git a/Makefile b/Makefile
index 887a37f..5237633 100644
--- a/Makefile
+++ b/Makefile
@@ -534,7 +534,17 @@ lldb_ikc3:
 	${MAKE} -C ikc3 lldb_ikc3
 
 lldb_test:
-	${MAKE} debug
+	${MAKE} -C libtommath debug
+	${MAKE} -C ucd2c
+	${MAKE} -C libkc3 debug
+	${MAKE} -C ikc3 debug
+	${MAKE} -C kc3s debug
+	${MAKE} -C ekc3 debug
+	${MAKE} -C event debug
+	${MAKE} -C json debug
+	${MAKE} -C socket debug
+	${MAKE} -C http debug
+	${MAKE} -C httpd debug
 	${MAKE} -C test lldb_test
 
 test:
diff --git a/libkc3/configure b/libkc3/configure
index 56c638d..ecf24df 100755
--- a/libkc3/configure
+++ b/libkc3/configure
@@ -73,7 +73,7 @@ LDFLAGS_COV="$LDFLAGS --coverage"
 LIBS_COV="$LIBS -lgcov"
 
 # Debug config
-CFLAGS_DEBUG="$CFLAGS -DDEBUG -O1 -g"
+CFLAGS_DEBUG="$CFLAGS -DDEBUG -O2 -g"
 LDFLAGS_DEBUG="$LDFLAGS"
 LIBS_DEBUG="$LIBS"
 
diff --git a/libkc3/env.c b/libkc3/env.c
index 312ca2b..fc69143 100644
--- a/libkc3/env.c
+++ b/libkc3/env.c
@@ -1768,6 +1768,7 @@ bool env_eval_struct (s_env *env, const s_struct *s, s_struct *dest)
   uw i;
   s_tag tag = {0};
   s_struct tmp = {0};
+  void    *tmp_data = NULL;
   const s_sym *type;
   s_var *var = NULL;
   assert(env);
@@ -1802,13 +1803,13 @@ bool env_eval_struct (s_env *env, const s_struct *s, s_struct *dest)
       if (! tag_to_const_pointer(tmp.type->map.value + i, type, &data))
         goto ko;
     }
-    if (false) {
+    if (true) {
       err_write_1("env_eval_struct: type = ");
       err_inspect_sym(&type);
       err_write_1("\n");
     }
-    if (! data_init_copy(type, (s8 *) tmp.data + tmp.type->offset[i],
-                         data))
+    tmp_data = (s8 *) tmp.data + tmp.type->offset[i];
+    if (! data_init_copy(type, tmp_data, data))
       goto ko_init;
     if (s->tag)
       tag_clean(&tag);
diff --git a/libkc3/tag.c b/libkc3/tag.c
index 73a42dd..e604026 100644
--- a/libkc3/tag.c
+++ b/libkc3/tag.c
@@ -340,6 +340,55 @@ s_tag * tag_init_call_cast (s_tag *tag, const s_sym *type)
   return tag;
 }
 
+s_tag * tag_init_cast (s_tag *tag, const s_sym * const *type,
+                       s_tag *src)
+{
+  assert(tag);
+  assert(type);
+  assert(*type);
+  assert(src);
+  switch (src->type) {
+  case TAG_PTR:
+    if (*type != &g_sym_Tag)
+      break;
+    return tag_init_copy(tag, src->data.ptr.p);
+  default:
+    break;
+  }
+  err_puts("tag_init_cast: invalid cast");
+  assert(! "tag_init_cast: invalid cast");
+  return NULL;
+}
+
+s_tag * tag_init_cast_struct (s_tag *tag, const s_sym * const *type,
+                              s_tag *src)
+{
+  assert(tag);
+  assert(type);
+  assert(*type);
+  assert(src);
+  switch (src->type) {
+  case TAG_PTR:
+    if (! src->data.ptr.p)
+      return tag_init_void(tag);
+    return tag_init_struct_with_data(tag, *type, src->data.ptr.p,
+                                     false);
+  case TAG_PTR_FREE:
+    if (! src->data.ptr_free.p)
+      return tag_init_void(tag);
+    return tag_init_struct_with_data(tag, *type, src->data.ptr_free.p,
+                                     false);
+  case TAG_STRUCT:
+    if (*type == src->data.struct_.type->module)
+      return tag_init_struct_copy(tag, &src->data.struct_);
+  default:
+    break;
+  }
+  err_puts("tag_init_cast_struct: invalid cast");
+  assert(! "tag_init_cast_struct: invalid cast");
+  return NULL;
+}
+
 s_tag * tag_init_copy (s_tag *tag, const s_tag *src)
 {
   assert(tag);
@@ -537,55 +586,6 @@ s_tag * tag_init_copy (s_tag *tag, const s_tag *src)
   return NULL;
 }
 
-s_tag * tag_init_cast (s_tag *tag, const s_sym * const *type,
-                       s_tag *src)
-{
-  assert(tag);
-  assert(type);
-  assert(*type);
-  assert(src);
-  switch (src->type) {
-  case TAG_PTR:
-    if (*type != &g_sym_Tag)
-      break;
-    return tag_init_copy(tag, src->data.ptr.p);
-  default:
-    break;
-  }
-  err_puts("tag_init_cast: invalid cast");
-  assert(! "tag_init_cast: invalid cast");
-  return NULL;
-}
-
-s_tag * tag_init_cast_struct (s_tag *tag, const s_sym * const *type,
-                              s_tag *src)
-{
-  assert(tag);
-  assert(type);
-  assert(*type);
-  assert(src);
-  switch (src->type) {
-  case TAG_PTR:
-    if (! src->data.ptr.p)
-      return tag_init_void(tag);
-    return tag_init_struct_with_data(tag, *type, src->data.ptr.p,
-                                     false);
-  case TAG_PTR_FREE:
-    if (! src->data.ptr_free.p)
-      return tag_init_void(tag);
-    return tag_init_struct_with_data(tag, *type, src->data.ptr_free.p,
-                                     false);
-  case TAG_STRUCT:
-    if (*type == src->data.struct_.type->module)
-      return tag_init_struct_copy(tag, &src->data.struct_);
-  default:
-    break;
-  }
-  err_puts("tag_init_cast_struct: invalid cast");
-  assert(! "tag_init_cast_struct: invalid cast");
-  return NULL;
-}
-
 s_tag * tag_init_var (s_tag *tag, const s_sym *type)
 {
   s_tag tmp = {0};
@@ -599,7 +599,7 @@ s_tag * tag_init_var (s_tag *tag, const s_sym *type)
 s_tag * tag_init_void (s_tag *tag)
 {
   assert(tag);
-  *tag = (s_tag) {0};
+  memset(tag, 0, sizeof(s_tag));
   return tag;
 }
 
diff --git a/test/ikc3/str.out.expected b/test/ikc3/str.out.expected
index bf20e08..b3b1f53 100644
--- a/test/ikc3/str.out.expected
+++ b/test/ikc3/str.out.expected
@@ -47,9 +47,7 @@
 "#{%KC3.Operator{}}"
 "%KC3.Operator{sym: :+,\n              symbol_value: ?,\n              operator_precedence: 0,\n              operator_associativity: :left}"
 "#{%KC3.Operator{sym: :-,
-                 symbol_value: ?,
-                 operator_precedence: 0,
-                 operator_associativity: :left}}"
+                 symbol_value: ?}}"
 "%KC3.Operator{sym: :-,\n              symbol_value: ?,\n              operator_precedence: 0,\n              operator_associativity: :left}"
 "#{false}"
 "false"