Commit 35c2f2fe9e90896fd6e86695f5299723b75d2aac

Thomas de Grivel 2024-07-23T20:35:40

wip env

diff --git a/lib/kc3/0.1/kc3.facts b/lib/kc3/0.1/kc3.facts
index d8d57be..8f2111d 100644
--- a/lib/kc3/0.1/kc3.facts
+++ b/lib/kc3/0.1/kc3.facts
@@ -3,139 +3,139 @@
 replace {KC3, :is_a, :module}
 replace {KC3, :operator, KC3.operator_paren}
 replace {KC3.operator_paren, :is_a, :operator}
-replace {KC3.operator_paren, :symbol, :"()"}
+replace {KC3.operator_paren, :sym, :"()"}
 replace {KC3.operator_paren, :arity, 1}
 replace {KC3.operator_paren, :symbol_value, cfn Tag "tag_paren" (Tag, Result)}
 replace {KC3.operator_paren, :operator_precedence, 13}
 replace {KC3.operator_paren, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_brackets}
 replace {KC3.operator_brackets, :is_a, :operator}
-replace {KC3.operator_brackets, :symbol, :"[]"}
+replace {KC3.operator_brackets, :sym, :"[]"}
 replace {KC3.operator_brackets, :arity, 2}
 replace {KC3.operator_brackets, :symbol_value, cfn Tag "tag_brackets" (Tag, Tag, Result)}
 replace {KC3.operator_brackets, :operator_precedence, 13}
 replace {KC3.operator_brackets, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_bnot}
 replace {KC3.operator_bnot, :is_a, :operator}
-replace {KC3.operator_bnot, :symbol, :~}
+replace {KC3.operator_bnot, :sym, :~}
 replace {KC3.operator_bnot, :arity, 1}
 replace {KC3.operator_bnot, :symbol_value, cfn Tag "tag_bnot" (Tag, Result)}
 replace {KC3.operator_bnot, :operator_precedence, 12}
 replace {KC3.operator_bnot, :operator_associativity, :right}
 add {KC3, :operator, KC3.operator_defstruct}
 replace {KC3.operator_defstruct, :is_a, :operator}
-replace {KC3.operator_defstruct, :symbol, :defstruct}
+replace {KC3.operator_defstruct, :sym, :defstruct}
 replace {KC3.operator_defstruct, :arity, 1}
 replace {KC3.operator_defstruct, :symbol_value, cfn Tag "kc3_defstruct" (List, Result)}
 replace {KC3.operator_defstruct, :operator_precedence, 12}
 replace {KC3.operator_defstruct, :operator_associativity, :none}
 add {KC3, :operator, KC3.operator_pin}
 replace {KC3.operator_pin, :is_a, :operator}
-replace {KC3.operator_pin, :symbol, :^}
+replace {KC3.operator_pin, :sym, :^}
 replace {KC3.operator_pin, :arity, 1}
 replace {KC3.operator_pin, :symbol_value, cfn Tag "kc3_pin" (Tag, Result)}
 replace {KC3.operator_pin, :operator_precedence, 12}
 replace {KC3.operator_pin, :operator_associativity, :right}
 add {KC3, :operator, KC3.operator_neg}
 replace {KC3.operator_neg, :is_a, :operator}
-replace {KC3.operator_neg, :symbol, :-}
+replace {KC3.operator_neg, :sym, :-}
 replace {KC3.operator_neg, :arity, 1}
 replace {KC3.operator_neg, :symbol_value, cfn Tag "tag_neg" (Tag, Result)}
 replace {KC3.operator_neg, :operator_precedence, 12}
 replace {KC3.operator_neg, :operator_associativity, :right}
 add {KC3, :operator, KC3.operator_not}
 replace {KC3.operator_not, :is_a, :operator}
-replace {KC3.operator_not, :symbol, :!}
+replace {KC3.operator_not, :sym, :!}
 replace {KC3.operator_not, :arity, 1}
 replace {KC3.operator_not, :symbol_value, cfn Bool "tag_not" (Tag, Result)}
 replace {KC3.operator_not, :operator_precedence, 12}
 replace {KC3.operator_not, :operator_associativity, :right}
 add {KC3, :operator, KC3.operator_require}
 replace {KC3.operator_require, :is_a, :operator}
-replace {KC3.operator_require, :symbol, :require}
+replace {KC3.operator_require, :sym, :require}
 replace {KC3.operator_require, :arity, 1}
 replace {KC3.operator_require, :symbol_value, cfn Tag "kc3_require" (List, Result)}
 replace {KC3.operator_require, :operator_precedence, 12}
 replace {KC3.operator_require, :operator_associativity, :none}
 add {KC3, :operator, KC3.operator_div}
 replace {KC3.operator_div, :is_a, :operator}
-replace {KC3.operator_div, :symbol, :/}
+replace {KC3.operator_div, :sym, :/}
 replace {KC3.operator_div, :arity, 2}
 replace {KC3.operator_div, :symbol_value, cfn Tag "tag_div" (Tag, Tag, Result)}
 replace {KC3.operator_div, :operator_precedence, 11}
 replace {KC3.operator_div, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_mod}
 replace {KC3.operator_mod, :is_a, :operator}
-replace {KC3.operator_mod, :symbol, :mod}
+replace {KC3.operator_mod, :sym, :mod}
 replace {KC3.operator_mod, :arity, 2}
 replace {KC3.operator_mod, :symbol_value, cfn Tag "tag_mod" (Tag, Tag, Result)}
 replace {KC3.operator_mod, :operator_precedence, 11}
 replace {KC3.operator_mod, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_mul}
 replace {KC3.operator_mul, :is_a, :operator}
-replace {KC3.operator_mul, :symbol, :*}
+replace {KC3.operator_mul, :sym, :*}
 replace {KC3.operator_mul, :arity, 2}
 replace {KC3.operator_mul, :symbol_value, cfn Tag "tag_mul" (Tag, Tag, Result)}
 replace {KC3.operator_mul, :operator_precedence, 11}
 replace {KC3.operator_mul, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_add}
 replace {KC3.operator_add, :is_a, :operator}
-replace {KC3.operator_add, :symbol, :+}
+replace {KC3.operator_add, :sym, :+}
 replace {KC3.operator_add, :arity, 2}
 replace {KC3.operator_add, :symbol_value, cfn Tag "tag_add" (Tag, Tag, Result)}
 replace {KC3.operator_add, :operator_precedence, 10}
 replace {KC3.operator_add, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_addi}
 replace {KC3.operator_addi, :is_a, :operator}
-replace {KC3.operator_addi, :symbol, :+i}
+replace {KC3.operator_addi, :sym, :+i}
 replace {KC3.operator_addi, :arity, 2}
 replace {KC3.operator_addi, :symbol_value, cfn Tag "tag_addi" (Tag, Tag, Result)}
 replace {KC3.operator_addi, :operator_precedence, 10}
 replace {KC3.operator_addi, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_sub}
 replace {KC3.operator_sub, :is_a, :operator}
-replace {KC3.operator_sub, :symbol, :-}
+replace {KC3.operator_sub, :sym, :-}
 replace {KC3.operator_sub, :arity, 2}
 replace {KC3.operator_sub, :symbol_value, cfn Tag "tag_sub" (Tag, Tag, Result)}
 replace {KC3.operator_sub, :operator_precedence, 10}
 replace {KC3.operator_sub, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_shift_left}
 replace {KC3.operator_shift_left, :is_a, :operator}
-replace {KC3.operator_shift_left, :symbol, :<<}
+replace {KC3.operator_shift_left, :sym, :<<}
 replace {KC3.operator_shift_left, :arity, 2}
 replace {KC3.operator_shift_left, :symbol_value, cfn Tag "tag_shift_left" (Tag, Tag, Result)}
 replace {KC3.operator_shift_left, :operator_precedence, 9}
 replace {KC3.operator_shift_left, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_shift_right}
 replace {KC3.operator_shift_right, :is_a, :operator}
-replace {KC3.operator_shift_right, :symbol, :>>}
+replace {KC3.operator_shift_right, :sym, :>>}
 replace {KC3.operator_shift_right, :arity, 2}
 replace {KC3.operator_shift_right, :symbol_value, cfn Tag "tag_shift_right" (Tag, Tag, Result)}
 replace {KC3.operator_shift_right, :operator_precedence, 9}
 replace {KC3.operator_shift_right, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_lt}
 replace {KC3.operator_lt, :is_a, :operator}
-replace {KC3.operator_lt, :symbol, :<}
+replace {KC3.operator_lt, :sym, :<}
 replace {KC3.operator_lt, :arity, 2}
 replace {KC3.operator_lt, :symbol_value, cfn Bool "tag_lt" (Tag, Tag, Result)}
 replace {KC3.operator_lt, :operator_precedence, 8}
 replace {KC3.operator_lt, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_lte}
-replace {KC3.operator_lte, :symbol, :<=}
+replace {KC3.operator_lte, :sym, :<=}
 replace {KC3.operator_lte, :is_a, :operator}
 replace {KC3.operator_lte, :arity, 2}
 replace {KC3.operator_lte, :symbol_value, cfn Bool "tag_lte" (Tag, Tag, Result)}
 replace {KC3.operator_lte, :operator_precedence, 8}
 replace {KC3.operator_lte, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_gt}
-replace {KC3.operator_gt, :symbol, :>}
+replace {KC3.operator_gt, :sym, :>}
 replace {KC3.operator_gt, :is_a, :operator}
 replace {KC3.operator_gt, :arity, 2}
 replace {KC3.operator_gt, :symbol_value, cfn Bool "tag_gt" (Tag, Tag, Result)}
 replace {KC3.operator_gt, :operator_precedence, 8}
 replace {KC3.operator_gt, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_gte}
-replace {KC3.operator_gte, :symbol, :>=}
+replace {KC3.operator_gte, :sym, :>=}
 replace {KC3.operator_gte, :is_a, :operator}
 replace {KC3.operator_gte, :arity, 2}
 replace {KC3.operator_gte, :symbol_value, cfn Bool "tag_gte" (Tag, Tag, Result)}
@@ -143,49 +143,49 @@ replace {KC3.operator_gte, :operator_precedence, 8}
 replace {KC3.operator_gte, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_eq}
 replace {KC3.operator_eq, :is_a, :operator}
-replace {KC3.operator_eq, :symbol, :==}
+replace {KC3.operator_eq, :sym, :==}
 replace {KC3.operator_eq, :arity, 2}
 replace {KC3.operator_eq, :symbol_value, cfn Bool "tag_eq" (Tag, Tag, Result)}
 replace {KC3.operator_eq, :operator_precedence, 7}
 replace {KC3.operator_eq, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_not_eq}
 replace {KC3.operator_not_eq, :is_a, :operator}
-replace {KC3.operator_not_eq, :symbol, :!=}
+replace {KC3.operator_not_eq, :sym, :!=}
 replace {KC3.operator_not_eq, :arity, 2}
 replace {KC3.operator_not_eq, :symbol_value, cfn Bool "tag_not_eq" (Tag, Tag, Result)}
 replace {KC3.operator_not_eq, :operator_precedence, 7}
 replace {KC3.operator_not_eq, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_band}
 replace {KC3.operator_band, :is_a, :operator}
-replace {KC3.operator_band, :symbol, :&}
+replace {KC3.operator_band, :sym, :&}
 replace {KC3.operator_band, :arity, 2}
 replace {KC3.operator_band, :symbol_value, cfn Tag "tag_band" (Tag, Tag, Result)}
 replace {KC3.operator_band, :operator_precedence, 6}
 replace {KC3.operator_band, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_bxor}
 replace {KC3.operator_bxor, :is_a, :operator}
-replace {KC3.operator_bxor, :symbol, :^}
+replace {KC3.operator_bxor, :sym, :^}
 replace {KC3.operator_bxor, :arity, 2}
 replace {KC3.operator_bxor, :symbol_value, cfn Tag "tag_bxor" (Tag, Tag, Result)}
 replace {KC3.operator_bxor, :operator_precedence, 5}
 replace {KC3.operator_bxor, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_bor}
 replace {KC3.operator_bor, :is_a, :operator}
-replace {KC3.operator_bor, :symbol, :bor}
+replace {KC3.operator_bor, :sym, :bor}
 replace {KC3.operator_bor, :arity, 2}
 replace {KC3.operator_bor, :symbol_value, cfn Tag "tag_bor" (Tag, Tag, Result)}
 replace {KC3.operator_bor, :operator_precedence, 4}
 replace {KC3.operator_bor, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_and}
 replace {KC3.operator_and, :is_a, :operator}
-replace {KC3.operator_and, :symbol, :&&}
+replace {KC3.operator_and, :sym, :&&}
 replace {KC3.operator_and, :arity, 2}
 replace {KC3.operator_and, :symbol_value, cfn Bool "tag_and" (Tag, Tag, Result)}
 replace {KC3.operator_and, :operator_precedence, 3}
 replace {KC3.operator_and, :operator_associativity, :left}
 add {KC3, :operator, KC3.operator_or}
 replace {KC3.operator_or, :is_a, :operator}
-replace {KC3.operator_or, :symbol, :||}
+replace {KC3.operator_or, :sym, :||}
 replace {KC3.operator_or, :arity, 2}
 replace {KC3.operator_or, :symbol_value, cfn Bool "tag_or" (Tag, Tag, Result)}
 replace {KC3.operator_or, :operator_precedence, 2}
@@ -194,11 +194,16 @@ add {KC3, :operator, KC3.operator_equal}
 replace {KC3.operator_equal, :is_a, :operator}
 replace {KC3.operator_equal, :arity, 2}
 add {KC3.operator_equal, :is_a, :special_operator}
-replace {KC3.operator_equal, :symbol, :=}
+replace {KC3.operator_equal, :sym, :=}
 replace {KC3.operator_equal, :symbol_value, cfn Tag "tag_equal" (Tag, Tag, Result)}
 replace {KC3.operator_equal, :operator_precedence, 1}
 replace {KC3.operator_equal, :operator_associativity, :right}
+add {KC3, :symbol, KC3.break}
 replace {KC3.break, :symbol_value, cfn Void "kc3_break" ()}
+add {KC3, :symbol, KC3.if_then_else}
+replace {KC3.if_then_else, :arity, 3}
+replace {KC3.if_then_else, :is_a, :special_operator}
+replace {KC3.if_then_else, :symbol_value, cfn Tag "kc3_if_then_else" (Tag, Tag, Tag, Result)}
 replace {KC3, :symbol, KC3.license}
 replace {KC3.license, :symbol_value, cfn Void "kc3_license" ()}
 add {KC3, :symbol, KC3.type}
@@ -210,22 +215,18 @@ replace {KC3.getenv, :symbol_value, cfn Str "kc3_getenv" (Str, Result)}
 add {KC3, :symbol, KC3.dlopen}
 replace {KC3.dlopen, :symbol_value, cfn Ptr "kc3_dlopen" (Str, Result)}
 add {KC3, :symbol, KC3.first}
-replace {KC3.first, :symbol_value, KC3.fn {
+replace {KC3.first, :symbol_value, fn {
  ([a | _b]) { a }
  ({a, _b}) { a }
  ({a, _b, _c}) { a }
  ({a, _b, _c, _d}) { a }
 }}
 add {KC3, :symbol, KC3.fib}
-replace {KC3.fib, :symbol_value, KC3.fn {
+replace {KC3.fib, :symbol_value, fn {
   (0) { 1 }
   (1) { 1 }
   (x) { if x < 0 then 0 else fib(x - 1) + fib(x - 2) end }
 }}
-add {KC3, :symbol, KC3.if_then_else}
-replace {KC3.if_then_else, :arity, 3}
-replace {KC3.if_then_else, :is_a, :special_operator}
-replace {KC3.if_then_else, :symbol_value, cfn Tag "kc3_if_then_else" (Tag, Tag, Tag, Result)}
 add {KC3, :symbol, KC3.sqrt}
 replace {KC3.sqrt, :symbol_value, cfn Tag "tag_sqrt" (Tag, Result)}
 add {KC3, :symbol, KC3.hash}
diff --git a/libkc3/env.c b/libkc3/env.c
index d60e7b2..8361d3d 100644
--- a/libkc3/env.c
+++ b/libkc3/env.c
@@ -2285,7 +2285,7 @@ bool * env_module_has_ident (s_env *env, const s_sym *module,
     return dest;
   }
   tag_init_sym(&tag_sym_sym, &g_sym_sym);
-  tag_init_var(&tag_var, &g_sym_Tag);
+  tag_init_var(&tag_var, &g_sym_Ident);
   if (! facts_with(&env->facts, &cursor, (t_facts_spec) {
         &tag_module_name, &tag_operator, &tag_var, NULL,
         &tag_var, &tag_sym_sym, &tag_sym_value, NULL, NULL})) {
@@ -2646,11 +2646,11 @@ s_ident * env_operator_resolve (s_env *env, const s_ident *op,
   tag_init_sym(&tag_operator, &g_sym_operator);
   tag_init_var(&tag_var, &g_sym_Ident);
   tag_init_sym(&tag_sym, tmp.sym);
-  tag_init_sym(&tag_symbol, &g_sym_symbol);
+  tag_init_sym(&tag_sym_sym, &g_sym_sym);
   if (! facts_with(&env->facts, &cursor, (t_facts_spec) {
         &tag_module_name, &tag_is_a, &tag_module,
         &tag_operator, &tag_var, NULL,
-        &tag_var, &tag_symbol, &tag_sym,
+        &tag_var, &tag_sym_sym, &tag_sym,
         &tag_arity, &tag_arity_u8,
         NULL, NULL })) {
     err_write_1("env_operator_resolve: ");
@@ -2788,7 +2788,7 @@ bool env_sym_search_modules (s_env *env, const s_sym *sym,
     }
     if (b) {
       *dest = module;
-      if (false) {
+      if (true) {
         err_write_1("env_sym_search_modules: ");
         err_inspect_sym(&sym);
         err_write_1(": search_module: ");
@@ -2797,7 +2797,7 @@ bool env_sym_search_modules (s_env *env, const s_sym *sym,
       }
       return true;
     }
-    if (false) {
+    if (true) {
       err_write_1("env_sym_search_modules: ");
       err_inspect_sym(&sym);
       err_write_1(": search_module: ");
@@ -2808,7 +2808,7 @@ bool env_sym_search_modules (s_env *env, const s_sym *sym,
     }
     search_module = list_next(search_module);
   }
-  if (false) {
+  if (true) {
     err_write_1("env_sym_search_modules: ");
     err_inspect_sym(&sym);
     err_write_1(": search_module: ");
diff --git a/libkc3/kc3.c b/libkc3/kc3.c
index 6f9056b..7fd41dd 100644
--- a/libkc3/kc3.c
+++ b/libkc3/kc3.c
@@ -161,7 +161,7 @@ s_str * kc3_getenv (const s_str *name, s_str *dest)
 
 /* Special operator. */
 s_tag * kc3_if_then_else (const s_tag *cond, const s_tag *then,
-                         const s_tag *else_, s_tag *dest)
+                          const s_tag *else_, s_tag *dest)
 {
   bool b;
   s_tag tmp;
diff --git a/libkc3/sym.c b/libkc3/sym.c
index e96f927..e3ff5df 100644
--- a/libkc3/sym.c
+++ b/libkc3/sym.c
@@ -83,6 +83,7 @@ const s_sym g_sym_do              = {{{NULL},  2, {"do"}}};
 const s_sym g_sym_else            = {{{NULL},  4, {"else"}}};
 const s_sym g_sym_end             = {{{NULL},  3, {"end"}}};
 const s_sym g_sym_fn              = {{{NULL},  2, {"fn"}}};
+const s_sym g_sym_if              = {{{NULL},  2, {"if"}}};
 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_is_loading      = {{{NULL}, 10, {"is_loading"}}};
@@ -376,6 +377,7 @@ void sym_init_g_sym (void)
   sym_register(&g_sym_else, NULL);
   sym_register(&g_sym_end, NULL);
   sym_register(&g_sym_fn, NULL);
+  sym_register(&g_sym_if, NULL);
   sym_register(&g_sym_if_then_else, NULL);
   sym_register(&g_sym_is_a, NULL);
   sym_register(&g_sym_is_loading, NULL);
diff --git a/libkc3/sym.h b/libkc3/sym.h
index 6551936..8541efe 100644
--- a/libkc3/sym.h
+++ b/libkc3/sym.h
@@ -87,6 +87,7 @@ extern const s_sym g_sym_do;
 extern const s_sym g_sym_else;
 extern const s_sym g_sym_end;
 extern const s_sym g_sym_fn;
+extern const s_sym g_sym_if;
 extern const s_sym g_sym_if_then_else;
 extern const s_sym g_sym_is_a;
 extern const s_sym g_sym_is_loading;