Commit 1d333c52790ea3f581d29cc68f84dbf1900696eb

Thomas de Grivel 2024-02-02T17:37:48

fix array quote/unquote

diff --git a/ic3/.ic3_history b/ic3/.ic3_history
index cdbbd1b..c0703f6 100644
--- a/ic3/.ic3_history
+++ b/ic3/.ic3_history
@@ -40,3 +40,8 @@ hello("Thomas")
 quote "abc"
 quote "abc #{unquote name} !"
 quote "abc #{name} !"
+(Integer[]) {1, 2}
+a = (Integer[]) {1, 2}
+quote (Integer[]) {1, 2}
+quote (Integer[]) {unquote 1, unquote 2}
+quote (Integer[]) {unquote 1 + 1, unquote 2 + 2, 3 + 3}
diff --git a/libc3/array.h b/libc3/array.h
index 8025bd8..6d5515a 100644
--- a/libc3/array.h
+++ b/libc3/array.h
@@ -22,6 +22,7 @@ s_array * array_init (s_array *a, const s_sym *array_type,
 s_array * array_init_1 (s_array *a, const char *p);
 s_array * array_init_cast (s_array *a, const s_tag *tag);
 s_array * array_init_copy (s_array *a, const s_array *src);
+s_array * array_init_copy_shallow (s_array *a, const s_array *src);
 s_array * array_init_void (s_array *array);
 
 /* Observers */
diff --git a/libc3/env.c b/libc3/env.c
index ea6a355..ebc53f8 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -684,6 +684,8 @@ bool env_eval_quote_array (s_env *env, const s_array *array,
       return false;
     return true;
   }
+  if (! array_init_copy_shallow(&tmp, array))
+    return false;
   tag = array->tags;
   tmp_tag = tmp.tags = calloc(tmp.count, sizeof(s_tag));
   i = 0;
@@ -723,6 +725,7 @@ bool env_eval_quote_call (s_env *env, const s_call *call, s_tag *dest)
     *tmp_arg_last = list_new(NULL);
     if (! env_eval_quote_tag(env, &arg->tag, &(*tmp_arg_last)->tag))
       goto ko;
+    tmp_arg_last = &(*tmp_arg_last)->next.data.list;
     arg = list_next(arg);
   }
   // TODO: copy cfn and fn ?
@@ -745,6 +748,8 @@ bool env_eval_quote_list (s_env *env, const s_list *list, s_tag *dest)
   assert(dest);
   while (list) {
     *tail = list_new(NULL);
+    if (! *tail)
+      goto ko;
     if (! env_eval_quote_tag(env, &list->tag, &(*tail)->tag))
       goto ko;
     next = list_next(list);