Commit c11ccf0fe7d933ea3bd59231e2ef2e49932f6b69

Thomas de Grivel 2024-04-08T15:57:56

fix pattern matching of calls

diff --git a/.ic3_history b/.ic3_history
index 7e24c02..9a549c0 100644
--- a/.ic3_history
+++ b/.ic3_history
@@ -1,30 +1,3 @@
-1 / 4
-(Ratio) 1 / 4
-(Ratio) 1 / 4 * 2
-1/4 * 2
-type(1/4)
-1/4 / 13/12
-1/4 / 13/12 * 2
-(Complex) 1
-1 +i 2
-type(1 +i 2)
-1 +i 2 +i 3
-(1 +i 2) * (2 +i 3)
-sqrt(-1)
-sqrt(-1) * sqrt(-1)
-sqrt(-2) * sqrt(-2)
-def dt = macro (x) do
-  quote do
-    x = ^ unquote(x)
-    {x, x}
-  end
-end
-dt(200)
-dt(200 * 200)
-dt(sqrt(-1))
-def double = fn (x) { x * 2 }
-double(200)
-double(beaucoup)
 def beaucoup = 1 + 10000000000000000000000000000000000000000000
 double(beaucoup)
 dt
@@ -97,3 +70,30 @@ Plop.a
 (Sw) 123
 (Sw) 123/2
 (Sw) 123 / 2
+defmodule Plop do def a = 1 end
+Plop.a
+defmodule Plop do def a = 2 end
+Plop.a
+defmodule Plop do def a = 1; def double = fn (x) { x * 2 } end
+Plop.a
+Plop.double
+Plop.double(21)
+def a = 1
+a
+def double = fn (x) { x * 2 }
+double(42)
+defmodule Tiyon do
+  def a = 1
+  def double = fn (x) { x * 2 }
+  def double_tuple = macro (x) do {x, x} end
+  def double_list = macro (x) do [x, x] end
+end
+Tiyon.a
+Tiyon.double(21)
+Tiyon.double_tuple(21)
+Tiyon.double_tuple(21 + 21)
+Tiyon.double_list(21 + 21)
+[42, x] = Tiyon.double_list(21 + 21)
+[42, x] = [42, 42]
+x
+Tiyon.double_list(21 + 21) = [42, y]
diff --git a/ic3/.ic3_history b/ic3/.ic3_history
index 2308239..8d20fcf 100644
--- a/ic3/.ic3_history
+++ b/ic3/.ic3_history
@@ -1,37 +1,3 @@
-type(1 +i 2)
-1 +i 2 +i 3
-(1 +i 2) * (2 +i 3)
-sqrt(-1)
-sqrt(-1) * sqrt(-1)
-sqrt(-2) * sqrt(-2)
-def dt = macro (x) do
-  quote do
-    x = ^ unquote(x)
-    {x, x}
-  end
-end
-dt(200)
-dt(200 * 200)
-dt(sqrt(-1))
-def double = fn (x) { x * 2 }
-double(200)
-double(beaucoup)
-def beaucoup = 1 + 10000000000000000000000000000000000000000000
-double(beaucoup)
-dt
-double(3/4)
-1 / double(3/4)
-a = b
-a = 1
-b = a
-b = ^ a
-b = a
-a = ^ b
-a = ^ c
-a = ^ b
-b = 1
-a = ^ b
-a = c
 fib(10)
 fib(20)
 def fib = fn { (0) { 1 } (1) { 1 } (x) { if x < 0 then 1 else fib(x - 2) + fib(x - 1) end } }
@@ -82,19 +48,52 @@ defmodule Plop do
   def sq = fn (x) { x + x }
 end
 Plop.sq(4)
-+
-%C3.Operator{
-  sym: :****,                                                                        
-  symbol_value: cfn Tag "tag_mul" (Tag, Tag, Result),
-  operator_precedence: 11,
-  operator_associativity: :left
-}
-%C3.Operator{sym: :****, symbol_value: cfn Tag "tag_mul" (Tag, Tag, Result), operator_precedence: 11}
-(Void) 0
-(Integer) 0
-(Integer) 10
-type((Integer) 10)
-type((Integer) 0)
-(Sw) 10
-(Uw) 10
-def operator_muul = %C3.Operator{sym: :****, symbol_value: cfn Tag "tag_mul" (Tag, Tag, Result), operator_precedence: 11, operator_associativity: :left}
+defmodule Plop do def a = 1 end
+Plop.a
+(Sw) 123\
+(Sw) 123
+(Sw) 123/2
+(Sw) 123 / 2
+defmodule Plop do def a = 1 end
+Plop.a
+defmodule Plop do def a = 2 end
+Plop.a
+defmodule Plop do def a = 1; def double = fn (x) { x * 2 } end
+Plop.a
+Plop.double
+Plop.double(21)
+def a = 1
+a
+def double = fn (x) { x * 2 }
+double(42)
+defmodule Tiyon do
+  def a = 1
+  def double = fn (x) { x * 2 }
+  def double_tuple = macro (x) do {x, x} end
+  def double_list = macro (x) do [x, x] end
+end
+Tiyon.a
+Tiyon.double(21)
+Tiyon.double_tuple(21)
+Tiyon.double_tuple(21 + 21)
+Tiyon.double_list(21 + 21)
+[42, x] = Tiyon.double_list(21 + 21)
+[42, x] = [42, 42]
+x
+Tiyon.double_list(21 + 21) = [42, y]
+defmodule Tiyon do
+  def double_list = macro (x) do [x, x] end
+end
+Tiyon.double_list(21 + 21) = [42, y]
+defmodule Tiyon do
+  def double_list = macro (x) do [x, x] end
+end
+Tiyon.double_list(21 + 21) = y
+y
+defmodule Tiyon do
+  def double_list = macro (x) do [x, x] end
+end
+Tiyon.double_list(21 + 21) = y
+y
+Tiyon.double_list(21 + 21) = [42, z]
+z
diff --git a/libc3/cfn.c b/libc3/cfn.c
index fe94888..8c3e00f 100644
--- a/libc3/cfn.c
+++ b/libc3/cfn.c
@@ -111,6 +111,7 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
         err_write_1(" != ");
         err_inspect_pointer(arg_pointer_result);
         err_write_1("\n");
+        assert(! "cfn_apply: invalid result pointer");
         goto ko;
       }
       *dest = tmp2;
diff --git a/libc3/env.c b/libc3/env.c
index cc0abbf..b3d48ed 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -615,10 +615,8 @@ bool env_eval_equal_tag (s_env *env, bool macro, const s_tag *a,
     return true;
   }
   if (! macro &&
-      a->type == TAG_CALL &&
-      a->data.call.ident.module == &g_sym_C3 &&
-      a->data.call.ident.sym == &g_sym_operator_pin) {
-    if (! env_eval_tag(env, &a->data.call.arguments->tag, &tmp_a))
+      a->type == TAG_CALL) {
+    if (! env_eval_tag(env, a, &tmp_a))
       return false;
     if (! env_eval_equal_tag(env, macro, &tmp_a, b, dest)) {
       tag_clean(&tmp_a);
@@ -628,10 +626,8 @@ bool env_eval_equal_tag (s_env *env, bool macro, const s_tag *a,
     return true;
   }
   if (! macro &&
-      b->type == TAG_CALL &&
-      b->data.call.ident.module == &g_sym_C3 &&
-      b->data.call.ident.sym == &g_sym_operator_pin) {
-    if (! env_eval_tag(env, &b->data.call.arguments->tag, &tmp_b))
+      b->type == TAG_CALL) {
+    if (! env_eval_tag(env, b, &tmp_b))
       return false;
     if (! env_eval_equal_tag(env, macro, a, &tmp_b, dest)) {
       tag_clean(&tmp_b);