summaryrefslogtreecommitdiff
path: root/tests/coq/misc/External_Funs.v
blob: f18bbd1feaaa1b11dccf68ba48f78e5e433c8009 (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
(** THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS *)
(** [external]: function definitions *)
Require Import Primitives.
Import Primitives.
Require Import Coq.ZArith.ZArith.
Local Open Scope Primitives_scope.
Require Export External_Types.
Import External_Types.
Require Export External_Opaque.
Import External_Opaque.
Module External_Funs.

(** [external::swap]: forward function *)
Definition swap_fwd
  (T : Type) (x : T) (y : T) (st : state) : result (state * unit) :=
  p <- core_mem_swap_fwd T x y st;
  let (st0, _) := p in
  p0 <- core_mem_swap_back0 T x y st st0;
  let (st1, _) := p0 in
  p1 <- core_mem_swap_back1 T x y st st1;
  let (st2, _) := p1 in
  Return (st2, tt)
.

(** [external::swap]: backward function 0 *)
Definition swap_back
  (T : Type) (x : T) (y : T) (st : state) (st0 : state) :
  result (state * (T * T))
  :=
  p <- core_mem_swap_fwd T x y st;
  let (st1, _) := p in
  p0 <- core_mem_swap_back0 T x y st st1;
  let (st2, x0) := p0 in
  p1 <- core_mem_swap_back1 T x y st st2;
  let (_, y0) := p1 in
  Return (st0, (x0, y0))
.

(** [external::test_new_non_zero_u32]: forward function *)
Definition test_new_non_zero_u32_fwd
  (x : u32) (st : state) : result (state * Core_num_nonzero_non_zero_u32_t) :=
  p <- core_num_nonzero_non_zero_u32_new_fwd x st;
  let (st0, opt) := p in
  core_option_option_unwrap_fwd Core_num_nonzero_non_zero_u32_t opt st0
.

(** [external::test_vec]: forward function *)
Definition test_vec_fwd : result unit :=
  let v := vec_new u32 in _ <- vec_push_back u32 v 0%u32; Return tt
.

(** Unit test for [external::test_vec] *)
Check (test_vec_fwd )%return.

(** [external::custom_swap]: forward function *)
Definition custom_swap_fwd
  (T : Type) (x : T) (y : T) (st : state) : result (state * T) :=
  p <- core_mem_swap_fwd T x y st;
  let (st0, _) := p in
  p0 <- core_mem_swap_back0 T x y st st0;
  let (st1, x0) := p0 in
  p1 <- core_mem_swap_back1 T x y st st1;
  let (st2, _) := p1 in
  Return (st2, x0)
.

(** [external::custom_swap]: backward function 0 *)
Definition custom_swap_back
  (T : Type) (x : T) (y : T) (st : state) (ret : T) (st0 : state) :
  result (state * (T * T))
  :=
  p <- core_mem_swap_fwd T x y st;
  let (st1, _) := p in
  p0 <- core_mem_swap_back0 T x y st st1;
  let (st2, _) := p0 in
  p1 <- core_mem_swap_back1 T x y st st2;
  let (_, y0) := p1 in
  Return (st0, (ret, y0))
.

(** [external::test_custom_swap]: forward function *)
Definition test_custom_swap_fwd
  (x : u32) (y : u32) (st : state) : result (state * unit) :=
  p <- custom_swap_fwd u32 x y st; let (st0, _) := p in Return (st0, tt)
.

(** [external::test_custom_swap]: backward function 0 *)
Definition test_custom_swap_back
  (x : u32) (y : u32) (st : state) (st0 : state) :
  result (state * (u32 * u32))
  :=
  custom_swap_back u32 x y st 1%u32 st0
.

(** [external::test_swap_non_zero]: forward function *)
Definition test_swap_non_zero_fwd
  (x : u32) (st : state) : result (state * u32) :=
  p <- swap_fwd u32 x 0%u32 st;
  let (st0, _) := p in
  p0 <- swap_back u32 x 0%u32 st st0;
  let (st1, p1) := p0 in
  let (x0, _) := p1 in
  if x0 s= 0%u32 then Fail_ Failure else Return (st1, x0)
.

End External_Funs .