Skip to content

Commit ee9b68e

Browse files
committed
Add exception declaration, raise, and update logic
1 parent 4fc8b63 commit ee9b68e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1626
-448
lines changed

examples/exception.ec

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
require import AllCore.
2+
3+
exception assume.
4+
exception assert.
5+
6+
module M' ={
7+
proc truc (x:int) : int = {
8+
raise (x = 3) assume;
9+
x <- 1;
10+
if (x = 3) {
11+
raise assume;
12+
}
13+
if (x=3) {
14+
raise assert;
15+
}
16+
return x;
17+
}
18+
}.
19+
20+
print M'.
21+
22+
(* Missing ; after printing raise *)
23+
24+
op p7: bool.
25+
op p1: bool.
26+
op p2: bool.
27+
op p3: bool.
28+
29+
lemma assume_assert :
30+
hoare [M'.truc : p7 ==> p3 | assume:p1 |assert: p2 ].
31+
proof.
32+
admitted.
33+
34+
op p8: bool.
35+
op q1: bool.
36+
op q2: bool.
37+
op q3: bool.
38+
39+
lemma assert_assume :
40+
hoare [M'.truc : p8 ==> q3 | assume:q1 |assert: q2 ].
41+
proof.
42+
admitted.
43+
44+
op p4: bool.
45+
op p5: bool.
46+
op p6: bool.
47+
op p9: bool.
48+
lemma assert_assume' :
49+
hoare [M'.truc : p9 ==> p4 | assume:p6 |assert: p5 ].
50+
proof.
51+
conseq (assume_assert) (assert_assume).
52+
+ admit.
53+
+ admit.
54+
qed.
55+
56+
exception e1.
57+
exception e2.
58+
exception e3.
59+
60+
module M ={
61+
proc f1 (x:int) : int = {
62+
raise (x = 3) e1;
63+
x <- 5;
64+
return x;
65+
}
66+
67+
proc f2 (x:int) : int = {
68+
if (x = 3) {
69+
x <- x;
70+
x <@ f1(x);
71+
} else {
72+
x <@ f1(x);
73+
}
74+
return x;
75+
}
76+
}.
77+
78+
79+
(* Multiple time post for the same exception *)
80+
81+
lemma l_f1 (_x: int):
82+
hoare [M.f1 : _x = x ==> (4 < res) | e1:_x = 3 | e2: p5 | p4].
83+
proof.
84+
proc.
85+
conseq (: _ ==> x = 5 | e1: _x = 0 | e2: p2 | p3).
86+
+ admit.
87+
+ admit.
88+
qed.
89+
90+
lemma l_f2 (_x: int):
91+
hoare [M.f2 : p9 ==> p4 | e1: p2 | e2:p1 | e3: p6 | p1 ].
92+
proof.
93+
proc.
94+
if.
95+
+ call (: p5 ==> p3 | e1 : p9 | e2: p7 | p8).
96+
+ admit.
97+
admit.
98+
call (l_f1 _x).
99+
admit.
100+
qed.
101+
102+
103+
module M1 ={
104+
var i:int
105+
106+
proc f1 (x:int) : int = {
107+
i <- 0;
108+
raise e2;
109+
return x;
110+
}
111+
112+
proc f2 (x:int) : int = {
113+
i <- 1;
114+
x <@ f1(x);
115+
return x;
116+
}
117+
}.
118+
119+
120+
lemma test (_x: int):
121+
hoare [M1.f2 : true ==> true |e2: M1.i = 0].
122+
proof.
123+
proc.
124+
call (: true ==> true | e2 : M1.i = 0).
125+
proc.
126+
wp. auto.
127+
auto.
128+
qed.
129+
130+
lemma test2 (_x: int):
131+
hoare [M1.f1 : true ==> true |e2: M1.i = 0].
132+
proof.
133+
proc.
134+
conseq (: _ ==> _ | e2: M1.i = 0).
135+
auto.
136+
qed.
137+
138+
module M2 ={
139+
140+
proc f1 (x:int) : int = {
141+
142+
return x;
143+
}
144+
145+
proc f2 (x:int) : int = {
146+
x <- x + 1;
147+
x <@ f1(x);
148+
return x;
149+
}
150+
}.
151+
152+
153+
lemma test3 (_x: int):
154+
hoare [M2.f1 : _x = x ==> res = _x | e2 : _x = 0].
155+
proof.
156+
proc.
157+
auto.
158+
qed.
159+
160+
lemma test4 (_x: int):
161+
hoare [M2.f2 : _x = x ==> res = _x + 1 | e2 : _x + 1= 0 ].
162+
proof.
163+
proc.
164+
(* call (test3 (_x )). *)
165+
ecall(test3 x).
166+
auto.
167+
qed.
168+
169+
170+
171+
172+
173+
174+
175+
(* module M2 ={ *)
176+
177+
(* proc f1 (x:int) : int = { *)
178+
(* if (x = 0) {raise e2; } *)
179+
(* return x; *)
180+
(* } *)
181+
182+
(* proc f2 (x:int) : int = { *)
183+
(* x <- x + 1; *)
184+
(* x <@ f1(x); *)
185+
(* return x; *)
186+
(* } *)
187+
(* }. *)
188+
189+
190+
(* lemma test3 (_x: int): *)
191+
(* hoare [M2.f1 : _x = x ==> res = _x | e2 : _x = 0]. *)
192+
(* proof. *)
193+
(* proc. *)
194+
(* auto. *)
195+
(* qed. *)
196+
197+
(* lemma test4 (_x: int): *)
198+
(* hoare [M2.f2 : _x = x ==> res = _x + 1 | e2 : _x = 0]. *)
199+
(* proof. *)
200+
(* proc. *)
201+
(* seq 1 : true. *)
202+
(* admit. *)
203+
(* ecall(test3 x). *)
204+
(* auto. *)
205+
(* qed. *)
206+

0 commit comments

Comments
 (0)