This file is indexed.

/usr/share/acl2-6.3/books/misc/seqw.lisp is in acl2-books-source 6.3-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
; The SEQW Macro Language
; Copyright (C) 2008-2010 Centaur Technology
;
; Contact:
;   Centaur Technology Formal Verification Group
;   7600-C N. Capital of Texas Highway, Suite 300, Austin, TX 78731, USA.
;   http://www.centtech.com/
;
; This program is free software; you can redistribute it and/or modify it under
; the terms of the GNU General Public License as published by the Free Software
; Foundation; either version 2 of the License, or (at your option) any later
; version.  This program is distributed in the hope that it will be useful but
; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
; more details.  You should have received a copy of the GNU General Public
; License along with this program; if not, write to the Free Software
; Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
;
; Original author: Jared Davis <jared@centtech.com>

(in-package "ACL2")
(include-book "seq")


; THE SEQW MACRO
;
; SEQW is an alternative implementation of the SEQ language which allows for
; warnings to be implicitly collected and stored in a list as your program
; executes.  This comment only describes the differences between SEQW and SEQ,
; so if you have not yet examined seq.lisp and seq-examples.lsp, you will
; want to look at them first.
;
; The difference is quite straightforward:
;
;   - Whereas a SEQ program has the form (seq <stream> ...), a SEQW program
;     instead has one additional argument, (seqw <stream> <warnings> ...),
;     where <warnings> is the name of a warnings structure.
;
;   - Whereas every SEQ action returns (MV ERROR VAL STREAM), each SEQW action
;     instead returns (MV ERROR VAL STREAM WARNINGS), where WARNINGS is the
;     updated warnings structure.
;
; Similarly, every SEQW program returns (MV ERROR VAL STREAM WARNINGS) instead
; of (MV ERROR VAL STREAM).
;
; What is a warnings structure?  When we use SEQW, we generally accumulate
; warnings into a list, so our actions just cons new warnings into this list
; when desired.  But SEQW itself imposes no particular constraints on what
; a warnings structure is, and generally the way in which a warning is updated
; is determined by the actions of the program rather than by SEQW itself.
;
; For examples of using SEQW, see the file seqw-examples.lsp.

(program)

(defun seqw-process-bind (x stream warnings rest)

; X is a bind statement, stream is the name of the stream we are processing,
; and rest is the expansion of the rest of the lines in the block.  We are to
; write the MV code for this bind statement.

  (declare (xargs :guard (and (seq-bind-p x)
                              (seq-name-p stream)
                              (seq-name-p warnings))))

  (cond ((eq (car x) :=)
         (let ((action (second x)))
           `(mv-let (!!!error !!!val ,stream ,warnings)
                    ,action
                    (if !!!error
                        (mv !!!error !!!val ,stream ,warnings)
                      (check-vars-not-free (!!!error !!!val !!!stream)
                                           ,rest)))))

        ((or (eq (car x) :w=)
             (eq (car x) :s=))
         (let ((action (second x)))
           `(let ((!!!stream ,stream))
              (mv-let (!!!error !!!val ,stream ,warnings)
                      ,action
                      (cond (!!!error
                             (mv !!!error !!!val ,stream ,warnings))
                            ((not (mbt (,(case (car x) (:s= '<) (:w= '<=))
                                        (acl2-count ,stream)
                                        (acl2-count !!!stream))))
                             (prog2$ (er hard? "SEQW count failed for (~x0 ~x1.)~%"
                                         ',(car x) ',action)
                                     (mv "SEQW count failure." nil !!!stream ,warnings)))
                            (t
                             (check-vars-not-free (!!!error !!!val !!!stream)
                                                  ,rest)))))))

        (t
         (let* ((nametree (first x))
                (type     (second x))
                (action   (third x)))
           (if (and nametree (symbolp nametree))
               ;; We have only a single variable.  We can write some cleaner
               ;; mv-let code without any of this nametree destucturing.

               (case type

                 (:= `(mv-let (!!!error ,nametree ,stream ,warnings)
                              ,action
                              (if !!!error
                                  (mv !!!error ,nametree ,stream ,warnings)
                                (check-vars-not-free (!!!error !!!val !!!stream)
                                                     ,rest))))

                 ((:w= :s=)
                  `(let ((!!!stream ,stream))
                     (mv-let (!!!error ,nametree ,stream ,warnings)
                             ,action
                             (cond (!!!error
                                    (mv !!!error ,nametree ,stream ,warnings))
                                   ((not (mbt (,(case type (:s= '<) (:w= '<=))
                                               (acl2-count ,stream)
                                               (acl2-count !!!stream))))
                                    (prog2$ (er hard? "SEQW count failed for (~x0 ~x1 ~x2.)~%"
                                                ',nametree ',type ',action)
                                            (mv "SEQW count failure." nil !!!stream ,warnings)))
                                   (t
                                    (check-vars-not-free (!!!error !!!val !!!stream)
                                                         ,rest)))))))

             ;; Multiple variables; do the destructuring.
             (case type

               (:= `(mv-let (!!!error !!!val ,stream ,warnings)
                            ,action
                            (if !!!error
                                (mv !!!error !!!val ,stream ,warnings)
                              (let ,(seq-nametree-to-let-bindings nametree '!!!val)
                                (check-vars-not-free (!!!error !!!val !!!stream)
                                                     ,rest)))))

               ((:w= :s=)
                `(let ((!!!stream ,stream))
                   (mv-let (!!!error !!!val ,stream ,warnings)
                           ,action
                           (cond (!!!error
                                  (mv !!!error !!!val ,stream ,warnings))
                                 ((not (mbt (,(case type (:s= '<) (:w= '<=))
                                             (acl2-count ,stream)
                                             (acl2-count !!!stream))))
                                  (prog2$ (er hard?  "SEQW count failed for (~x0 ~x1 ~x2.)~%"
                                              ',nametree ',type ',action)
                                          (mv "SEQW count failure." nil !!!stream ,warnings)))
                                 (t
                                  (let ,(seq-nametree-to-let-bindings nametree '!!!val)
                                    (check-vars-not-free (!!!error !!!val !!!stream)
                                                         ,rest)))))))))))))

;(seqw-process-bind '(:= action) 'stream 'warnings '<rest>)
;(seqw-process-bind '(foo := action) 'stream 'warnings '<rest>)
;(seqw-process-bind '((foo . bar) := action) 'stream 'warnings '<rest>)
;(seqw-process-bind '((foo . nil) := action) 'stream 'warnings '<rest>)


(mutual-recursion

 (defun seqw-process-unless (x stream warnings rest)

; Unless statements are easily transformed into when statements.

   (declare (xargs :guard (and (seq-unless-p x)
                               (seq-name-p stream)
                               (seq-name-p warnings))))
   (let ((condition (second x))
         (subblock  (cddr x)))
     (seqw-process-when (list* 'when
                               `(not ,condition)
                               subblock)
                        stream warnings rest)))


 (defun seqw-process-when (x stream warnings rest)

; X is a when statement, stream is the name of the stream we are processing,
; warnings is the name of the warnings structure, and rest is the expansion for
; the statements that come after this when statement in the current block.  We
; are to write the MV code for this when statement.

   (declare (xargs :guard (and (seq-when-p x)
                               (seq-name-p stream)
                               (seq-name-p warnings))))

   (let* ((condition         (second x))
          (subblock          (cddr x))
          (ends-with-returnp (seq-list-ends-with-returnp subblock))
          (bound-in-subblock (seq-block-names subblock nil)))

     (cond

; Easy case 1.  The subblock ends with a return, so we always either process it
; or rest but never both.

      (ends-with-returnp
       `(if ,condition
            ,(seqw-process-block subblock stream warnings nil)
          ,rest))


; Easy case 2.  The subblock doesn't end with a return, so we may process it or
; and rest; but since it binds no variables so the only thing that it changes is
; the stream.

      ((not bound-in-subblock)
       `(mv-let (!!!error !!!val ,stream ,warnings)
                (if ,condition
                    ,(seqw-process-block subblock stream warnings nil)
                  (mv nil nil ,stream ,warnings))
                (if !!!error
                    (mv !!!error !!!val ,stream ,warnings)
                  (check-vars-not-free (!!!error !!!val) ,rest))))


; Hard case.  The subblock does not end with a return.  So if the condition is
; met, we're just going to do some additional bindings and stream manipulation
; before the processing rest.  The hard part of this is dealing with all of the
; things that variables that might have been bound in the subblock.

; Our basic approach is to add a return statement to the end of the subblock
; before processing it, which returns to us a list of all the values for the
; variables it binds.  We can then rebind these variables before giving them to
; rest.

      (t
       (let* ((return-stmt       `(return (list ,@bound-in-subblock)))
              (return-expansion  `(mv nil (list ,@bound-in-subblock) ,stream ,warnings))
              (new-subblock      (append subblock (list return-stmt)))
              (rebindings        (seq-make-let-pairs-for-when bound-in-subblock)))

         `(mv-let (!!!error !!!val ,stream ,warnings)
                  (if ,condition
                      ,(seqw-process-block new-subblock stream warnings nil)
                    ,return-expansion)
                  (if !!!error
                      (mv !!!error !!!val ,stream ,warnings)

; At this point, !!!val holds the list of all the values for the variables
; which were bound in the subblock.  We just need to redo these bindings so
; that they are available in rest.

                    (let* ,rebindings
                      (check-vars-not-free (!!!error !!!val) ,rest)))))))))

 (defun seqw-process-stmt (x stream warnings rest)
   (declare (xargs :guard (and (or (seq-bind-p x)
                                   (seq-when-p x)
                                   (seq-unless-p x)
                                   (seq-return-p x))
                               (seq-name-p stream)
                               (seq-name-p warnings))))
   (cond ((seq-bind-p x)
          (seqw-process-bind x stream warnings rest))
         ((seq-when-p x)
          (seqw-process-when x stream warnings rest))
         ((seq-unless-p x)
          (seqw-process-unless x stream warnings rest))
         (t
          (let ((type (first x))
                (value (second x)))
            (cond ((eq type 'return)
                   `(mv nil ,value ,stream ,warnings))
                  ((eq type 'return-raw)
                   value))))))

 (defun seqw-process-block (x stream warnings toplevelp)
   (declare (xargs :guard (and (seq-block-p x toplevelp)
                               (seq-name-p stream)
                               (seq-name-p warnings))))
   (if (atom (cdr x))
       (seqw-process-stmt (car x) stream warnings `(mv nil nil ,stream ,warnings))
     (let ((rest (seqw-process-block (cdr x) stream warnings toplevelp)))
       (seqw-process-stmt (car x) stream warnings rest)))))

(defun seqw-fn (stream warnings block)
  (declare (xargs :guard (and (seq-name-p stream)
                              (seq-name-p warnings)
                              (seq-block-p block t))))
  (let* ((names            (seq-block-names block t))
         (initial-bindings (seq-make-initial-let-pairs (remove-duplicates names))))
    `(let ,initial-bindings
       (declare (ignorable ,@names))
       ,(seqw-process-block block stream warnings t))))

(defmacro seqw (stream warnings &rest block)
  (seqw-fn stream warnings block))





(defun seqw-backtrack-fn (stream warnings blocks)
  (declare (xargs :guard (and (seq-name-p stream)
                              (seq-name-p warnings)
                              (seq-block-list-p blocks t)
                              (consp blocks))))
  (if (atom (cdr blocks))
      `(seqw ,stream ,warnings . ,(car blocks))
    `(mv-let (!!!error !!!val updated-stream updated-warnings)
             (seqw ,stream ,warnings . ,(car blocks))
             (if (not !!!error)
                 (mv !!!error !!!val updated-stream updated-warnings)
               (check-vars-not-free (!!!error !!!val)
                                    ,(seqw-backtrack-fn stream warnings (cdr blocks)))))))

(defmacro seqw-backtrack (stream warnings &rest blocks)
  (seqw-backtrack-fn stream warnings blocks))