File size: 1,323 Bytes
bff4ec7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/*@ Extern Coq (sll :: *) */
/*@ Extern Coq
      (stack_capacity : Z)
      (sll_empty : sll)
      (sll_cons : Z -> sll -> sll)
      (sll_from_array : list Z -> sll)
      (store_stack : Z -> sll -> Z -> Assertion)
      (BuildStackPrefix : sll -> list Z -> Z -> Prop)
      (StackConcreteView : sll -> list Z -> Z -> Prop)
 */
/*@ Import Coq Require Import PVbench.Data_structures.stack.rocq.spec_lib */

void push(int *stack, int n, int x)
/*@ With (before : sll)
    Require
      n < stack_capacity &&
      store_stack(stack, before, n) *
      IntArray::undef_seg(stack, n, n + 1)
    Ensure
      store_stack(stack, sll_cons(x, before), n + 1)
 */
{

  stack[n] = x;

}

int pop(int *stack, int n)
/*@ With (top : Z) (rest : sll)
    Require
      1 <= n &&
      store_stack(stack, sll_cons(top, rest), n)
    Ensure
      __return == top &&
      store_stack(stack, rest, n - 1) *
      IntArray::undef_seg(stack, n - 1, n)
 */
{

  int ret = stack[n - 1];

  return ret;
}

void build(int *stack, int n)
/*@ With (input : list Z)
    Require
      0 <= n &&
      n <= stack_capacity &&
      Zlength(input) == n &&
      IntArray::full(stack, n, input)
    Ensure
      store_stack(stack, sll_from_array(input), n)
 */
{

  for (int i = 1; i < n; ++i) {
    int x = stack[i];

    push(stack, i, x);

  }

}