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
|
; XDOC Documentation System for ACL2
; Copyright (C) 2009-2016 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/
;
; License: (An MIT/X11-style license)
;
; Permission is hereby granted, free of charge, to any person obtaining a
; copy of this software and associated documentation files (the "Software"),
; to deal in the Software without restriction, including without limitation
; the rights to use, copy, modify, merge, publish, distribute, sublicense,
; and/or sell copies of the Software, and to permit persons to whom the
; Software is furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included in
; all copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
; DEALINGS IN THE SOFTWARE.
;
; Original author: Jared Davis <jared@centtech.com> (but see next comment)
; This book was created by Matt Kaufmann to define function save-rendered,
; essentially using code that was formerly in community book
; books/doc/top.lisp, with original author Jared Davis.
(in-package "XDOC")
(include-book "defxdoc-raw")
(include-book "save")
(include-book "system/doc/render-doc-base" :dir :system)
(include-book "alter")
(include-book "xdoc-error")
(set-state-ok t)
(program)
(defttag :open-output-channel!)
(defconst *acl2-doc-search-separator* "###---###---###---###---###")
; Here is old code that has been replaced so as to speed up printing; see a
; comment about fms! in acl2-doc-print-topic-index below.
#||
(defun acl2-doc-fix-symbol-msg (sym)
(cond ((eq (intern$ (symbol-name sym) "ACL2") sym)
(msg "~s0" (symbol-name sym)))
(t (msg "~s0::~s1" (symbol-package-name sym) (symbol-name sym)))))
(defun acl2-doc-fix-symbol-lst-msg (lst)
(cond ((endp lst) "")
((endp (cdr lst))
(acl2-doc-fix-symbol-msg (car lst)))
(t (msg "~@0 ~@1"
(acl2-doc-fix-symbol-msg (car lst))
(acl2-doc-fix-symbol-lst-msg (cdr lst))))))
||#
(defun acl2-doc-print-fix-symbol (sym channel state)
(cond ((eq (intern$ (symbol-name sym) "ACL2") sym)
(princ$ (symbol-name sym) channel state))
(t (pprogn (princ$ (symbol-package-name sym) channel state)
(princ$ "::" channel state)
(princ$ (symbol-name sym) channel state)))))
(defun acl2-doc-print-fix-symbol-lst (lst channel state)
(cond ((endp lst) state)
((endp (cdr lst))
(acl2-doc-print-fix-symbol (car lst) channel state))
(t (pprogn
(acl2-doc-print-fix-symbol (car lst) channel state)
(princ$ " " channel state)
(acl2-doc-print-fix-symbol-lst (cdr lst) channel state)))))
(defun remove-sgr-1 (s i len acc)
(let ((p (search *sgr-prefix* s :start2 i)))
(cond
(p (let ((p2 (search "m" s :start2 (+ 2 p))))
(assert$
p2
(remove-sgr-1 s (1+ p2) len
(concatenate 'string
acc
(subseq s i p))))))
(t (concatenate 'string acc (subseq s i len))))))
(defun remove-sgr (s)
; The acl2-doc search file, acl2-doc-search, needs to avoid having any SGR
; control sequences, so that searches there can match up with searches in the
; acl2-doc buffer, where those markings have been removed. See comments in the
; definition of sgr-prefix in display.lisp for more on SGR.
(let ((p (search *sgr-prefix* s :start2 0)))
(cond ((null p)
s)
(t (remove-sgr-1 s p (length s) (subseq s 0 p))))))
(defun acl2-doc-print-topic-index (tuple channel state)
; Warning: Do not set the buffer to read-only here, because this
; function may be called repeatedly for the same buffer, e.g., by
; function acl2-doc-search-buffer.
; The fms! call that is commented out just below is equivalent to the code
; below it, but is much slower. Replacing that fms! call reduced the time for
; acl2-doc-print-topic-index-lst under save-rendered, when building the full
; ACL2+books manual 7/18/2021, from 52.50 seconds to 2.74 seconds.
; (fms! "~s0~|Topic: ~@1~|Parent list: (~@2)~|~@3~%~s4~|"
; (list (cons #\0 *acl2-doc-search-separator*)
; (cons #\1 (acl2-doc-fix-symbol-msg (nth 0 tuple)))
; (cons #\2 (acl2-doc-fix-symbol-lst-msg (nth 1 tuple)))
; (cons #\3 (if (equal (length tuple) 4)
; (if (eq (nth 0 tuple) 'TOP)
; ""
; (msg ":DOC source: ~s0~|" (nth 3 tuple)))
; ":DOC source: ACL2 Sources~|"))
; (cons #\4 (nth 2 tuple)))
; channel state nil)
(pprogn (newline channel state)
(princ$ *acl2-doc-search-separator* channel state)
(newline channel state)
(princ$ "Topic: " channel state)
(acl2-doc-print-fix-symbol (nth 0 tuple) channel state)
(newline channel state)
(princ$ "Parent list: (" channel state)
(acl2-doc-print-fix-symbol-lst (nth 1 tuple) channel state)
(princ$ ")" channel state)
(newline channel state)
(if (equal (length tuple) 4)
(if (eq (nth 0 tuple) 'TOP)
state
(pprogn (princ$ ":DOC source: " channel state)
(princ$ (remove-sgr (nth 3 tuple)) channel state)
(newline channel state)))
(pprogn (princ$ ":DOC source: ACL2 Sources" channel state)
(newline channel state)))
(princ$ (remove-sgr (nth 2 tuple)) channel state)
(newline channel state)))
(defun acl2-doc-print-topic-index-lst (tuple-lst channel state)
(cond ((endp tuple-lst) state)
(t (pprogn
(acl2-doc-print-topic-index (car tuple-lst) channel state)
(acl2-doc-print-topic-index-lst (cdr tuple-lst) channel state)))))
(defmacro with-acl2-doc-images (form)
; Form evaluates to (mv val state) and we return (value val), except that form
; is evaluated in an environment where documentation will be printed to be
; rendered with images. We restore the original environment even in the case
; of an error.
; Form should not contain with wadi- variable bound by b* below. We should
; really use something like check-vars-not-free, but this will do. ("Wadi" is
; based on the name of this macro.)
`(b* (((mv - wadi-env-val state)
(getenv$ "ACL2_DOC_IMAGES" state))
((mv - wadi-temp state)
(acl2::acl2-unwind-protect
"with-acl2-doc-images"
(prog2$ (setenv$ "ACL2_DOC_IMAGES" "t")
(mv-let (wadi-temp state)
,form
(value wadi-temp)))
(prog2$ (setenv$ "ACL2_DOC_IMAGES" (or wadi-env-val ""))
state)
(prog2$ (setenv$ "ACL2_DOC_IMAGES" (or wadi-env-val "" ""))
state))))
(value wadi-temp)))
(defun save-rendered (outfile
header
topic-list-name
error ; when true, cause an error on xdoc or Markup error
write-acl2-doc-search-file
state)
; See books/doc/top.lisp for an example call of xdoc::save-rendered. In
; particular, the constant *rendered-doc-combined-header* defined in that file
; is an example of header, which goes at the top of the generated file; and
; topic-list-name is a symbol, such as acl2::*acl2+books-documentation*.
; Below we bind force-missing-parents-p and maybe-add-top-topic-p both true.
; These could be formal parameters if need be.
; Example of outfile:
; (acl2::extend-pathname (cbd)
; "../system/doc/rendered-doc-combined.lsp"
; state))
(let ((force-missing-parents-p t)
(maybe-add-top-topic-p t)
(search-file (if (position acl2::*directory-separator* outfile)
(concatenate 'string
(acl2::get-directory-of-file outfile)
acl2::*directory-separator-string*
"acl2-doc-search")
"acl2-doc-search")))
(state-global-let*
((current-package "ACL2" set-current-package-state))
(b* ((- (initialize-xdoc-errors error))
(state (f-put-global 'broken-links-limit nil state))
((mv ? all-topics0 state)
(all-xdoc-topics state))
(all-topics
(time$
(let* ((all-topics1 (normalize-parents-list ; Should we clean-topics?
all-topics0))
(all-topics2 (if maybe-add-top-topic-p
(maybe-add-top-topic all-topics1)
all-topics1))
(all-topics3 (if force-missing-parents-p
(force-missing-parents all-topics2)
all-topics2)))
all-topics3)))
((er rendered)
(time$ (with-acl2-doc-images
(render-topics all-topics all-topics state))))
(rendered (time$ (split-acl2-topics rendered nil nil nil)))
(- (cw "Writing ~s0~%" outfile))
((mv channel state) (open-output-channel! outfile :character state))
((unless channel)
(cw "can't open ~s0 for output." outfile)
(acl2::silent-error state))
(state (princ$ header channel state))
(state (fms! "(in-package \"ACL2\")~|~%(defconst ~x0 '~|"
(list (cons #\0 topic-list-name))
channel state nil))
; I tried replacing the fms! call below with mostly princ$ calls, but I needed
; a prin1$ call for (at least) the main doc string of each topic (to escape
; characters as necessary, especially double-quote (")). However, the measured
; time reduction was slight, however; 16.77 seconds reduced to 16.03 seconds.
; The bytes allocated were reduced more noticeably, 12,642,544 down to 1,456;
; however, that's trivial compared to more than 22GB allocated by render-topics
; when saving rendered-doc-combined.lsp.
(state (time$ (fms! "~x0"
(list (cons #\0 rendered))
channel state nil)))
(state (fms! ")" nil channel state nil))
(state (newline channel state))
(state (close-output-channel channel state))
(- (report-xdoc-errors 'save-rendered))
((when (not write-acl2-doc-search-file))
(value '(value-triple :ok)))
((mv channel state)
(open-output-channel! search-file :character state))
((unless channel)
(cw "can't open ~s0 for output." search-file)
(acl2::silent-error state))
(state (time$
(acl2-doc-print-topic-index-lst rendered channel state)))
(state (close-output-channel channel state)))
(value '(value-triple :ok))))))
(defmacro save-rendered-event (outfile
header
topic-list-name
error ; when true, cause an error on xdoc or Markup error
&key
script-file ; e.g., for building TAGS-acl2-doc
script-args
timep ; if a surrounding time$ call is desired
write-acl2-doc-search-file
)
(let* ((form1 `(save-rendered
,outfile ,header ,topic-list-name ,error
,write-acl2-doc-search-file state))
(form2 `(prog2$ (let ((script-file ,script-file)
(script-args ,script-args))
(and script-file
(sys-call ; requires active trust tag
script-file script-args)))
,form1))
(form3 (if timep
`(time$ ,form2)
form2)))
`(make-event
,form3)))
|