-
Notifications
You must be signed in to change notification settings - Fork 0
/
pvsServer.pvs
389 lines (364 loc) · 13.7 KB
/
pvsServer.pvs
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
pvsServer: THEORY
BEGIN
%-- user-defined datatypes
DefinitionList: TYPE = { EMPTY, UPDATED_DEFS }
PvsRequest: TYPE = { NULL_REQ, FOLDERNAME, FILENAME, FILENAME_FORMULANAME, FORMULANAME_FULLTHEORYNAME, FULLTHEORYNAME, PROOF_CMD, CLEAR }
PvsResponse: TYPE = { TCCS, SEQUENT, SEQUENT_BRANCH_COMPLETE, SEQUENT_QED, PRF_PROOF, ERROR_MUST_EXIT_PROVER_FIRST, PROOF_ABORTED, ERROR_PROOF_NOT_FOUND, TYPECHECK_SUCCESS, TYPECHECK_ERROR, PARSE_SUCCESS, PARSE_ERROR, ERROR_NOT_TYPECHECKED, FOLDERNAME, NULL_RES }
%-- operating modes
Mode: TYPE = { AWAIT_CMD, FS_UPDATE, GET_PROOF_SCRIPT, INTERRUPTING, PARSING, PROVING, READY, SAVE_PROOF, START_PROVER, SW_UPDATE, TCCS, TYPECHECKING, WORKSPACE_UPDATE }
%-- state attributes
State: TYPE = [#
mode: Mode,
previous_mode: Mode,
defs: DefinitionList,
parsed: boolean,
req: PvsRequest,
res: PvsResponse,
typechecked: boolean,
unsavedProof: boolean
#]
%-- init function
init(x: real): State = (#
previous_mode := READY,
mode := READY,
defs := EMPTY,
parsed := false,
req := NULL_REQ,
res := NULL_RES,
typechecked := false,
unsavedProof := false
#)
%-- leave/enter functions
enter(m: Mode)(st: State): State =
LET st = st WITH [ mode := m ]
IN COND %-- entry actions
mode(st) = AWAIT_CMD
-> LET st = st WITH [ req := NULL_REQ ]
IN st,
mode(st) = READY
-> LET st = st WITH [ req := NULL_REQ ]
IN st,
ELSE -> st
ENDCOND
leave(m: Mode)(st: State): State =
LET st = st WITH [ mode := m ]
IN COND %-- entry actions
mode(st) = PARSING
-> LET st = st WITH [ defs := UPDATED_DEFS ]
IN st,
mode(st) = READY
-> LET st = st WITH [ unsavedProof := false ]
IN st,
mode(st) = TYPECHECKING
-> LET st = st WITH [ defs := UPDATED_DEFS ]
IN st,
ELSE -> st
ENDCOND
%-- transitions
per_changeWorkspace(st: State): bool = (mode(st) = READY)
changeWorkspace(st: (per_changeWorkspace)): State =
COND
mode(st) = READY
-> LET st = leave(READY)(st),
st = st WITH [ req := FOLDERNAME ]
IN enter(WORKSPACE_UPDATE)(st),
ELSE -> st
ENDCOND
per_clearTheories(st: State): bool = (mode(st) = READY)
clearTheories(st: (per_clearTheories)): State =
COND
mode(st) = READY
-> LET st = leave(READY)(st),
st = st WITH [ req := CLEAR ]
IN enter(WORKSPACE_UPDATE)(st),
ELSE -> st
ENDCOND
per_evt_DID_UPDATE_FS(st: State): bool = (mode(st) = READY)
evt_DID_UPDATE_FS(st: (per_evt_DID_UPDATE_FS)): State =
COND
mode(st) = READY
-> LET st = leave(READY)(st)
IN enter(FS_UPDATE)(st),
ELSE -> st
ENDCOND
per_interrupt(st: State): bool = (mode(st) = PROVING)
interrupt(st: (per_interrupt)): State =
COND
mode(st) = PROVING
-> LET st = leave(PROVING)(st)
IN enter(INTERRUPTING)(st),
ELSE -> st
ENDCOND
per_loadPvsPatches(st: State): bool = (mode(st) = READY)
loadPvsPatches(st: (per_loadPvsPatches)): State =
COND
mode(st) = READY
-> LET st = leave(READY)(st)
IN enter(SW_UPDATE)(st),
ELSE -> st
ENDCOND
per_notify_ABORT(st: State): bool = (mode(st) = PROVING)
notify_ABORT(st: (per_notify_ABORT)): State =
COND
mode(st) = PROVING
-> LET st = leave(PROVING)(st),
st = st WITH [ res := PROOF_ABORTED ],
st = st WITH [ unsavedProof := true ]
IN enter(READY)(st),
ELSE -> st
ENDCOND
per_notify_BRANCH_COMPLETE(st: State): bool = (mode(st) = PROVING)
notify_BRANCH_COMPLETE(st: (per_notify_BRANCH_COMPLETE)): State =
COND
mode(st) = PROVING
-> LET st = leave(PROVING)(st),
st = st WITH [ res := SEQUENT_BRANCH_COMPLETE ]
IN enter(AWAIT_CMD)(st),
ELSE -> st
ENDCOND
per_notify_ERROR(st: State): bool = (mode(st) = GET_PROOF_SCRIPT AND ( typechecked(st) = true ))
OR (mode(st) = PARSING)
OR (mode(st) = TYPECHECKING)
notify_ERROR(st: (per_notify_ERROR)): State =
COND
mode(st) = GET_PROOF_SCRIPT AND ( typechecked(st) = true )
-> LET st = leave(GET_PROOF_SCRIPT)(st),
st = st WITH [ res := ERROR_PROOF_NOT_FOUND ]
IN enter(READY)(st),
mode(st) = PARSING
-> LET st = leave(PARSING)(st),
st = st WITH [ parsed := false ],
st = st WITH [ res := PARSE_ERROR ]
IN enter(READY)(st),
mode(st) = TYPECHECKING
-> LET st = leave(TYPECHECKING)(st),
st = st WITH [ typechecked := false ],
st = st WITH [ res := TYPECHECK_ERROR ]
IN enter(READY)(st),
ELSE -> st
ENDCOND
per_notify_INTERRUPTED_BY_CLIENT(st: State): bool = (mode(st) = INTERRUPTING)
notify_INTERRUPTED_BY_CLIENT(st: (per_notify_INTERRUPTED_BY_CLIENT)): State =
COND
mode(st) = INTERRUPTING
-> LET st = leave(INTERRUPTING)(st),
st = st WITH [ res := SEQUENT ]
IN enter(AWAIT_CMD)(st),
ELSE -> st
ENDCOND
per_notify_INVALID_COMMAND(st: State): bool = (mode(st) = PROVING)
notify_INVALID_COMMAND(st: (per_notify_INVALID_COMMAND)): State =
COND
mode(st) = PROVING
-> LET st = leave(PROVING)(st),
st = st WITH [ res := SEQUENT ]
IN enter(AWAIT_CMD)(st),
ELSE -> st
ENDCOND
per_notify_NO_CHANGE(st: State): bool = (mode(st) = PROVING)
notify_NO_CHANGE(st: (per_notify_NO_CHANGE)): State =
COND
mode(st) = PROVING
-> LET st = leave(PROVING)(st),
st = st WITH [ res := SEQUENT ]
IN enter(AWAIT_CMD)(st),
ELSE -> st
ENDCOND
per_notify_PROOF_SCRIPT(st: State): bool = (mode(st) = GET_PROOF_SCRIPT AND ( typechecked(st) = true ))
notify_PROOF_SCRIPT(st: (per_notify_PROOF_SCRIPT)): State =
COND
mode(st) = GET_PROOF_SCRIPT AND ( typechecked(st) = true )
-> LET st = leave(GET_PROOF_SCRIPT)(st),
st = st WITH [ res := PRF_PROOF ]
IN enter(READY)(st),
ELSE -> st
ENDCOND
per_notify_QED(st: State): bool = (mode(st) = START_PROVER AND ( typechecked(st) = true ))
OR (mode(st) = PROVING)
notify_QED(st: (per_notify_QED)): State =
COND
mode(st) = START_PROVER AND ( typechecked(st) = true )
-> LET st = leave(START_PROVER)(st),
st = st WITH [ res := SEQUENT_QED ]
IN enter(READY)(st),
mode(st) = PROVING
-> LET st = leave(PROVING)(st),
st = st WITH [ res := SEQUENT_QED ]
IN enter(SAVE_PROOF)(st),
ELSE -> st
ENDCOND
per_notify_SEQUENT(st: State): bool = (mode(st) = START_PROVER AND ( typechecked(st) = true ))
OR (mode(st) = PROVING)
notify_SEQUENT(st: (per_notify_SEQUENT)): State =
COND
mode(st) = START_PROVER AND ( typechecked(st) = true )
-> LET st = leave(START_PROVER)(st),
st = st WITH [ res := SEQUENT ]
IN enter(AWAIT_CMD)(st),
mode(st) = PROVING
-> LET st = leave(PROVING)(st),
st = st WITH [ res := SEQUENT ]
IN enter(AWAIT_CMD)(st),
ELSE -> st
ENDCOND
per_notify_SUCCESS(st: State): bool = (mode(st) = TYPECHECKING AND ( previous_mode(st) = READY ))
OR (mode(st) = PARSING)
notify_SUCCESS(st: (per_notify_SUCCESS)): State =
COND
mode(st) = TYPECHECKING AND ( previous_mode(st) = READY )
-> LET st = leave(TYPECHECKING)(st),
st = st WITH [ typechecked := true ],
st = st WITH [ res := TYPECHECK_SUCCESS ]
IN enter(READY)(st),
mode(st) = PARSING
-> LET st = leave(PARSING)(st),
st = st WITH [ parsed := true ],
st = st WITH [ res := PARSE_SUCCESS ]
IN enter(READY)(st),
ELSE -> st
ENDCOND
per_notify_TCCS(st: State): bool = (mode(st) = TCCS AND ( typechecked(st) = true ))
notify_TCCS(st: (per_notify_TCCS)): State =
COND
mode(st) = TCCS AND ( typechecked(st) = true )
-> LET st = leave(TCCS)(st),
st = st WITH [ res := TCCS ]
IN enter(READY)(st),
ELSE -> st
ENDCOND
per_parseFile(st: State): bool = (mode(st) = READY)
parseFile(st: (per_parseFile)): State =
COND
mode(st) = READY
-> LET st = leave(READY)(st),
st = st WITH [ req := FILENAME ]
IN enter(PARSING)(st),
ELSE -> st
ENDCOND
per_proofCommand(st: State): bool = (mode(st) = AWAIT_CMD)
proofCommand(st: (per_proofCommand)): State =
COND
mode(st) = AWAIT_CMD
-> LET st = leave(AWAIT_CMD)(st),
st = st WITH [ req := PROOF_CMD ]
IN enter(PROVING)(st),
ELSE -> st
ENDCOND
per_proofScript(st: State): bool = (mode(st) = READY)
OR (mode(st) = AWAIT_CMD)
proofScript(st: (per_proofScript)): State =
COND
mode(st) = READY
-> LET st = leave(READY)(st),
st = st WITH [ req := FILENAME_FORMULANAME ]
IN enter(GET_PROOF_SCRIPT)(st),
mode(st) = AWAIT_CMD
-> LET st = leave(AWAIT_CMD)(st),
st = st WITH [ res := ERROR_MUST_EXIT_PROVER_FIRST ]
IN enter(AWAIT_CMD)(st),
ELSE -> st
ENDCOND
per_proveFormula(st: State): bool = (mode(st) = READY)
OR (mode(st) = AWAIT_CMD)
proveFormula(st: (per_proveFormula)): State =
COND
mode(st) = READY
-> LET st = leave(READY)(st),
st = st WITH [ req := FORMULANAME_FULLTHEORYNAME ]
IN enter(START_PROVER)(st),
mode(st) = AWAIT_CMD
-> LET st = leave(AWAIT_CMD)(st),
st = st WITH [ res := ERROR_MUST_EXIT_PROVER_FIRST ]
IN enter(AWAIT_CMD)(st),
ELSE -> st
ENDCOND
per_saveLastStoredProofAttempt(st: State): bool = (mode(st) = READY AND ( unsavedProof(st) = true ))
saveLastStoredProofAttempt(st: (per_saveLastStoredProofAttempt)): State =
COND
mode(st) = READY AND ( unsavedProof(st) = true )
-> LET st = leave(READY)(st),
st = st WITH [ req := FORMULANAME_FULLTHEORYNAME ]
IN enter(SAVE_PROOF)(st),
ELSE -> st
ENDCOND
per_showTCCs(st: State): bool = (mode(st) = READY)
showTCCs(st: (per_showTCCs)): State =
COND
mode(st) = READY
-> LET st = leave(READY)(st),
st = st WITH [ req := FULLTHEORYNAME ]
IN enter(TCCS)(st),
ELSE -> st
ENDCOND
per_tick(st: State): bool = (mode(st) = INTERRUPTING)
OR (mode(st) = SW_UPDATE)
OR (mode(st) = TYPECHECKING AND ( previous_mode(st) = GET_PROOF_SCRIPT))
OR (mode(st) = TYPECHECKING AND ( previous_mode(st) = TCCS ))
OR (mode(st) = TCCS AND ( typechecked(st) = false ))
OR (mode(st) = TYPECHECKING AND ( previous_mode(st) = START_PROVER ))
OR (mode(st) = WORKSPACE_UPDATE AND ( req(st) = CLEAR ))
OR (mode(st) = WORKSPACE_UPDATE AND ( req(st) = FOLDERNAME ))
OR (mode(st) = GET_PROOF_SCRIPT AND ( typechecked(st) = false ))
OR (mode(st) = START_PROVER AND ( typechecked(st) = false ))
OR (mode(st) = FS_UPDATE)
OR (mode(st) = SAVE_PROOF)
tick(st: (per_tick)): State =
COND
mode(st) = INTERRUPTING
-> LET st = leave(INTERRUPTING)(st)
IN enter(PROVING)(st),
mode(st) = SW_UPDATE
-> LET st = leave(SW_UPDATE)(st)
IN enter(READY)(st),
mode(st) = TYPECHECKING AND ( previous_mode(st) = GET_PROOF_SCRIPT )
-> LET st = leave(TYPECHECKING)(st),
st = st WITH [ typechecked := true ]
IN enter(GET_PROOF_SCRIPT)(st),
mode(st) = TYPECHECKING AND ( previous_mode(st) = TCCS )
-> LET st = leave(TYPECHECKING)(st),
st = st WITH [ typechecked := true ]
IN enter(TCCS)(st),
mode(st) = TCCS AND ( typechecked(st) = false )
-> LET st = leave(TCCS)(st)
IN enter(TYPECHECKING)(st),
mode(st) = TYPECHECKING AND ( previous_mode(st) = START_PROVER )
-> LET st = leave(TYPECHECKING)(st),
st = st WITH [ typechecked := true ]
IN enter(START_PROVER)(st),
mode(st) = WORKSPACE_UPDATE AND ( req(st) = CLEAR )
-> LET st = leave(WORKSPACE_UPDATE)(st),
st = st WITH [ defs := EMPTY ],
st = st WITH [ parsed := false ],
st = st WITH [ typechecked := false ]
IN enter(READY)(st),
mode(st) = WORKSPACE_UPDATE AND ( req(st) = FOLDERNAME )
-> LET st = leave(WORKSPACE_UPDATE)(st),
st = st WITH [ res := FOLDERNAME ]
IN enter(READY)(st),
mode(st) = GET_PROOF_SCRIPT AND ( typechecked(st) = false )
-> LET st = leave(GET_PROOF_SCRIPT)(st)
IN enter(TYPECHECKING)(st),
mode(st) = START_PROVER AND ( typechecked(st) = false )
-> LET st = leave(START_PROVER)(st)
IN enter(TYPECHECKING)(st),
mode(st) = FS_UPDATE
-> LET st = leave(FS_UPDATE)(st),
st = st WITH [ parsed := false ],
st = st WITH [ typechecked := false ]
IN enter(READY)(st),
mode(st) = SAVE_PROOF
-> LET st = leave(SAVE_PROOF)(st),
st = st WITH [ unsavedProof := false ]
IN enter(READY)(st),
ELSE -> st
ENDCOND
per_typecheckFile(st: State): bool = (mode(st) = READY)
typecheckFile(st: (per_typecheckFile)): State =
COND
mode(st) = READY
-> LET st = leave(READY)(st),
st = st WITH [ req := FILENAME ]
IN enter(TYPECHECKING)(st),
ELSE -> st
ENDCOND
END pvsServer