-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Benjamin Pierce
committed
Jun 16, 2024
1 parent
fb2cfe1
commit d9e3445
Showing
11 changed files
with
115 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
/*@ | ||
predicate (datatype seq) IntQueuePtr (pointer q) { | ||
take H = Owned<struct int_queue>(q); | ||
assert ( (is_null(H.front) && is_null(H.back)) | ||
|| (!is_null(H.front) && !is_null(H.back))); | ||
take Q = IntQueueFB(H.front, H.back); | ||
return Q; | ||
take Q = Owned<struct int_queue>(q); | ||
assert ( (is_null(Q.front) && is_null(Q.back)) | ||
|| (!is_null(Q.front) && !is_null(Q.back))); | ||
take L = IntQueueFB(Q.front, Q.back); | ||
return L; | ||
} | ||
@*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/*@ | ||
predicate (datatype seq) IntQueueAux (pointer h, pointer t) { | ||
if (ptr_eq(h,t)) { | ||
predicate (datatype seq) IntQueueAux (pointer f, pointer b) { | ||
if (ptr_eq(f,b)) { | ||
return Seq_Nil{}; | ||
} else { | ||
take C = Owned<struct int_queueCell>(h); | ||
assert (!is_null(C.next)); | ||
take TL = IntQueueAux(C.next, t); | ||
return Seq_Cons { head: C.first, tail: TL }; | ||
take F = Owned<struct int_queueCell>(f); | ||
assert (!is_null(F.next)); | ||
take B = IntQueueAux(F.next, b); | ||
return Seq_Cons{head: F.first, tail: B}; | ||
} | ||
} | ||
@*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
/*@ | ||
lemma tl_snoc (pointer front, pointer back, datatype seq before, i32 popped) | ||
lemma tl_snoc (pointer front, pointer back, i32 x) | ||
requires | ||
take T = Owned<struct int_queueCell>(back); | ||
is_null(T.next); | ||
take Q = IntQueueAux(front, back); | ||
let after = snoc(Q, T.first); | ||
before == snoc (Seq_Cons{head: popped, tail: Q}, T.first); | ||
take B = Owned<struct int_queueCell>(back); | ||
is_null(B.next); | ||
let after = snoc (Q, B.first); | ||
let before = snoc (Seq_Cons{head: x, tail: Q}, B.first); | ||
ensures | ||
take T2 = Owned<struct int_queueCell>(back); | ||
T == T2; | ||
is_null(T.next); | ||
take Q2 = IntQueueAux(front, back); | ||
Q == Q2; | ||
take NewQ = IntQueueAux(front, back); | ||
Q == NewQ; | ||
take NewB = Owned<struct int_queueCell>(back); | ||
B == NewB; | ||
after == tl(before); | ||
popped == hd(before); | ||
x == hd(before); | ||
@*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
// NEEDS UPDATING? | ||
|
||
#include "queue_headers.h" | ||
|
||
int IntQueue_pop (struct int_queue *q) | ||
{ | ||
struct int_queueCell* h = q->front; | ||
struct int_queueCell* t = q->back; | ||
if (h == t) { | ||
if (h == q->back) { | ||
int x = h->first; | ||
freeIntQueueCell(h); | ||
q->front = 0; | ||
q->back = 0; | ||
return x; | ||
} else { | ||
int x = h->first; | ||
struct int_queueCell* n = h->next; | ||
q->front = n; | ||
q->front = h->next; | ||
freeIntQueueCell(h); | ||
return x; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
/*@ | ||
lemma aux_induction(pointer front, pointer prev, pointer back, | ||
datatype seq before, i32 prev_pushed) | ||
requires | ||
take Prev = Owned<struct int_queueCell>(prev); | ||
take Q = IntQueueAux(front, prev); | ||
ptr_eq(Prev.next, back); // sanity check | ||
Prev.first == prev_pushed; // sanity check | ||
snoc(Q, prev_pushed) == before; // sanity check | ||
ensures | ||
take Q2 = IntQueueAux(front, back); | ||
before == Q2; | ||
lemma push_lemma (pointer front, pointer p) | ||
requires | ||
take Q = IntQueueAux(front, p); | ||
take P = Owned<struct int_queueCell>(p); | ||
ensures | ||
take NewQ = IntQueueAux(front, P.next); | ||
NewQ == snoc(Q, P.first); | ||
@*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters