Commit 01fcf0a3357247c507247d29e8aae34ae1d0f4bf

Thomas de Grivel 2023-11-27T00:51:59

reduce code

diff --git a/libc3/tag.c b/libc3/tag.c
index 072e31f..4d7ccef 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -1762,85 +1762,14 @@ ffi_type * tag_type_to_ffi_type (e_tag_type type)
   return &ffi_type_void;
 }
 
-const s_sym * tag_type_to_module (e_tag_type tag_type)
+const s8 * tag_type_to_string (e_tag_type type)
 {
-  switch (tag_type) {
-  case TAG_VOID:       return sym_1("Void");
-  case TAG_ARRAY:      return sym_1("Array");
-  case TAG_BOOL:       return sym_1("Bool");
-  case TAG_CALL:       return sym_1("Call");
-  case TAG_CFN:        return sym_1("Cfn");
-  case TAG_CHARACTER:  return sym_1("Character");
-  case TAG_F32:        return sym_1("F32");
-  case TAG_F64:        return sym_1("F64");
-  case TAG_FACT:       return sym_1("Fact");
-  case TAG_FN:         return sym_1("Fn");
-  case TAG_IDENT:      return sym_1("Ident");
-  case TAG_INTEGER:    return sym_1("Integer");
-  case TAG_SW:         return sym_1("Sw");
-  case TAG_S64:        return sym_1("S64");
-  case TAG_S32:        return sym_1("S32");
-  case TAG_S16:        return sym_1("S16");
-  case TAG_S8:         return sym_1("S8");
-  case TAG_U8:         return sym_1("U8");
-  case TAG_U16:        return sym_1("U16");
-  case TAG_U32:        return sym_1("U32");
-  case TAG_U64:        return sym_1("U64");
-  case TAG_UW:         return sym_1("Uw");
-  case TAG_LIST:       return sym_1("List");
-  case TAG_MAP:        return sym_1("Map");
-  case TAG_PTAG:       return sym_1("Ptag");
-  case TAG_PTR:        return sym_1("Ptr");
-  case TAG_QUOTE:      return sym_1("Quote");
-  case TAG_STR:        return sym_1("Str");
-  case TAG_SYM:        return sym_1("Sym");
-  case TAG_TUPLE:      return sym_1("Tuple");
-  case TAG_VAR:        return sym_1("Var");
-  }
-  assert(! "tag_type_to_module: invalid tag type");
-  errx(1, "tag_type_to_module: invalid tag type: %d", tag_type);
-  return NULL;
+  const s_sym *sym;
+  if (! (sym = tag_type_to_sym(type)))
+    return NULL;
+  return sym->str.ptr.ps8;
 }
 
-s8 * tag_type_to_string (e_tag_type type)
-{
-  switch (type) {
-  case TAG_VOID: return "Void";
-  case TAG_ARRAY: return "Array";
-  case TAG_BOOL: return "Bool";
-  case TAG_CALL: return "Call";
-  case TAG_CFN: return "Cfn";
-  case TAG_CHARACTER: return "Character";
-  case TAG_F32: return "F32";
-  case TAG_F64: return "F64";
-  case TAG_FACT: return "Fact";
-  case TAG_FN: return "Fn";
-  case TAG_IDENT: return "Ident";
-  case TAG_INTEGER: return "Integer";
-  case TAG_SW: return "Sw";
-  case TAG_S64: return "S64";
-  case TAG_S32: return "S32";
-  case TAG_S16: return "S16";
-  case TAG_S8: return "S8";
-  case TAG_U8: return "U8";
-  case TAG_U16: return "U16";
-  case TAG_U32: return "U32";
-  case TAG_U64: return "U64";
-  case TAG_UW: return "Uw";
-  case TAG_LIST: return "List";
-  case TAG_MAP: return "Map";
-  case TAG_PTAG: return "Ptag";
-  case TAG_PTR: return "Void*";
-  case TAG_QUOTE: return "Quote";
-  case TAG_STR: return "Str";
-  case TAG_SYM: return "Sym";
-  case TAG_TUPLE: return "Tuple";
-  case TAG_VAR: return "Var";
-  }
-  assert(! "tag_type_to_string: unknown tag type");
-  errx(1, "tag_type_to_string: unknown tag type");
-  return NULL;
-}
 
 const s_sym * tag_type_to_sym (e_tag_type tag_type)
 {
diff --git a/libc3/tag.h b/libc3/tag.h
index de31632..8a9e1aa 100644
--- a/libc3/tag.h
+++ b/libc3/tag.h
@@ -116,8 +116,7 @@ sw                 tag_type_size (e_tag_type type);
 f_buf_inspect      tag_type_to_buf_inspect (e_tag_type type);
 f_buf_inspect_size tag_type_to_buf_inspect_size (e_tag_type type);
 f_buf_parse        tag_type_to_buf_parse (e_tag_type type);
-const s_sym *      tag_type_to_module (e_tag_type type);
-s8 *               tag_type_to_string (e_tag_type type);
+const s8 *         tag_type_to_string (e_tag_type type);
 const s_sym *      tag_type_to_sym (e_tag_type tag_type);
 
 /* Modifiers */