2
(include-book "defcode" :ttags ((defcode)))
4
(acl2::begin-book t :ttags ((defcode)));$ACL2s-Preamble$|#
7
; cert_param: (non-acl2r)
13
(defun chk-acceptable-redefun (def ctx wrld state)
15
((tuple (chk-acceptable-defuns (list def) ctx wrld state)))
17
(equal (length tuple) 23)
18
(let* ((name (car def))
19
(new-wrld (nth 18 tuple))
21
(getprop name 'symbol-class 0 'current-acl2-world wrld))
22
(new-symbol-class (nth 15 tuple))
24
(getprop name 'formals 0 'current-acl2-world wrld))
26
(getprop name 'formals 0 'current-acl2-world new-wrld))
28
(getprop name 'stobjs-in 0 'current-acl2-world wrld))
30
(getprop name 'stobjs-in 0 'current-acl2-world new-wrld))
32
(getprop name 'stobjs-out 0 'current-acl2-world wrld))
34
(getprop name 'stobjs-out 0 'current-acl2-world new-wrld)))
35
(cond ((eql old-symbol-class 0)
36
(er soft ctx "No existing definition: ~x0" name))
37
((nth 19 tuple) ; non-executablep
39
"Please do not redefun a non-executable function. The ~
40
offending definition is: ~x0."
42
((not (eq ':program old-symbol-class))
44
"Old definition should have defun-mode :program. Sorry."))
45
((not (eq ':program new-symbol-class))
47
"New definition should have defun-mode :program. Sorry."))
48
((not (equal new-formals old-formals))
50
"Please use the same formal parameter list when redefining. ~
51
Previous formals: ~x0"
53
((not (equal new-stobjs-in old-stobjs-in))
55
"New definition should have the same stobjs-in.Previously, ~
57
old-stobjs-in new-stobjs-in))
58
((not (equal new-stobjs-out old-stobjs-out))
60
"New definition should have the same stobjs-out.Previously, ~
62
old-stobjs-out new-stobjs-out))
64
(value :invisible)))))))
67
(include-book "rewrite-code")
69
; this is a safer version of doing defun with redefinition allowed.
71
; only :program mode functions may be used here, because the intent is to
72
; maintain sound reasoning.
74
; lots of checks are performed and actions are taken to prevent the logic from
75
; being tainted by the redefinition.
77
(defmacro redefun (name ll &rest decls-and-body)
78
(declare (xargs :guard (and (symbolp name)
80
(consp decls-and-body))))
81
(let ((def (list* name ll decls-and-body)))
83
(assert-include-defun-matches-certify-defun ,name)
86
(assert-no-special-raw-definition ,name)
87
(chk-acceptable-redefun ',def
91
(ensure-program-only-flag ,name)
96
(if (f-get-global 'safe-mode *the-live-state*)
97
(throw-raw-ev-fncall (list 'program-only-er ',name
98
(list . ,ll) 't '(nil) t))
104
; this uses redefun and our code rewrite stuff (see rewrite-code.lisp,
105
; especially compute-copy-defun+rewrite) to redefine a :program mode
106
; function in terms of its existing definition.
108
(defmacro redefun+rewrite (name &rest rewrite-spec)
109
(declare (xargs :guard (symbolp name)))
111
(compute-copy-defun+rewrite
112
',name ',name ',rewrite-spec 'redefun state)))
118
"defcode" :ttags ((defcode)))
122
(redefun deflabel-fn (name state doc event-form)
123
(declare (ignore doc event-form))
126
(set-guard-checking :none)