-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
d58a65f
commit 16a39e5
Showing
1 changed file
with
14 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
//\\ settings { "Sequent Generation Type" = "ssa" } | ||
|
||
class BoundedStack { | ||
var data : seq<int>; | ||
var curSize : int; | ||
var maxSize : int; | ||
|
||
function valid() : bool | ||
{ | ||
curSize >= 0 && curSize <= |data| && | ||
maxSize >= curSize && maxSize == |data| | ||
this.curSize >= 0 && this.curSize <= |this.data| && | ||
this.maxSize >= this.curSize && this.maxSize == |this.data| | ||
} | ||
|
||
method pop() returns (res : int) | ||
requires curSize > 0 && valid(); | ||
ensures curSize == old(curSize - 1) && valid() && res == data[curSize]; | ||
requires this.curSize > 0 && valid(); | ||
ensures this.curSize == old(this.curSize - 1) && valid() && res == this.data[this.curSize]; | ||
{ | ||
var res : int; | ||
res := data[curSize -1]; | ||
curSize := curSize - 1; | ||
res := this.data[this.curSize -1]; | ||
this.curSize := this.curSize - 1; | ||
} | ||
|
||
method push(n : int) | ||
requires curSize < maxSize && valid(); | ||
ensures data[curSize - 1] == n; | ||
ensures curSize == old(curSize) + 1 && valid(); | ||
requires this.curSize < this.maxSize && valid(); | ||
ensures this.data[this.curSize - 1] == n; | ||
ensures this.curSize == old(this.curSize) + 1 && valid(); | ||
{ | ||
data[curSize] := n; | ||
curSize := curSize + 1; | ||
this.data[this.curSize] := n; | ||
this.curSize := this.curSize + 1; | ||
} | ||
} | ||
} |