Skip to content

Commit

Permalink
making this references explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
mattulbrich committed May 21, 2019
1 parent d58a65f commit 16a39e5
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions doc/examples/stackExample/stack.dfy
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;
}
}
}

0 comments on commit 16a39e5

Please sign in to comment.