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
//! What a statement program answers: the run it completed, or the run that
//! stopped, each with the context it left and the roots it stored into.
use crate::;
use fmt;
/// A statement program that ran to its end ([`execute`](crate::execute),
/// [`execute_value`](crate::execute_value)): the context it left, the roots
/// it stored into and, from [`execute_value`](crate::execute_value), the
/// value of its last expression statement.
///
/// ```
/// use predicator_rs::{Context, Instructions, Key, Options, Value, execute};
///
/// let program = Instructions::from_json(r#"[["lit","x"],["lit",1],["store",1]]"#)?;
/// let execution = execute(&program, &Context::new(), &Options::new())?;
/// assert_eq!(execution.context().get(&Key::from("x")), Some(&Value::from(1)));
/// assert_eq!(execution.stored_roots(), [Key::from("x")]);
/// assert_eq!(execution.value(), None);
/// # Ok::<(), predicator_rs::Error>(())
/// ```
/// A statement program that stopped before its end: the [`Error`] it
/// stopped on, the context as of the last statement it completed (every
/// earlier write kept, the failing write not made) and the roots it had
/// stored into by then. The context passed in is never changed; a caller
/// that wants all or nothing keeps the one it has.
///
/// It converts into its [`Error`], so `?` takes a stopped run where only the
/// error matters.
///
/// ```
/// use predicator_rs::{Context, Instructions, Key, Options, Value, execute};
///
/// let program = Instructions::from_json(
/// r#"[["lit","a"],["lit",1],["store",1],["lit","a"],["lit","b"],["lit",2],["store",2]]"#,
/// )?;
/// let stopped = execute(&program, &Context::new(), &Options::new()).unwrap_err();
/// assert_eq!(stopped.error().reason(), "not_a_container");
/// assert_eq!(stopped.context().get(&Key::from("a")), Some(&Value::from(1)));
/// assert_eq!(stopped.stored_roots(), [Key::from("a")]);
/// # Ok::<(), predicator_rs::Error>(())
/// ```