cbv_of_args.v 1.84 KB
Newer Older
Léon Gondelman 's avatar
Léon Gondelman committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
From iris_c.vcgen Require Import proofmode.

Section Incr_Ptr.
(* In the program below, after the execution of 'main',
the global pointer 'l' has the value 43. *)

(* // C

   void incr(int* x) {
     *x = *x + 1;
   }

   int* l = 42;

   int main() {
     incr(&l);
     return 0
   }
*)

(* // λMC (paper version)

   incr(x) {
     *x = *x + 1;
   }

   l <- alloc 42;

   main() {
     incr(l);
     0;
   }
*)

Let incr : val := λᶜ "x",
  (c_ret "x")  = ∗ᶜ (c_ret "x") + 1 ; ().

Let main : val :=  λᶜ "()",
  "r" ←ᶜ alloc (1, 42) ;
  call (c_ret incr) (c_ret "r") ;
  0.

Let main_spec `{cmonadG Σ}  :
  CWP main #() {{ v, v = #0   ptr, ptr C #43%nat }}%I.
Proof.
  iIntros.
  iApply cwp_fun; simpl.
  vcg.
  iIntros (ptr) "_ _ Hptr !> _ !>".
  iApply cwp_fun; simpl.
  vcg.
  iIntros "Hptr !>". iSplit; eauto.
  vcg_continue.
  eauto with iFrame.
Qed.

End Incr_Ptr.

Section Incr_Int.
(* In the program below, after the execution of 'main',
the global pointer 'l' has the value 42. *)

(* // C

   void incr(int x) {
     x = x + 1;
   }

   int* l = 42;

   int main() {
     incr(l);
     return 0
   }
*)

(* // λMC (paper version)

   incr(x) {
     r <- alloc x ;
     *r = *r + 1;
   }

   l <- alloc 42 ;

   main() {
     incr(∗l);
     0
   }
*)

Let incr : val := λᶜ "x",
  "r" mut (c_ret "x") ;
  (c_ret "r")  = ∗ᶜ (c_ret "r") + 1 ; ().


Let main : val :=  λᶜ "()",
  "r" ←ᶜ alloc (1, 42) ;
  call (c_ret incr) ( ∗ᶜ c_ret "r") ;
  0.

Let main_spec `{cmonadG Σ}  :
  CWP main #() {{ v, v = #0   ptr, ptr C #42%nat }}%I.
Proof.
  iIntros.
  iApply cwp_fun; simpl.
  vcg.
  iIntros (ptr) "_ _ Hptr !> _ !>".
  iApply cwp_fun; simpl.
  vcg.
  iIntros (?) "Hptr !>". iSplit; eauto.
  vcg_continue.
  eauto with iFrame.
Qed.