/
opsem.elf
executable file
·423 lines (282 loc) · 10.8 KB
/
opsem.elf
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
%%%%% Stores %%%%%
store-lookup : store -> location -> entry -> type.
store-lookup/hit
: store-lookup (store/cons _ L EN) L EN.
store-lookup/miss
: store-lookup (store/cons ST _ _) L EN
<- store-lookup ST L EN.
store-update : store -> location -> entry -> store -> type.
store-update/hit
: store-update (store/cons ST L _) L EN (store/cons ST L EN).
store-update/miss
: store-update (store/cons ST L EN) L' EN' (store/cons ST' L EN)
<- store-update ST L' EN' ST'.
nextloc : store -> location -> type.
nextloc/nil : nextloc store/nil location/0.
nextloc/cons : nextloc (store/cons _ L _) L'
<- loc-succ L L'.
%%%%% Evaluation %%%%%
step : store -> term -> store -> term -> type.
step-md : store -> module -> store -> module -> type.
raises : term -> term -> type.
raises-md : module -> term -> type.
step/abort : step ST (tm/abort E T) ST' (tm/abort E' T)
<- step ST E ST' E'.
step/pair1 : step ST (tm/pair E1 E2) ST' (tm/pair E1' E2)
<- step ST E1 ST' E1'.
step/pair2 : step ST (tm/pair E1 E2) ST' (tm/pair E1 E2')
<- value E1
<- step ST E2 ST' E2'.
step/pi1 : step ST (tm/pi1 E) ST' (tm/pi1 E')
<- step ST E ST' E'.
step/pi1-beta : step ST (tm/pi1 (tm/pair E1 E2)) ST E1
<- value E1
<- value E2.
step/pi2 : step ST (tm/pi2 E) ST' (tm/pi2 E')
<- step ST E ST' E'.
step/pi2-beta : step ST (tm/pi2 (tm/pair E1 E2)) ST E2
<- value E1
<- value E2.
step/app1 : step ST (tm/app E1 E2) ST' (tm/app E1' E2)
<- step ST E1 ST' E1'.
step/app2 : step ST (tm/app E1 E2) ST' (tm/app E1 E2')
<- value E1
<- step ST E2 ST' E2'.
step/app-beta : step ST (tm/app (tm/lam T ([x] E1 x)) E2) ST (E1 E2)
<- value E2.
step/in1 : step ST (tm/in1 E T) ST' (tm/in1 E' T)
<- step ST E ST' E'.
step/in2 : step ST (tm/in2 E T) ST' (tm/in2 E' T)
<- step ST E ST' E'.
step/case : step ST (tm/case E E1 E2) ST' (tm/case E' E1 E2)
<- step ST E ST' E'.
step/case-beta1 : step ST (tm/case (tm/in1 E _) E1 E2) ST (E1 E)
<- value E.
step/case-beta2 : step ST (tm/case (tm/in2 E _) E1 E2) ST (E2 E)
<- value E.
step/ref : step ST (tm/ref E) ST' (tm/ref E')
<- step ST E ST' E'.
step/ref-beta : step ST (tm/ref E) (store/cons ST L (entry/ref E)) (tm/refloc L)
<- value E
<- nextloc ST L.
step/deref : step ST (tm/deref E) ST' (tm/deref E')
<- step ST E ST' E'.
step/deref-beta : step ST (tm/deref (tm/refloc L)) ST E
<- store-lookup ST L (entry/ref E).
step/assign1 : step ST (tm/assign E1 E2) ST' (tm/assign E1' E2)
<- step ST E1 ST' E1'.
step/assign2 : step ST (tm/assign E1 E2) ST' (tm/assign E1 E2')
<- value E1
<- step ST E2 ST' E2'.
step/assign-beta
: step ST (tm/assign (tm/refloc L) E) ST' tm/unit
<- value E
<- store-update ST L (entry/ref E) ST'.
step/newtag-beta
: step ST (tm/newtag T) (store/cons ST L (entry/tag T)) (tm/tagloc L)
<- nextloc ST L.
step/tag1 : step ST (tm/tag E1 E2) ST' (tm/tag E1' E2)
<- step ST E1 ST' E1'.
step/tag2 : step ST (tm/tag E1 E2) ST' (tm/tag E1 E2')
<- value E1
<- step ST E2 ST' E2'.
step/iftag1 : step ST (tm/iftag E1 E2 E3 E4) ST' (tm/iftag E1' E2 E3 E4)
<- step ST E1 ST' E1'.
step/iftag2 : step ST (tm/iftag E1 E2 E3 E4) ST' (tm/iftag E1 E2' E3 E4)
<- value E1
<- step ST E2 ST' E2'.
step/iftag-beta1
: step ST (tm/iftag (tm/tag (tm/tagloc L) E) (tm/tagloc L) E3 E4) ST (E3 E)
<- value E.
step/iftag-beta2
: step ST (tm/iftag (tm/tag (tm/tagloc L) E) (tm/tagloc L') E3 E4) ST E4
<- value E
<- loc-neq L L'.
step/roll : step ST (tm/roll E K C1 C2) ST' (tm/roll E' K C1 C2)
<- step ST E ST' E'.
step/unroll : step ST (tm/unroll E) ST' (tm/unroll E')
<- step ST E ST' E'.
step/unroll-beta
: step ST (tm/unroll (tm/roll E _ _ _)) ST E
<- value E.
step/in : step ST (tm/in I E) ST' (tm/in I E')
<- step ST E ST' E'.
step/out : step ST (tm/out E) ST' (tm/out E')
<- step ST E ST' E'.
step/out-beta : step ST (tm/out (tm/in I E)) ST E
<- value E.
step/raise : step ST (tm/raise E T) ST' (tm/raise E' T)
<- step ST E ST' E'.
step/try : step ST (tm/try E1 E2) ST' (tm/try E1' E2)
<- step ST E1 ST' E1'.
step/try-done : step ST (tm/try E1 E2) ST E1
<- value E1.
step/try-handle : step ST (tm/try E1 E2) ST (E2 V)
<- raises E1 V.
step/lett1 : step ST (tm/lett E1 E2) ST' (tm/lett E1' E2)
<- step ST E1 ST' E1'.
step/lett2 : step ST (tm/lett E1 E2) ST (E2 E1)
<- value E1.
step/snd : step ST (tm/snd M) ST' (tm/snd M')
<- step-md ST M ST' M'.
step/snd-beta : step ST (tm/snd (md/datom E T)) ST E
<- value E.
step-md/datom : step-md ST (md/datom E T) ST' (md/datom E' T)
<- step ST E ST' E'.
step-md/pair1 : step-md ST (md/pair M1 M2) ST' (md/pair M1' M2)
<- step-md ST M1 ST' M1'.
step-md/pair2 : step-md ST (md/pair M1 M2) ST' (md/pair M1 M2')
<- value-md M1
<- step-md ST M2 ST' M2'.
step-md/dpair1 : step-md ST (md/dpair M1 ([a] [m] M2 a m)) ST' (md/dpair M1' ([a] [m] M2 a m))
<- step-md ST M1 ST' M1'.
%% We can see here why it's necessary to have dependent and non-dependent pairs as
%% separate constructs. If we tried to make non-dependent pairs a degenerate case
%% of dependent pairs, then the step-md/dpair2 rule and the dpair analog of the
%% step-md/pair2 rule could both be enabled, making the operational semantics
%% non-deterministic. Fixes (such as checking to make sure the dependency is unused
%% before allowing step-md/pair2) would be clumsy. Besides, this is more faithful
%% to what the implementation will actually do anyway.
step-md/dpair2 : step-md ST (md/dpair M1 ([a] [m] M2 a m)) ST (md/pair M1 (M2 C1 M1))
<- value-md M1
<- md-fst M1 C1.
step-md/pi1 : step-md ST (md/pi1 M) ST' (md/pi1 M')
<- step-md ST M ST' M'.
step-md/pi1-beta
: step-md ST (md/pi1 (md/pair M1 M2)) ST M1
<- value-md M1
<- value-md M2.
step-md/pi2 : step-md ST (md/pi2 M) ST' (md/pi2 M')
<- step-md ST M ST' M'.
step-md/pi2-beta
: step-md ST (md/pi2 (md/pair M1 M2)) ST M2
<- value-md M1
<- value-md M2.
step-md/app1 : step-md ST (md/app M1 M2) ST' (md/app M1' M2)
<- step-md ST M1 ST' M1'.
step-md/app2 : step-md ST (md/app M1 M2) ST' (md/app M1 M2')
<- value-md M1
<- step-md ST M2 ST' M2'.
step-md/app-beta
: step-md ST (md/app (md/lam S ([a] [m] M1 a m)) M2) ST (M1 C2 M2)
<- value-md M2
<- md-fst M2 C2.
step-md/in : step-md ST (md/in L M) ST' (md/in L M')
<- step-md ST M ST' M'.
step-md/out : step-md ST (md/out M) ST' (md/out M')
<- step-md ST M ST' M'.
step-md/out-beta
: step-md ST (md/out (md/in L M)) ST M
<- value-md M.
step-md/let1 : step-md ST (md/let M1 ([a] [m] M2 a m) S) ST' (md/let M1' ([a] [m] M2 a m) S)
<- step-md ST M1 ST' M1'.
step-md/let2 : step-md ST (md/let M1 ([a] [m] M2 a m) S) ST (M2 C1 M1)
<- value-md M1
<- md-fst M1 C1.
step-md/letp1 : step-md ST (md/letp M1 ([a] [m] M2 a m)) ST' (md/letp M1' ([a] [m] M2 a m))
<- step-md ST M1 ST' M1'.
step-md/letp2 : step-md ST (md/letp M1 ([a] [m] M2 a m)) ST (M2 C1 M1)
<- value-md M1
<- md-fst M1 C1.
step-md/lete1 : step-md ST (md/lete E T ([x] M x)) ST' (md/lete E' T ([x] M x))
<- step ST E ST' E'.
step-md/lete2 : step-md ST (md/lete E T ([x] M x)) ST (M E)
<- value E.
step-md/seal : step-md ST (md/seal M S) ST M.
raises/abort : raises (tm/abort E T) V
<- raises E V.
raises/pair1 : raises (tm/pair E1 E2) V
<- raises E1 V.
raises/pair2 : raises (tm/pair E1 E2) V
<- value E1
<- raises E2 V.
raises/pi1 : raises (tm/pi1 E) V
<- raises E V.
raises/pi2 : raises (tm/pi2 E) V
<- raises E V.
raises/app1 : raises (tm/app E1 E2) V
<- raises E1 V.
raises/app2 : raises (tm/app E1 E2) V
<- value E1
<- raises E2 V.
raises/in1 : raises (tm/in1 E T) V
<- raises E V.
raises/in2 : raises (tm/in2 E T) V
<- raises E V.
raises/case : raises (tm/case E E1 E2) V
<- raises E V.
raises/ref : raises (tm/ref E) V
<- raises E V.
raises/deref : raises (tm/deref E) V
<- raises E V.
raises/assign1 : raises (tm/assign E1 E2) V
<- raises E1 V.
raises/assign2 : raises (tm/assign E1 E2) V
<- value E1
<- raises E2 V.
raises/tag1 : raises (tm/tag E1 E2) V
<- raises E1 V.
raises/tag2 : raises (tm/tag E1 E2) V
<- value E1
<- raises E2 V.
raises/iftag1 : raises (tm/iftag E1 E2 E3 E4) V
<- raises E1 V.
raises/iftag2 : raises (tm/iftag E1 E2 E3 E4) V
<- value E1
<- raises E2 V.
raises/roll : raises (tm/roll E _ _ _) V
<- raises E V.
raises/unroll : raises (tm/unroll E) V
<- raises E V.
raises/in : raises (tm/in I E) V
<- raises E V.
raises/out : raises (tm/out E) V
<- raises E V.
raises/raise1 : raises (tm/raise E T) V
<- raises E V.
raises/raise2 : raises (tm/raise E T) E
<- value E.
raises/lett : raises (tm/lett E1 E2) V
<- raises E1 V.
raises/snd : raises (tm/snd M) V
<- raises-md M V.
raises-md/datom : raises-md (md/datom E T) V
<- raises E V.
raises-md/pair1 : raises-md (md/pair M1 M2) V
<- raises-md M1 V.
raises-md/pair2 : raises-md (md/pair M1 M2) V
<- value-md M1
<- raises-md M2 V.
raises-md/dpair : raises-md (md/dpair M1 ([a] [m] M2 a m)) V
<- raises-md M1 V.
raises-md/pi1 : raises-md (md/pi1 M) V
<- raises-md M V.
raises-md/pi2 : raises-md (md/pi2 M) V
<- raises-md M V.
raises-md/app1 : raises-md (md/app M1 M2) V
<- raises-md M1 V.
raises-md/app2 : raises-md (md/app M1 M2) V
<- value-md M1
<- raises-md M2 V.
raises-md/in : raises-md (md/in L M) V
<- raises-md M V.
raises-md/out : raises-md (md/out M) V
<- raises-md M V.
raises-md/let : raises-md (md/let M1 ([a] [m] M2 a m) S) V
<- raises-md M1 V.
raises-md/letp : raises-md (md/letp M1 ([a] [m] M2 a m)) V
<- raises-md M1 V.
raises-md/lete : raises-md (md/lete E T ([x] M x)) V
<- raises E V.
%%%%% Derived Forms %%%%%
%{
%define tm/fix1 : con -> (term -> term) -> term = E
%solve step/fix : {t} {e} step ST (tm/fix t e) ST (E t e).
%define tm/fix2 : con -> (term -> term) -> term = E
%solve step/fix1 : {t} {e} step ST (tm/fix1 t e) ST (E t e).
%define tm/fix3 : con -> (term -> term) -> term = E
%solve step/fix2 : {t} {e} step ST (tm/fix2 t e) ST (E t e).
%define tm/fix4 : con -> (term -> term) -> term = E
%solve step/fix3 : {t} {e} step ST (tm/fix3 t e) ST (E t e).
%solve step/fix4 : {t} {e} step ST (tm/fix4 t e) ST (e (tm/fix t e)).
}%