File: early_return.sail

package info (click to toggle)
sail-ocaml 0.19.1%2Bdfsg5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,008 kB
  • sloc: ml: 75,941; ansic: 8,848; python: 1,342; exp: 560; sh: 474; makefile: 218; cpp: 36
file content (205 lines) | stat: -rw-r--r-- 3,726 bytes parent folder | download
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
default Order dec

$include <prelude.sail>
$include <arith.sail>

$[no_enum_number_conversions]
enum E = A | B | C

register r_A : E
register r_B : E
register r_C : E

register r : nat

function foreach_earlyreturneffect(n : nat) -> bool = {
  foreach (i from 0 to n) {
    if i > 5 then return false;
    r = r + 1;
  };
  r > n
}

function foreach_earlyreturnpure(n : nat) -> bool = {
  var res : nat = 0;
  foreach (i from 0 to n) {
    if i > 5 then return false;
    res = res + i;
  };
  res > n
}

function foreach_inner_earlyreturneffect(n : nat) -> bool = {
  foreach (i from 0 to n) {
    foreach (j from 0 to i) {
      if i > 5 then return false;
      r = r + 1;
    }
  };
  r > n
}

function foreach_inner_earlyreturnpure(n : nat) -> bool = {
  var res : nat = 0;
  foreach (i from 0 to n) {
    foreach (j from 0 to i) {
      if i > 5 then return false;
      res = res + 1;
    };
  };
  res > n
}

function foreach_inner_earlyreturneffect_catch(n : nat) -> bool = {
  foreach (i from 0 to n) {
    foreach (j from 0 to i) {
      if i > 5 then return false;
      r = r + 1;
    };
    r = r * 2;
  };
  r > n
}

function foreach_inner_earlyreturnpure_catch(n : nat) -> bool = {
  var res : nat = 0;
  foreach (i from 0 to n) {
    foreach (j from 0 to i) {
      if i > 5 then return false;
      res = res + 1;
    };
    res = res * 2;
  };
  res > n
}

function while_earlyreturneffect(n : nat) -> bool = {
  while (r < n) do {
    if r > 5 then return false;
    r = r + 1;
  };
  r > n
}

function while_earlyreturnpure(n : nat) -> bool = {
  var res : nat = 0;
  while (res < n) do {
    if res > 5 then return false;
    res = res + 1;
  };
  res > n
}

function while_inner_earlyreturneffect(n : nat) -> bool = {
  while (r < n) do {
    while (r < n) do {
      if n > 5 then return false;
      r = r + 1;
    }
  };
  r > n
}

function while_inner_earlyreturnpure(n : nat) -> bool = {
  var res : nat = 0;
  while (res < n) do {
    while (res < n) do {
      if n > 5 then return false;
      res = res + 1;
    };
  };
  res > n
}

function while_inner_earlyreturneffect_catch(n : nat) -> bool = {
  while (r < n) do {
    while (r < n) do {
      if n > 5 then return false;
      r = r + 1;
    };
    r = r * 2;
  };
  r > n
}

function while_inner_earlyreturnpure_catch(n : nat) -> bool = {
  var res : nat = 0;
  while (res < n) do {
    while (res < n) do {
      if n > 5 then return false;
      res = res + 1;
    };
    res = res * 2;
  };
  res > n
}

function match_early_return(x : E) -> E = {
  match x {
    A => return r_A,
    B => r_B = A,
    C => r_C = A,
  };
  r_B
}

function match_early_return_inloop(x : E) -> E = {
  foreach (i from 0 to 10) {
    match x {
      A => return r_A,
      B => r_B = A,
      C => r_C = A,
    }};
  r_B
}

function match_early_return_inloop_2(x : E) -> E = {
  foreach (i from 0 to 10) {
    let y : E = match x {
      A => return r_A,
      B => r_B,
      C => r_C,
    }};
  r_B
}

function match_early_return_loop(x : E) -> E = {
  match x {
    A => foreach (i from 0 to 10) {
      return r_A
    },
    B => r_B = A,
    C => r_C = A,
  };
  r_B
}

function ite_early_return(x : bool) -> E = {
  r_A = r_C;
  let y : E = if x then return r_A else r_B;
  r_B
}

function ite_early_return_inloop(x : bool) -> E = {
  foreach (i from 0 to 10){
  r_A = r_C;
  let y : E = if x then return r_A else r_B;};
  r_B
}

function ite_early_return_loop(x : bool) -> E = {
  if x then foreach (i from 0 to 10) {
      return r_A
    } else r_B = A;
  r_B
}

function unit_type(x : E) -> unit = {
  r_A = x;
}

function ite_early_return_seq(x : bool) -> E = {
  r_A = r_C;
  let y : E = if x then {unit_type(A); return r_A} else r_B;
  r_B
}