Commit 917553a040fb94525c36347d65fd3d3c241d97c6

Thomas de Grivel 2024-05-06T00:16:30

wip cow

diff --git a/ic3/.ic3_history b/ic3/.ic3_history
index 625e501..2590ffc 100644
--- a/ic3/.ic3_history
+++ b/ic3/.ic3_history
@@ -1,10 +1,3 @@
-defmodule Plop do end
-quote Plop
-quote_cfn Plop
-(Sym) "Abc"
-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
@@ -97,3 +90,10 @@ C3.reverse
 reverse
 def reverse = fn (x) { List.reverse(x) }
 reverse
+cow 1
+type(cow 1)
+cow 1
+type(cow 1)
+a = cow 1
+a
+type(a)
diff --git a/libc3/cow.c b/libc3/cow.c
index f66edb6..376befa 100644
--- a/libc3/cow.c
+++ b/libc3/cow.c
@@ -158,8 +158,10 @@ s_cow * cow_new_copy (const s_cow *src)
 const s_tag * cow_ro (const s_cow *cow)
 {
   assert(cow);
-  if (cow->w_is_set)
+  if (cow->w_is_set) {
+    // FIXME: get a read lock ?
     return &cow->w;
+  }
   return &cow->r;
 }
 
diff --git a/libc3/env.c b/libc3/env.c
index bdc1f5a..617bb41 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -578,6 +578,24 @@ bool env_eval_complex (s_env *env, const s_complex *c, s_tag *dest)
   return true;
 }
 
+bool env_eval_cow (s_env *env, const s_cow *cow, s_tag *dest)
+{
+  s_cow *tmp = NULL;
+  assert(env);
+  assert(cow);
+  assert(dest);
+  tmp = alloc(sizeof(s_cow));
+  if (! tmp)
+    return false;
+  if (! env_eval_tag(env, cow_ro(cow), &tmp->r)) {
+    free(tmp);
+    return false;
+  }
+  dest->type = TAG_COW;
+  dest->data.cow = tmp;
+  return true;
+}
+
 bool env_eval_equal_list (s_env *env, bool macro, const s_list *a,
                           const s_list *b, s_list **dest)
 {
@@ -1775,7 +1793,7 @@ bool env_eval_tag (s_env *env, const s_tag *tag, s_tag *dest)
   case TAG_COMPLEX:
     return env_eval_complex(env, tag->data.complex, dest);
   case TAG_COW:
-    return env_eval_tag(env, cow_ro(tag->data.cow), dest);
+    return env_eval_cow(env, tag->data.cow, dest);
   case TAG_FN:
     return env_eval_fn(env, &tag->data.fn, dest);
   case TAG_IDENT:
diff --git a/libc3/env.h b/libc3/env.h
index 53ea7ca..abc3cd5 100644
--- a/libc3/env.h
+++ b/libc3/env.h
@@ -65,6 +65,7 @@ bool          env_eval_call_fn_args (s_env *env, const s_fn *fn,
 bool          env_eval_call_resolve (s_env *env, s_call *call);
 bool          env_eval_complex (s_env *env, const s_complex *c,
                                 s_tag *dest);
+bool          env_eval_cow (s_env *env, const s_cow *cow, s_tag *dest);
 bool          env_eval_equal_block (s_env *env, bool macro,
                                     const s_block *a, const s_block *b,
                                     s_block *dest);