Commit 374c6d77c9c25bd857dec15eb312d0658ab6dd3a

Thomas de Grivel 2024-03-20T11:06:10

major speed up : removed all non necessary usage of tag_init_1

diff --git a/libc3/env.c b/libc3/env.c
index 776e9ff..cfbc77a 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -1504,7 +1504,7 @@ s8 env_operator_arity (s_env *env, const s_ident *op)
   assert(env);
   assert(op);
   tag_init_ident(&tag_op, op);
-  tag_init_1(    &tag_arity, ":arity");
+  tag_init_sym(  &tag_arity, &g_sym_arity);
   tag_init_var(  &tag_var);
   facts_with_tags(&env->facts, &cursor, &tag_op, &tag_arity, &tag_var);
   if (facts_cursor_next(&cursor) &&
@@ -1529,11 +1529,11 @@ bool env_operator_find (s_env *env, const s_ident *op)
   s_tag tag_operator;
   assert(env);
   assert(op);
-  tag_init_1(    &tag_is_a, ":is_a");
+  tag_init_sym(  &tag_is_a, &g_sym_is_a);
   tag_init_ident(&tag_op, op);
-  tag_init_1(    &tag_operator, ":operator");
+  tag_init_sym(  &tag_operator, &g_sym_operator);
   return facts_find_fact_by_tags(&env->facts, &tag_op, &tag_is_a,
-                                 &tag_operator) ? 1 : 0;
+                                 &tag_operator) ? true : false;
 }
 
 s_ident * env_operator_ident (s_env *env, const s_ident *op,
@@ -1557,11 +1557,11 @@ bool env_operator_is_right_associative (s_env *env, const s_ident *op)
   s_tag tag_right;
   assert(env);
   assert(op);
-  tag_init_1(    &tag_assoc, ":operator_associativity");
+  tag_init_sym(  &tag_assoc, &g_sym_operator_associativity);
   tag_init_ident(&tag_op, op);
-  tag_init_1(    &tag_right, ":right");
+  tag_init_sym(  &tag_right, &g_sym_right);
   return facts_find_fact_by_tags(&env->facts, &tag_op, &tag_assoc,
-                                 &tag_right) ? 1 : 0;
+                                 &tag_right) ? true : false;
 }
 
 s8 env_operator_precedence (s_env *env, const s_ident *op)
@@ -1574,7 +1574,7 @@ s8 env_operator_precedence (s_env *env, const s_ident *op)
   assert(env);
   assert(op);
   tag_init_ident(&tag_op, op);
-  tag_init_1(    &tag_precedence, ":operator_precedence");
+  tag_init_sym(  &tag_precedence, &g_sym_operator_precedence);
   tag_init_var(  &tag_var);
   facts_with_tags(&env->facts, &cursor, &tag_op, &tag_precedence,
                   &tag_var);
@@ -1609,15 +1609,15 @@ s_ident * env_operator_resolve (s_env *env, const s_ident *op,
   s_ident tmp;
   tmp = *op;
   ident_resolve_module(&tmp, env);
-  tag_init_1(  &tag_arity, ":arity");
+  tag_init_sym(&tag_arity, &g_sym_arity);
   tag_init_u8( &tag_arity_u8, arity);
-  tag_init_1(  &tag_is_a, ":is_a");
-  tag_init_1(  &tag_module, ":module");
+  tag_init_sym(&tag_is_a, &g_sym_is_a);
+  tag_init_sym(&tag_module, &g_sym_module);
   tag_init_sym(&tag_module_name, tmp.module);
-  tag_init_1(  &tag_operator, ":operator");
+  tag_init_sym(&tag_operator, &g_sym_operator);
   tag_init_var(&tag_var);
   tag_init_sym(&tag_sym, tmp.sym);
-  tag_init_1(  &tag_symbol, ":symbol");
+  tag_init_sym(&tag_symbol, &g_sym_symbol);
   facts_with(&env->facts, &cursor, (t_facts_spec) {
       &tag_module_name, &tag_is_a, &tag_module,
       &tag_operator, &tag_var, NULL,   /* module exports operator */
@@ -1645,7 +1645,7 @@ const s_sym * env_operator_symbol (s_env *env, const s_ident *op)
   assert(env);
   assert(op);
   tag_init_ident(&tag_op, op);
-  tag_init_1(    &tag_symbol, ":symbol");
+  tag_init_sym(  &tag_symbol, &g_sym_symbol);
   tag_init_var(  &tag_var);
   facts_with_tags(&env->facts, &cursor, &tag_op, &tag_symbol, &tag_var);
   if (facts_cursor_next(&cursor) &&
@@ -1700,7 +1700,7 @@ u8 env_special_operator_arity (s_env *env, const s_ident *ident)
   assert(ident);
   tag_init_ident(&tag_ident, ident);
   env_ident_resolve_module(env, &tag_ident.data.ident);
-  tag_init_1(    &tag_arity, ":arity");
+  tag_init_sym(  &tag_arity, &g_sym_arity);
   tag_init_var(  &tag_var);
   facts_with_tags(&env->facts, &cursor,
                   &tag_ident, &tag_arity, &tag_var);
diff --git a/libc3/list.c b/libc3/list.c
index da48b47..1110f51 100644
--- a/libc3/list.c
+++ b/libc3/list.c
@@ -68,7 +68,8 @@ s_list * list_init (s_list *list, s_list *next)
 s_list * list_init_1 (s_list *list, const char *p, s_list *next)
 {
   assert(list);
-  tag_init_1(&list->tag, p);
+  if (! tag_init_1(&list->tag, p))
+    return NULL;
   tag_init_list(&list->next, next);
   return list;
 }
diff --git a/libc3/module.c b/libc3/module.c
index 4c64e3d..64225eb 100644
--- a/libc3/module.c
+++ b/libc3/module.c
@@ -22,6 +22,7 @@
 #include "file.h"
 #include "module.h"
 #include "tag.h"
+#include "sym.h"
 
 bool module_ensure_loaded (const s_sym *module, s_facts *facts)
 {
@@ -30,8 +31,8 @@ bool module_ensure_loaded (const s_sym *module, s_facts *facts)
   s_tag tag_is_a;
   s_tag tag_module;
   tag_init_sym(&tag_module_name, module);
-  tag_init_1(  &tag_is_a,     ":is_a");
-  tag_init_1(  &tag_module,   ":module");
+  tag_init_sym(&tag_is_a, &g_sym_is_a);
+  tag_init_sym(&tag_module, &g_sym_module);
   facts_with(facts, &cursor, (t_facts_spec) {
       &tag_module_name,
       &tag_is_a, &tag_module,     /* module exists */
@@ -62,7 +63,7 @@ s_tag * module_load_time (const s_sym *module, s_facts *facts,
   s_tag tag_load_time;
   s_tag tag_time_var;
   tag_init_sym(&tag_module_name, module);
-  tag_init_1(  &tag_load_time, ":load_time");
+  tag_init_sym(&tag_load_time, &g_sym_load_time);
   tag_init_var(&tag_time_var);
   facts_with(facts, &cursor, (t_facts_spec) {
       &tag_module_name, &tag_load_time, &tag_time_var, NULL, NULL });
diff --git a/libc3/sym.c b/libc3/sym.c
index 73b8724..8fe1fa1 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -68,6 +68,7 @@ const s_sym g_sym_Uw              = {{{NULL},  2, {"Uw"}}};
 const s_sym g_sym_Uw_brackets     = {{{NULL},  4, {"Uw[]"}}};
 const s_sym g_sym_Var             = {{{NULL},  3, {"Var"}}};
 const s_sym g_sym_Void            = {{{NULL},  4, {"Void"}}};
+const s_sym g_sym_arity           = {{{NULL},  5, {"arity"}}};
 const s_sym g_sym_cast            = {{{NULL},  4, {"cast"}}};
 const s_sym g_sym_defstruct       = {{{NULL},  9, {"defstruct"}}};
 const s_sym g_sym_do              = {{{NULL},  2, {"do"}}};
@@ -77,9 +78,15 @@ const s_sym g_sym_if_then_else    = {{{NULL}, 12, {"if_then_else"}}};
 const s_sym g_sym_is_a            = {{{NULL},  4, {"is_a"}}};
 const s_sym g_sym_load_time       = {{{NULL},  9, {"load_time"}}};
 const s_sym g_sym_macro           = {{{NULL},  5, {"macro"}}};
+const s_sym g_sym_module          = {{{NULL},  6, {"module"}}};
 const s_sym g_sym_operator        = {{{NULL},  8, {"operator"}}};
+const s_sym g_sym_operator_associativity =
+  {{{NULL}, 22, {"operator_associativity"}}};
 const s_sym g_sym_operator_pin    = {{{NULL}, 12, {"operator_pin"}}};
+const s_sym g_sym_operator_precedence =
+  {{{NULL}, 19, {"operator_precedence"}}};
 const s_sym g_sym_r               = {{{NULL},  1, {"r"}}};
+const s_sym g_sym_right           = {{{NULL},  5, {"right"}}};
 const s_sym g_sym_rw              = {{{NULL},  2, {"rw"}}};
 const s_sym g_sym_rwx             = {{{NULL},  3, {"rwx"}}};
 const s_sym g_sym_rx              = {{{NULL},  2, {"rx"}}};
@@ -316,6 +323,7 @@ void sym_init_g_sym (void)
   sym_register(&g_sym_Uw_brackets, NULL);
   sym_register(&g_sym_Var, NULL);
   sym_register(&g_sym_Void, NULL);
+  sym_register(&g_sym_arity, NULL);
   sym_register(&g_sym_cast, NULL);
   sym_register(&g_sym_defstruct, NULL);
   sym_register(&g_sym_do, NULL);
@@ -325,9 +333,13 @@ void sym_init_g_sym (void)
   sym_register(&g_sym_is_a, NULL);
   sym_register(&g_sym_load_time, NULL);
   sym_register(&g_sym_macro, NULL);
+  sym_register(&g_sym_module, NULL);
   sym_register(&g_sym_operator, NULL);
+  sym_register(&g_sym_operator_associativity, NULL);
   sym_register(&g_sym_operator_pin, NULL);
+  sym_register(&g_sym_operator_precedence, NULL);
   sym_register(&g_sym_r, NULL);
+  sym_register(&g_sym_right, NULL);
   sym_register(&g_sym_rw, NULL);
   sym_register(&g_sym_rwx, NULL);
   sym_register(&g_sym_rx, NULL);
diff --git a/libc3/sym.h b/libc3/sym.h
index dd31892..26ca125 100644
--- a/libc3/sym.h
+++ b/libc3/sym.h
@@ -73,6 +73,7 @@ extern const s_sym g_sym_Uw;
 extern const s_sym g_sym_Uw_brackets;
 extern const s_sym g_sym_Var;
 extern const s_sym g_sym_Void;
+extern const s_sym g_sym_arity;
 extern const s_sym g_sym_cast;
 extern const s_sym g_sym_defstruct;
 extern const s_sym g_sym_do;
@@ -82,9 +83,13 @@ extern const s_sym g_sym_if_then_else;
 extern const s_sym g_sym_is_a;
 extern const s_sym g_sym_load_time;
 extern const s_sym g_sym_macro;
+extern const s_sym g_sym_module;
 extern const s_sym g_sym_operator;
+extern const s_sym g_sym_operator_associativity;
 extern const s_sym g_sym_operator_pin;
+extern const s_sym g_sym_operator_precedence;
 extern const s_sym g_sym_r;
+extern const s_sym g_sym_right;
 extern const s_sym g_sym_rw;
 extern const s_sym g_sym_rwx;
 extern const s_sym g_sym_rx;