5
(local (in-theory (enable statementp)))
7
;; The following are useful when disabling mstatep
9
(defthm mstate-pstate-listp
11
(pstate-listp (first ms))))
13
(defthm mstate-cstate-listp
15
(cstate-listp (second ms))))
17
(defthm mstate-lstate-listp
19
(lstate-listp (third ms))))
21
(defthm mstate-program-listp
23
(program-listp (fourth ms))))
25
;;--------------------------------
26
;; exec-setup-listener
28
;; [Jared] adding this because the defun below failed when it was added to ACL2.
29
(local (in-theory (disable FOLD-CONSTS-IN-+)))
31
(defun exec-setup-listener (stmt ps ms)
32
(declare (xargs :guard (and (statementp stmt)
33
(equal (car stmt) 'setup-listener)
38
(let ((port (evl2 (second stmt) (memory ps))))
40
(let* ((x (setup-listener (car ps) port ms))
45
(update-pstate (car ps)
59
(update-pstate (car ps)
65
''bad-port-in-setup-listener
73
(defthm evaluated-expressionp-car-setup-listener
74
(evaluated-expressionp (car (setup-listener hpid port ms))))
76
(verify-guards exec-setup-listener
78
:in-theory (disable setup-listener)))
81
(defthm exec-setup-listener-preserves-mstatep
82
(implies (and (statementp stmt)
83
(equal (car stmt) 'setup-listener)
86
(mstatep (exec-setup-listener stmt ps ms)))
88
:in-theory (disable setup-listener))))
90
;;------------------------------------
92
(defthm request-listp-is-alistp
93
(implies (request-listp rq)
96
:in-theory (enable hpid-fdp)))
97
:rule-classes :forward-chaining)
99
(defthm find-ls-alistp
100
(implies (and (lstate-listp lss)
101
(consp (find-ls dest-host dest-port lss)))
102
(alistp (caddr (find-ls dest-host dest-port lss)))))
104
(defun connection-status (my-hpid dest-host dest-port ms)
105
(declare (xargs :guard (and (hpidp my-hpid)
109
(let ((ls (find-ls dest-host dest-port (lstates ms))))
110
(cond ((atom ls) 'not-listening)
111
((assoc-equal my-hpid (requestq ls)) 'pending)
115
(declare (xargs :guard t))
116
(if (and (equal (len x) 2)
117
(equal (first x) 'quote))
121
(in-theory (disable unkwote))
123
;;------------------------------------------------------------------
126
;; This executes (or continues to execute) a statement like
127
;; (FDASGN FD (CONNECT remote-host remote-port)).
129
;; If the remote-host is not listening on the remote-port, we set
130
;; the FD to -1 and bump the PC (connection refused).
131
;; If we have already issued a connect-request, and the remote host
132
;; has not accepted it, we do nothing.
133
;; Otherwise, we issue a connect-request.
135
;; Note that the PC is bumped by the accepting process when the connection
136
;; is accepted. Perhaps this bit of implicit handshaking should be rethought.
138
(defun exec-connect (stmt ps ms)
139
(declare (xargs :guard (and (statementp stmt)
140
(equal (car stmt) 'connect)
145
(let ((my-hpid (car ps))
146
(dest-host (unkwote (evl2 (second stmt) (memory ps))))
147
(dest-port (evl2 (third stmt) (memory ps))))
148
(if (or (not (hostp dest-host))
149
(not (portp dest-port)))
151
(update-pstate (car ps)
152
(make-pstate (car ps)
157
''bad-host-or-port-in-connect
164
(let ((status (connection-status my-hpid dest-host dest-port ms)))
166
(pending ms) ;; do nothing
168
(not-listening (make-mstate
169
(update-pstate (car ps)
170
(make-pstate (car ps)
182
(ready (let* ((x (connect my-hpid dest-host dest-port ms))
187
(update-pstate (car ps)
188
(make-pstate (car ps)
203
(defthm evaluated-expressionp-car-connect
204
(evaluated-expressionp (car (connect hpid host port ms))))
206
(defthm conp-cdr-connect
207
(consp (cdr (connect hpid host port ms))))
210
(cdr (connect hpid host port ms)))
212
(verify-guards exec-connect
214
:in-theory (disable connect mstatep))))
216
(defthm exec-connect-preserves-mstatep
217
(implies (and (statementp stmt)
218
(equal (car stmt) 'connect)
221
(mstatep (exec-connect stmt ps ms)))
223
:in-theory (disable connect))))
225
;;------------------------------------
228
;; This executes a statement like (FDASGN FD (ACCEPT LFD)), where
229
;; LFD is the listening fd. When and if we succeed, FD is given
230
;; the new fd for the conection. If there are no requests to accept,
231
;; we do nothing (i.e., we wait).
233
(defun exec-accept (stmt ps ms)
234
(declare (xargs :guard (and (statementp stmt)
235
(equal (car stmt) 'accept)
240
(let ((lfd (evl2 (second stmt) (memory ps))))
242
;; The fd is bad, so set pc to 0 and set error variable.
244
(update-pstate (car ps)
245
(make-pstate (car ps)
257
;; The listening FD is ok. Try to accept a connection.
258
(let* ((x (accept (car ps) lfd ms))
263
;; There is nothing to accept, so just wait.
265
;; All is well, so accept, bump our PC, and assign fd.
267
(update-pstate (car ps)
268
(make-pstate (car ps)
280
(defthm evaluated-expressionp-car-accept
281
(evaluated-expressionp (car (accept hpid fd ms))))
283
(verify-guards exec-accept
285
:in-theory (disable accept))))
287
(defthm exec-accept-preserves-mstatep
288
(implies (and (statementp stmt)
289
(equal (car stmt) 'accept)
292
(mstatep (exec-accept stmt ps ms)))
294
:in-theory (disable accept))))