Commit e5030cf5952c0193d44fda7d56e6c51c412fac39

Thomas de Grivel 2024-11-26T21:12:10

better error messages

diff --git a/libkc3/env.c b/libkc3/env.c
index f0ebe66..4500cce 100644
--- a/libkc3/env.c
+++ b/libkc3/env.c
@@ -224,6 +224,13 @@ bool env_call_get (s_env *env, s_call *call)
 void env_clean (s_env *env)
 {
   assert(env);
+  if (false) {
+    uw size;
+    sym_list_size(&size);
+    err_write_1("env_clean: g_sym_list: ");
+    err_inspect_uw_decimal(&size);
+    err_write_1("\n");
+  }
   //facts_save_file(&env->facts, "debug.facts"); // debug
   env_clean_globals(env);
   env_clean_toplevel(env);
diff --git a/libkc3/map.c b/libkc3/map.c
index 5d1e772..d9e803f 100644
--- a/libkc3/map.c
+++ b/libkc3/map.c
@@ -121,8 +121,10 @@ const s_sym ** map_get_var_type (const s_map *map, const s_tag *key,
     i++;
   }
   err_write_1("map_get_type: ");
+  err_inspect_map(map);
+  err_write_1("\nkey not found: ");
   err_inspect_tag(key);
-  err_puts(": key not found");
+  err_write_1("\n");
   return NULL;
 }
 
diff --git a/libkc3/struct.c b/libkc3/struct.c
index 18a1830..a573830 100644
--- a/libkc3/struct.c
+++ b/libkc3/struct.c
@@ -46,17 +46,19 @@ s_tag * struct_access (s_struct *s, s_list *key, s_tag *dest)
     assert(! "struct_access: key is not a Sym");
     return NULL;
   }
-  if (! next)
-    return struct_access_sym(s, first->data.sym, dest);
   if (! struct_access_sym(s, first->data.sym, &tag)) {
-    err_write_1("struct_access: map_get(");
+    err_write_1("struct_access: struct_access_sym(");
     err_inspect_struct(s);
     err_write_1(", ");
     err_inspect_tag(first);
     err_write_1(")\n");
-    assert(! "struct_access: map_get");
+    assert(! "struct_access: map_access_sym");
     return NULL;
   }
+  if (! next) {
+    *dest = tag;
+    return dest;
+  }
   r = kc3_access(&tag, &next, dest);
   tag_clean(&tag);
   return r;
diff --git a/libkc3/sym.c b/libkc3/sym.c
index b0dcf78..0bd57d5 100644
--- a/libkc3/sym.c
+++ b/libkc3/sym.c
@@ -454,6 +454,19 @@ const s_sym ** sym_init_str (const s_sym **sym, const s_str *src)
   return sym;
 }
 
+uw * sym_list_size (uw *dest)
+{
+  uw size = 0;
+  const s_sym_list *l;
+  l = g_sym_list;
+  while (l) {
+    size += sizeof(s_sym) + l->sym->str.size + 1;
+    l = l->next;
+  }
+  *dest = size;
+  return dest;
+}
+
 bool sym_register (const s_sym *sym, s_sym *free_sym)
 {
   s_sym_list *tmp = NULL;
diff --git a/libkc3/sym.h b/libkc3/sym.h
index d66a86d..2bc8153 100644
--- a/libkc3/sym.h
+++ b/libkc3/sym.h
@@ -151,6 +151,7 @@ bool          sym_has_ident_reserved_characters (const s_sym *sym);
 bool          sym_has_reserved_characters (const s_sym *sym);
 bool          sym_is_array_type (const s_sym *sym);
 bool          sym_is_module (const s_sym *sym);
+uw *          sym_list_size (uw *dest);
 bool *        sym_must_clean (const s_sym *sym, bool *must_clean);
 bool          sym_search_modules (const s_sym *sym, const s_sym **dest);
 bool          sym_to_ffi_type (const s_sym *sym, ffi_type *result_type,