1
;;;============================================================================
3
;;; Generic theory tools.
5
;;;============================================================================
9
(certify-book "generic-theory")
15
;;;----------------------------------------------------------------------------
17
;;; Tools to obtain the event list:
19
;;;----------------------------------------------------------------------------
21
(defun get-event-lst-fn (event-name-lst wrld)
22
(declare (xargs :mode :program))
23
(cond ((endp event-name-lst) nil)
24
(t (cons (get-event (car event-name-lst) wrld)
25
(get-event-lst-fn (cdr event-name-lst) wrld)))))
27
(defmacro get-event-lst (event-name-lst)
28
`(get-event-lst-fn ,event-name-lst (w state)))
30
;;; Use this as follows
34
; (get-event-lst <event-name-lst>) => <event-lst>
42
;;;----------------------------------------------------------------------------
44
;;; Tools to instantiate the generic theory:
46
;;;----------------------------------------------------------------------------
50
(defun subst-equal (old new tree)
51
(cond ((equal old tree) new)
53
(t (cons (subst-equal old new (car tree))
54
(subst-equal old new (cdr tree))))))
56
(defun subst-equal-lst (lst tree)
57
(cond ((endp lst) tree)
58
(t (subst-equal-lst (cdr lst)
59
(subst-equal (caar lst) (cadar lst) tree)))))
61
;;; Generating new names:
63
(defun packn-string-in-pkg (string pkg-witness)
64
(declare (xargs :mode :program))
65
(intern-in-package-of-symbol string pkg-witness))
67
(defun add-name-subst (name subst suffix)
68
(declare (xargs :mode :program))
70
(packn-string-in-pkg (string-append (string name) suffix) name))
73
;;; Generating the instantiation:
75
(defun remove-old-hints (event)
76
(cond ((endp event) nil)
77
((eq ':hints (car event))
79
(t (cons (car event) (remove-old-hints (cdr event))))))
81
(defun functional-instance (event old-name subst)
82
(append (remove-old-hints event)
85
(:functional-instance ,old-name ,@subst))))))
87
(defun functional-instance-lst (event-lst subst suffix)
88
(declare (xargs :mode :program))
89
(cond ((endp event-lst) nil)
90
((equal (car (car event-lst)) 'defun)
92
(add-name-subst (cadr (car event-lst)) subst suffix)))
93
(cons (subst-equal-lst new-subst (car event-lst))
94
(functional-instance-lst (cdr event-lst) new-subst suffix))))
95
((equal (car (car event-lst)) 'defthm)
97
(add-name-subst (cadr (car event-lst)) subst suffix)))
98
(cons (functional-instance
99
(subst-equal-lst new-subst (car event-lst))
100
(cadr (car event-lst))
102
(functional-instance-lst (cdr event-lst) subst suffix))))
103
(t (functional-instance-lst (cdr event-lst) subst suffix))))
105
(defmacro make-generic-theory (theory)
106
(let ((definstance-theory
108
(string-append "DEFINSTANCE-" (string theory)) theory)))
109
`(defmacro ,definstance-theory (subst suffix)
112
(functional-instance-lst ,theory subst
113
(string-upcase suffix))))
116
;;; This must be use as follows:
120
(make-generic-theory *theory*)
124
;;;============================================================================