/usr/share/acl2-8.0dfsg/books/hacking/bridge.lisp is in acl2-books-source 8.0dfsg-1.
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 | (in-package "ACL2")
(include-book "doc-section")
;Needed to use, but not needed for certification:
;(include-book "defcode" :load-compiled-file :comp :ttags ((defcode)))
(program)
(set-state-ok t)
; return world with last cltl-command global-value replaced with given value
(defun replace-last-cltl-command-wrld (cltl-command wrld)
(declare (xargs :mode :program))
(cond ((endp wrld)
nil)
((and (consp (car wrld))
(eq (caar wrld) 'cltl-command)
(consp (cdar wrld))
(eq (cadar wrld) 'global-value))
(cons
(list* 'cltl-command 'global-value cltl-command)
(cdr wrld)))
(t
(cons
(car wrld)
(replace-last-cltl-command-wrld cltl-command (cdr wrld))))))
(defmacro replace-last-cltl-command (cltl-command)
`(progn!=touchable
:fns set-w!
:loop-only
(pprogn
(set-w! (replace-last-cltl-command-wrld
,(if (and (consp cltl-command)
(symbolp (car cltl-command))
(member-eq (car cltl-command)
'(defuns defstobj defpkg defconst defmacro
memoize unmemoize)))
`',cltl-command ; needs quoting
cltl-command ; might need evaluation
)
(w state))
state)
(value :invisible))))
; return world with last cltl-command global-value removed
(defun remove-last-cltl-command-wrld (wrld)
(declare (xargs :mode :program))
(cond ((endp wrld)
nil)
((and (consp (car wrld))
(eq (caar wrld) 'cltl-command)
(consp (cdar wrld))
(eq (cadar wrld) 'global-value))
(cdr wrld))
(t
(cons
(car wrld)
(remove-last-cltl-command-wrld (cdr wrld))))))
(defmacro remove-last-cltl-command ()
'(progn!=touchable
:fns set-w!
:loop-only
(pprogn
(set-w! (remove-last-cltl-command-wrld (w state)) state)
(value :invisible))))
; convert (declare (...)) or ((...)) or (...) into (declare (...))
(defun reconstruct-declare-lst (spec)
(cond ((atom spec) nil)
((eq 'declare (car spec))
(list spec))
((consp (car spec))
(list (cons 'declare spec)))
(t
(list (list 'declare spec)))))
; for public use
(defmacro defun-bridge (name
ll
.(&key (logic '() logic-p)
(logic-declare '())
(program '() program-p)
(program-declare '())
(raw '() raw-p)
(raw-declare '())
(doc '())))
;;; This legacy doc string was replaced Nov. 2014 by a corresponding
;;; auto-generated defxdoc form in file hacking-xdoc.lisp.
; ":Doc-Section hacker
;
; define a function with a different low-level definition.~/
; ~bv[]
; General Form:
; (defun-bridge ~i[name] (~i[formals])
; [:doc ~i[doc-string]]
; [:loop-declare ~i[loop-decls]]
; :loop ~i[loop-body]
; [:raw-declare ~i[raw-decls]]
; :raw ~i[raw-body])
; ~ev[] ~/
;
; This is much like executing
; ~bv[]
; (defun ~i[name] (~i[formals])
; ~i[doc-string]
; (declare (xargs :mode :program))
; ~i[loop-decls]
; ~i[loop-body])
; ~ev[]
; in ACL2 and then
; ~bv[]
; (defun ~i[name] (~i[formals])
; ~i[raw-decls]
; ~i[raw-body])
; ~ev[]
; in raw Lisp, except that extra checks and bookkeeping make it safer
; than that.
;
; An active ttag is required to use this form (~l[defttag]), because
; it can easily corrupt ACL2 or render it unsound.
; ~/"
(declare (xargs :guard (and (or (and logic-p program-p (not raw-p))
(and logic-p (not program-p) raw-p)
(and (not logic-p) program-p raw-p))
(implies doc
(stringp doc))))
(ignorable program-p))
(let*
((ignorable-decl-lst
(and ll `((declare (ignorable . ,ll)))))
(raw-def-tuple
`(,name ,ll
,@ ignorable-decl-lst
. ,(if raw-p
(append (reconstruct-declare-lst raw-declare)
(list raw))
(append (reconstruct-declare-lst program-declare)
(list program)))))
(loop-def
`(defun ,name
,ll
,@ (and doc (list doc))
. ,(if logic-p
(append
(list '(declare (xargs :mode :logic)))
ignorable-decl-lst
(reconstruct-declare-lst logic-declare)
(list logic))
(append
(list '(declare (xargs :mode :program)))
ignorable-decl-lst
(reconstruct-declare-lst program-declare)
(list program)))))
(code
(list loop-def
(if raw-p
'(remove-last-cltl-command)
`(replace-last-cltl-command
(defuns ,(if logic-p :logic :program) nil
,raw-def-tuple))))))
`(progn
(assert-unbound ,name)
,@ (if logic-p
nil
`((ensure-program-only-flag ,name)))
(ensure-special-raw-definition-flag ,name)
(defcode
:loop ,code
,@ (and raw-p
`(:extend (in-raw-mode (maybe-push-undo-stack 'defun ',name)
(defun . ,raw-def-tuple)
(defun-*1* ,name ,ll (,name . ,ll)))
:retract (in-raw-mode (maybe-pop-undo-stack ',name))))
:compile ((defun . ,raw-def-tuple)
. ,(and raw-p `((defun-*1* ,name ,ll (,name . ,ll)))))))))
; tests and stuff:
#|
(include-book
"defcode" :ttags ((defcode)))
(defttag t)
(defun-bridge foo (x)
:program x
:raw (progn (format t "~a~%" x)
x))
(foo 42)
(set-guard-checking :none)
(foo 42)
(defmacro bar ()
(foo nil))
(bar)
|#
|