Commit 6f2c2089cb49deefb432d687e2a614511d77bc07

Thomas de Grivel 2023-06-11T21:51:09

wip buf_inspect

diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 9bc60d0..38fd3fb 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -737,6 +737,34 @@ sw buf_inspect_fn_pattern (s_buf *buf, const s_list *pattern)
   return result;
 }
 
+sw buf_inspect_fn_size (const s_fn *fn)
+{
+  sw r;
+  sw result = 0;
+  r = strlen("fn ");
+  result += r;
+  if (fn->next_clause) {
+    r = strlen("{\n");
+    result += r;
+    while (fn) {
+      r = strlen("  ");
+      result += r;
+      r = buf_inspect_fn_clause_size(fn);
+      result += r;
+      r = strlen("\n");
+      result += r;
+      fn = fn->next_clause;
+    }
+    r = strlen("}\n");
+    result += r;
+  }
+  else {
+    r = buf_inspect_fn_clause_size(fn);
+    result += r;
+  }
+  return result;
+}
+
 sw buf_inspect_ident (s_buf *buf, const s_ident *ident)
 {
   sw r;
@@ -1441,7 +1469,7 @@ sw buf_inspect_var (s_buf *buf, const s_tag *var)
   if ((r = buf_write_1(buf, "var(0x")) < 0)
     return r;
   result += r;
-  if ((r = buf_inspect_uw_hexadecimal(buf, (uw *) &var)) < 0)
+  if ((r = buf_inspect_uw_hexadecimal(buf, (uw *) var)) < 0)
     return r;
   result += r;
   if ((r = buf_write_1(buf, ")")) < 0)
@@ -1450,6 +1478,19 @@ sw buf_inspect_var (s_buf *buf, const s_tag *var)
   return result;
 }
 
+sw buf_inspect_var_size (const s_tag *var)
+{
+  sw r;
+  sw result = 0;
+  r = strlen("var(0x");
+  result += r;
+  r = buf_inspect_uw_hexadecimal_size((uw *) var);
+  result += r;
+  r = strlen(")");
+  result += r;
+  return result;
+}
+
 sw buf_inspect_void (s_buf *buf, const void *_)
 {
   sw r;
diff --git a/libc3/buf_inspect.h b/libc3/buf_inspect.h
index 5f710ae..8909a82 100644
--- a/libc3/buf_inspect.h
+++ b/libc3/buf_inspect.h
@@ -78,6 +78,7 @@ sw buf_inspect_fact_spec (s_buf *buf, p_facts_spec spec);
 sw buf_inspect_fn (s_buf *buf, const s_fn *fn);
 sw buf_inspect_fn_algo (s_buf *buf, const s_list *algo);
 sw buf_inspect_fn_clause (s_buf *buf, const s_fn *fn);
+sw buf_inspect_fn_clause_size (const s_fn *fn);
 sw buf_inspect_fn_pattern (s_buf *buf, const s_list *pattern);
 sw buf_inspect_fn_size (const s_fn *fn);
 sw buf_inspect_ident (s_buf *buf, const s_ident *ident);
diff --git a/libc3/tag.c b/libc3/tag.c
index 7c26d8a..a897eb7 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -1943,6 +1943,11 @@ void * tag_to_pointer (s_tag *tag, const s_sym *type)
   return NULL;  
 }
 
+sw tag_type_size (e_tag_type type)
+{
+  return sizeof(type);
+}
+
 f_buf_parse tag_type_to_buf_parse (e_tag_type type)
 {
   switch (type) {