--  Ada.Numerics.Big_Numbers.Big_Integers (RM A.5.6). A Big_Integer is an integer of any size:
--  the prover reasons about its values as the mathematical integers, and the code computes
--  them exactly, with as many digits as they need. Only memory limits a value: an operation
--  whose result memory cannot hold raises Storage_Error, as an allocation does. A copy shares
--  its value (which never changes), counted by the run time, and the last holder frees it.
package Ada.Numerics.Big_Numbers.Big_Integers is
   type Big_Integer is private
     with Finalizable => (Adjust => Share, Finalize => Release, Relaxed_Finalization => True);

   function To_Big_Integer (Arg : Integer) return Big_Integer
     with Global => null;

   function In_Range (Arg, Low, High : Big_Integer) return Boolean
     with Global => null;

   function To_Integer (Arg : Big_Integer) return Integer
     with Global => null,
          Pre => In_Range (Arg, To_Big_Integer (Integer'First), To_Big_Integer (Integer'Last));

   --  the image, as Integer'Image: a space or a minus sign, then the digits
   function To_String (Arg : Big_Integer) return String
     with Global => null;

   function "=" (L, R : Big_Integer) return Boolean with Global => null;
   function "<" (L, R : Big_Integer) return Boolean with Global => null;
   function "<=" (L, R : Big_Integer) return Boolean with Global => null;
   function ">" (L, R : Big_Integer) return Boolean with Global => null;
   function ">=" (L, R : Big_Integer) return Boolean with Global => null;

   function "-" (L : Big_Integer) return Big_Integer with Global => null;
   function "abs" (L : Big_Integer) return Big_Integer with Global => null;
   function "+" (L, R : Big_Integer) return Big_Integer with Global => null;
   function "-" (L, R : Big_Integer) return Big_Integer with Global => null;
   function "*" (L, R : Big_Integer) return Big_Integer with Global => null;
   function "/" (L, R : Big_Integer) return Big_Integer
     with Global => null, Pre => R /= To_Big_Integer (0);
   function "mod" (L, R : Big_Integer) return Big_Integer
     with Global => null, Pre => R /= To_Big_Integer (0);
   function "rem" (L, R : Big_Integer) return Big_Integer
     with Global => null, Pre => R /= To_Big_Integer (0);
   function "**" (L : Big_Integer; R : Natural) return Big_Integer with Global => null;
   --  a copy holds the value too (the run time counts a value's holders, rt/bignum.c)
   procedure Share (X : in out Big_Integer)
     with Import, Convention => Ada, External_Name => "verada_rt_big_adjust",
          Global => null, Post => X = X'Old;

   --  X no longer holds its value (the last holder frees it)
   procedure Release (X : in out Big_Integer)
     with Import, Convention => Ada, External_Name => "verada_rt_big_finalize",
          Global => null;
private
   --  the model is the mathematical integers; Verada's prover, interpreter and code generator
   --  know these operations (the code uses the run time's bignum.c, where a value is a handle)
   type Big_Integer is null record;
end Ada.Numerics.Big_Numbers.Big_Integers;
