Commit 639abf556154ca05e0d38401e8f334636fc44cee

Thomas de Grivel 2024-04-02T10:17:38

wip defoperator

diff --git a/.ic3_history b/.ic3_history
index 479953d..bebc422 100644
--- a/.ic3_history
+++ b/.ic3_history
@@ -1,23 +1,3 @@
-  quote do
-    x = unquote(x)
-    {x, x}
-  end
-end
-dt(200)
-dt(a)
-a = [1, 2, 3]
-dt(a)
-def dt = macro (x) do
-  quote do
-    x = ^ unquote(x)
-    {x, x}
-  end
-end
-dt(a)
-1 + 10000000000000000000000000000000000000000000
-def beaucoup = 1 + 10000000000000000000000000000000000000000000
-type(beaucoup)
-def beaucoup = 1 + 10000000000000000000000000000000000000000000
 type(beaucoup)
 beaucoup
 def beaucoup = (U8) beaucoup
@@ -97,3 +77,23 @@ defmodule Plop do end
 defmodule Plop do def a = 1 end
 quote_cfn Plop
 defmodule Plop do def a = 1 end
+Plop.a
+defmodule Plop do def a = 1 end
+Plop.a
+Plop
+defmodule Plop do def a = 1 end
+Plop.a
+defmodule Plop do def a = 1 end
+Plop.a
+defmodule Plop do defoperator :operator_add :+ cfn Tag "tag_add" (Tag, Tag, Result) 10 :left end
+defmodule Plop do defoperator :operator_add :+ cfn Tag "tag_mul" (Tag, Tag, Result) 10 :left end
+defmodule Plop do
+  defoperator :operator_add :+ cfn Tag "tag_mul" (Tag, Tag, Result) 10 :left
+  def sq = fn (x) { x + x }
+end
+Plop.sq(4)
+defmodule Plop do defoperator :operator_add :+ cfn Tag "tag_mul" (Tag, Tag, Result) 10 :left end
+defmodule Plop do
+  def sq = fn (x) { x + x }
+end
+Plop.sq(4)
diff --git a/ic3/.ic3_history b/ic3/.ic3_history
index 16965a7..be20bb9 100644
--- a/ic3/.ic3_history
+++ b/ic3/.ic3_history
@@ -1,18 +1,3 @@
-dt(a)
-def dt = macro (x) do
-  quote do
-    x = ^ unquote(x)
-    {x, x}
-  end
-end
-dt(a)
-1 + 10000000000000000000000000000000000000000000
-def beaucoup = 1 + 10000000000000000000000000000000000000000000
-type(beaucoup)
-def beaucoup = 1 + 10000000000000000000000000000000000000000000
-type(beaucoup)
-beaucoup
-def beaucoup = (U8) beaucoup
 type(beaucoup)
 beacoup
 beaucoup
@@ -97,3 +82,18 @@ defmodule Plop do def a = 1 end
 Plop.a
 defmodule Plop do def a = 1 end
 Plop.a
+defmodule Plop do defoperator :operator_add :+ cfn Tag "tag_add" (Tag, Tag, Result) 10 :left end
+defmodule Plop do defoperator :operator_add :+ cfn Tag "tag_mul" (Tag, Tag, Result) 10 :left end
+defmodule Plop do
+  defoperator :operator_add :+ cfn Tag "tag_mul" (Tag, Tag, Result) 10 :left
+  def sq = fn (x) { x + x }
+end
+Plop.sq(4)
+defmodule Plop do defoperator :operator_add :+ cfn Tag "tag_mul" (Tag, Tag, Result) 10 :left end
+defmodule Plop do
+  def sq = fn (x) { x + x }
+end
+Plop.sq(4)
+defmodule Plop do defoperator :operator_add :+ cfn Tag "tag_mul" (Tag, Tag, Result) 10 :left end
+defmodule Plop do def sq = fn (x) { x + x } end
+Plop.sq(4)
diff --git a/libc3/env.c b/libc3/env.c
index fa3bada..c5517f4 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -128,12 +128,11 @@ s_tag * env_defmodule (s_env *env, const s_sym **name,
   tag_init_sym(&tag_module, &g_sym_module);
   tag_init_sym(&tag_module_name, *name);
   if (facts_add_tags(&env->facts, &tag_module_name, &tag_is_a,
-                     &tag_module)) {
-    if (env_eval_block(env, block, &tmp)) {
-      tag_clean(&tmp);
-      tag_init_sym(dest, *name);
-      result = dest;
-    }
+                     &tag_module) &&
+      env_eval_block(env, block, &tmp)) {
+    tag_clean(&tmp);
+    tag_init_sym(dest, *name);
+    result = dest;
   }
   env->current_module = module;
   env_module_is_loading_set(env, *name, false);
@@ -187,6 +186,14 @@ s_tag * env_defoperator (s_env *env, const s_sym **name,
                *operator_associativity);
   facts_add_tags(&env->facts, &tag_module_name, &tag_operator,
                  &tag_ident);
+  facts_add_tags(&env->facts, &tag_ident, &tag_is_a, &tag_operator);
+  facts_add_tags(&env->facts, &tag_ident, &tag_symbol, &tag_sym);
+  facts_add_tags(&env->facts, &tag_ident, &tag_arity_sym, &tag_arity_u8);
+  facts_add_tags(&env->facts, &tag_ident, &tag_symbol_value, symbol_value);
+  facts_add_tags(&env->facts, &tag_ident, &tag_operator_precedence_sym,
+                 &tag_operator_precedence_u8);
+  facts_add_tags(&env->facts, &tag_ident, &tag_operator_associativity_rel,
+                 &tag_operator_associativity_value);
   *dest = tag_ident;
   return dest;
 }