--  The checking allocator (proof-enclaves.md 8.6), in an advisory run where what does not prove
--  is checked as the program runs: an enclave body that reads a
--  cell after freeing it stops with B6011, not a corruption
package Stacks
  with Annotate => (Verada, Enclave)
is
   type Stack is limited private
     with Default_Initial_Condition => Size (Stack) = 0;
   function Model (S : Stack) return Natural with Ghost;
   function Size (S : Stack) return Natural
     with Post => Size'Result = Model (S);
   procedure Push (S : in out Stack; X : Integer)
     with Pre => Size (S) < Natural'Last, Post => Size (S) = Size (S)'Old + 1;
   procedure Pop (S : in out Stack; X : out Integer)
     with Pre => Size (S) > 0, Post => Size (S) = Size (S)'Old - 1;
private
   type Node;
   type Node_Ptr is access Node;
   type Node is record
      Value : Integer;
      Next : Node_Ptr;
   end record;
   type Stack is limited record
      Top : Node_Ptr;
      Count : Natural := 0;
   end record
     with Type_Invariant => (Stack.Count = 0) = (Stack.Top = null);
   function Model (S : Stack) return Natural is (S.Count);
   function Size (S : Stack) return Natural is (S.Count);
end Stacks;
