Advertisement
SimonWright

SPARK vs PO

Aug 30th, 2016
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.28 KB | None | 0 0
  1. --  po.gpr
  2. project PO IS
  3.  
  4.    for Object_Dir use ".build";
  5.  
  6.    package Builder is
  7.       for Global_Configuration_Pragmas use "gnat.adc";
  8.    end Builder;
  9.  
  10. end PO;
  11.  
  12. --  gnat.adc
  13. pragma Partition_Elaboration_Policy (Sequential);
  14. pragma Profile (Ravenscar);
  15.  
  16. --  po.ads
  17. package PO
  18. with Spark_Mode => On,
  19.   Abstract_State => State,
  20.   Initializes => State
  21. is
  22.  
  23.    procedure Set (Value : Integer)
  24.      with Depends => (State =>+ Value);
  25.  
  26.    procedure Get (Value : out Integer)
  27.      with Depends => (Value => State);
  28.  
  29. end PO;
  30.  
  31. --  po.adb
  32. package body PO
  33. with Refined_State => (State => (Protected_Value,
  34.                                  Impl))
  35. is
  36.  
  37.    Protected_Value : Integer := 0
  38.      with Volatile;
  39.  
  40.    protected Impl is
  41.       procedure Set (Value : Integer);
  42.       procedure Get (Value : out Integer);
  43.    end Impl;
  44.  
  45.    procedure Set (Value : Integer) is
  46.    begin
  47.       Impl.Set (Value);
  48.    end Set;
  49.  
  50.    procedure Get (Value : out Integer) is
  51.    begin
  52.       Impl.Get (Value);
  53.    end Get;
  54.  
  55.    protected body Impl is
  56.       procedure Set (Value : Integer) is
  57.       begin
  58.          Protected_Value := Value;
  59.       end Set;
  60.  
  61.       procedure Get (Value : out Integer) is
  62.       begin
  63.          Value := Protected_Value;
  64.       end Get;
  65.    end Impl;
  66.  
  67. end PO;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement