summaryrefslogtreecommitdiff
path: root/tests/coq/demo/Demo.v
blob: 1cccbedae3577ca8deef1ce04a4091946939583e (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
(** THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS *)
(** [demo] *)
Require Import Primitives.
Import Primitives.
Require Import Coq.ZArith.ZArith.
Require Import List.
Import ListNotations.
Local Open Scope Primitives_scope.
Module Demo.

(** [demo::choose]:
    Source: 'tests/src/demo.rs', lines 6:0-6:70 *)
Definition choose
  (T : Type) (b : bool) (x : T) (y : T) : result (T * (T -> result (T * T))) :=
  if b
  then let back := fun (ret : T) => Ok (ret, y) in Ok (x, back)
  else let back := fun (ret : T) => Ok (x, ret) in Ok (y, back)
.

(** [demo::mul2_add1]:
    Source: 'tests/src/demo.rs', lines 14:0-14:31 *)
Definition mul2_add1 (x : u32) : result u32 :=
  i <- u32_add x x; u32_add i 1%u32
.

(** [demo::use_mul2_add1]:
    Source: 'tests/src/demo.rs', lines 18:0-18:43 *)
Definition use_mul2_add1 (x : u32) (y : u32) : result u32 :=
  i <- mul2_add1 x; u32_add i y
.

(** [demo::incr]:
    Source: 'tests/src/demo.rs', lines 22:0-22:31 *)
Definition incr (x : u32) : result u32 :=
  u32_add x 1%u32.

(** [demo::use_incr]:
    Source: 'tests/src/demo.rs', lines 26:0-26:17 *)
Definition use_incr : result unit :=
  x <- incr 0%u32; x1 <- incr x; _ <- incr x1; Ok tt
.

(** [demo::CList]
    Source: 'tests/src/demo.rs', lines 35:0-35:17 *)
Inductive CList_t (T : Type) :=
| CList_CCons : T -> CList_t T -> CList_t T
| CList_CNil : CList_t T
.

Arguments CList_CCons { _ }.
Arguments CList_CNil { _ }.

(** [demo::list_nth]:
    Source: 'tests/src/demo.rs', lines 40:0-40:56 *)
Fixpoint list_nth (T : Type) (n : nat) (l : CList_t T) (i : u32) : result T :=
  match n with
  | O => Fail_ OutOfFuel
  | S n1 =>
    match l with
    | CList_CCons x tl =>
      if i s= 0%u32 then Ok x else (i1 <- u32_sub i 1%u32; list_nth T n1 tl i1)
    | CList_CNil => Fail_ Failure
    end
  end
.

(** [demo::list_nth_mut]:
    Source: 'tests/src/demo.rs', lines 55:0-55:68 *)
Fixpoint list_nth_mut
  (T : Type) (n : nat) (l : CList_t T) (i : u32) :
  result (T * (T -> result (CList_t T)))
  :=
  match n with
  | O => Fail_ OutOfFuel
  | S n1 =>
    match l with
    | CList_CCons x tl =>
      if i s= 0%u32
      then let back := fun (ret : T) => Ok (CList_CCons ret tl) in Ok (x, back)
      else (
        i1 <- u32_sub i 1%u32;
        p <- list_nth_mut T n1 tl i1;
        let (t, list_nth_mut_back) := p in
        let back :=
          fun (ret : T) => tl1 <- list_nth_mut_back ret; Ok (CList_CCons x tl1)
          in
        Ok (t, back))
    | CList_CNil => Fail_ Failure
    end
  end
.

(** [demo::list_nth_mut1]: loop 0:
    Source: 'tests/src/demo.rs', lines 70:0-79:1 *)
Fixpoint list_nth_mut1_loop
  (T : Type) (n : nat) (l : CList_t T) (i : u32) :
  result (T * (T -> result (CList_t T)))
  :=
  match n with
  | O => Fail_ OutOfFuel
  | S n1 =>
    match l with
    | CList_CCons x tl =>
      if i s= 0%u32
      then let back := fun (ret : T) => Ok (CList_CCons ret tl) in Ok (x, back)
      else (
        i1 <- u32_sub i 1%u32;
        p <- list_nth_mut1_loop T n1 tl i1;
        let (t, back) := p in
        let back1 := fun (ret : T) => tl1 <- back ret; Ok (CList_CCons x tl1)
          in
        Ok (t, back1))
    | CList_CNil => Fail_ Failure
    end
  end
.

(** [demo::list_nth_mut1]:
    Source: 'tests/src/demo.rs', lines 70:0-70:77 *)
Definition list_nth_mut1
  (T : Type) (n : nat) (l : CList_t T) (i : u32) :
  result (T * (T -> result (CList_t T)))
  :=
  list_nth_mut1_loop T n l i
.

(** [demo::i32_id]:
    Source: 'tests/src/demo.rs', lines 81:0-81:28 *)
Fixpoint i32_id (n : nat) (i : i32) : result i32 :=
  match n with
  | O => Fail_ OutOfFuel
  | S n1 =>
    if i s= 0%i32
    then Ok 0%i32
    else (i1 <- i32_sub i 1%i32; i2 <- i32_id n1 i1; i32_add i2 1%i32)
  end
.

(** [demo::list_tail]:
    Source: 'tests/src/demo.rs', lines 89:0-89:64 *)
Fixpoint list_tail
  (T : Type) (n : nat) (l : CList_t T) :
  result ((CList_t T) * (CList_t T -> result (CList_t T)))
  :=
  match n with
  | O => Fail_ OutOfFuel
  | S n1 =>
    match l with
    | CList_CCons t tl =>
      p <- list_tail T n1 tl;
      let (c, list_tail_back) := p in
      let back :=
        fun (ret : CList_t T) =>
          tl1 <- list_tail_back ret; Ok (CList_CCons t tl1) in
      Ok (c, back)
    | CList_CNil => Ok (CList_CNil, Ok)
    end
  end
.

(** Trait declaration: [demo::Counter]
    Source: 'tests/src/demo.rs', lines 98:0-98:17 *)
Record Counter_t (Self : Type) := mkCounter_t {
  Counter_t_incr : Self -> result (usize * Self);
}.

Arguments mkCounter_t { _ }.
Arguments Counter_t_incr { _ }.

(** [demo::{(demo::Counter for usize)}::incr]:
    Source: 'tests/src/demo.rs', lines 103:4-103:31 *)
Definition counterUsize_incr (self : usize) : result (usize * usize) :=
  self1 <- usize_add self 1%usize; Ok (self, self1)
.

(** Trait implementation: [demo::{(demo::Counter for usize)}]
    Source: 'tests/src/demo.rs', lines 102:0-102:22 *)
Definition CounterUsize : Counter_t usize := {|
  Counter_t_incr := counterUsize_incr;
|}.

(** [demo::use_counter]:
    Source: 'tests/src/demo.rs', lines 110:0-110:59 *)
Definition use_counter
  (T : Type) (counterInst : Counter_t T) (cnt : T) : result (usize * T) :=
  counterInst.(Counter_t_incr) cnt
.

End Demo.