Commit 7271f0fcbbf5ae8cd4afb20aa6734341d013d551

Thomas de Grivel 2023-09-23T08:44:38

wip integer arrays

diff --git a/libc3/integer.c b/libc3/integer.c
index 4e5848e..b5eecd0 100644
--- a/libc3/integer.c
+++ b/libc3/integer.c
@@ -127,7 +127,7 @@ s_integer * integer_cast (const s_tag *tag, s_integer *dest)
   case TAG_IDENT:
     goto ko;
   case TAG_INTEGER:
-    return integer_copy(&tag->data.integer, dest);
+    return integer_init_copy(dest, &tag->data.integer);
   case TAG_SW:
     return integer_init_sw(dest, tag->data.sw);
   case TAG_S64:
@@ -182,6 +182,18 @@ s_integer * integer_copy (const s_integer *a, s_integer *dest)
   return dest;
 }
 
+s_integer * integer_init_copy (s_integer *i, const s_integer *a)
+{
+  sw r;
+  assert(a);
+  assert(i);
+  if ((r = mp_init(&i->mp_int)) != MP_OKAY)
+    errx(1, "integer_init_copy: %s", mp_error_to_string(r));
+  if ((r = mp_copy(&a->mp_int, &i->mp_int)) != MP_OKAY)
+    errx(1, "integer_init_copy: %s", mp_error_to_string(r));
+  return i;
+}
+
 s_integer * integer_div (const s_integer *a, const s_integer *b,
                          s_integer *dest)
 {
diff --git a/libc3/integer.h b/libc3/integer.h
index 67b5eeb..f21c2e0 100644
--- a/libc3/integer.h
+++ b/libc3/integer.h
@@ -28,6 +28,7 @@
 /* Stack allocation compatible functions */
 s_integer * integer_init (s_integer *i);
 s_integer * integer_init_1 (s_integer *i, const s8 *p);
+s_integer * integer_init_copy (s_integer *i, const s_integer *x);
 s_integer * integer_init_f32 (s_integer *a, f32 x);
 s_integer * integer_init_f64 (s_integer *a, f64 x);
 s_integer * integer_init_s8 (s_integer *a, s8 x);
diff --git a/test/ic3/array.in b/test/ic3/array.in
index e7f9de3..0a81d8f 100644
--- a/test/ic3/array.in
+++ b/test/ic3/array.in
@@ -101,3 +101,9 @@ k = (U64) { 255 + 1, 255 + 2, 255 + 3 }
 k[0]
 k[1]
 k[2]
+quote (Integer) { 1000000000000000000000000000000001,
+                  2000000000000000000000000000000002 }
+l = (Integer) { 1000000000000000000000000000000001,
+                2000000000000000000000000000000002 }
+l[0]
+l[1]