/[cmucl]/src/pcl/env.lisp
ViewVC logotype

Contents of /src/pcl/env.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Sat Oct 19 16:44:42 1991 UTC (22 years, 6 months ago) by ram
Changes since 1.1: +4 -39 lines
*** empty log message ***
1 ;;;-*-Mode:LISP; Package:(PCL (LISP WALKER)); Base:10; Syntax:Common-lisp -*-
2 ;;;
3 ;;; *************************************************************************
4 ;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
5 ;;; All rights reserved.
6 ;;;
7 ;;; Use and copying of this software and preparation of derivative works
8 ;;; based upon this software are permitted. Any distribution of this
9 ;;; software or derivative works must comply with all applicable United
10 ;;; States export control laws.
11 ;;;
12 ;;; This software is made available AS IS, and Xerox Corporation makes no
13 ;;; warranty about the software, its performance or its conformity to any
14 ;;; specification.
15 ;;;
16 ;;; Any person obtaining a copy of this software is requested to send their
17 ;;; name and post office or electronic mail address to:
18 ;;; CommonLoops Coordinator
19 ;;; Xerox PARC
20 ;;; 3333 Coyote Hill Rd.
21 ;;; Palo Alto, CA 94304
22 ;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
23 ;;;
24 ;;; Suggestions, comments and requests for improvements are also welcome.
25 ;;; *************************************************************************
26 ;;;
27 ;;; Basic environmental stuff.
28 ;;;
29
30 (in-package 'pcl)
31
32 #+Lucid
33 (progn
34
35 (defvar *old-arglist*)
36
37 (defun pcl-arglist (function &rest other-args)
38 (let ((defn nil))
39 (cond ((and (fsc-instance-p function)
40 (generic-function-p function))
41 (generic-function-pretty-arglist function))
42 ((and (symbolp function)
43 (fboundp function)
44 (setq defn (symbol-function function))
45 (fsc-instance-p defn)
46 (generic-function-p defn))
47 (generic-function-pretty-arglist defn))
48 (t (apply *old-arglist* function other-args)))))
49
50 (eval-when (eval load)
51 (unless (boundp '*old-arglist*)
52 (setq *old-arglist* (symbol-function 'sys::arglist))
53 (setf (symbol-function 'sys::arglist) #'pcl-arglist)))
54
55 )
56
57
58 ;;;
59 ;;;
60 ;;;
61
62 (defgeneric describe-object (object stream))
63
64 #-Genera (progn
65
66 (defvar *old-describe* ())
67
68 (eval-when (load)
69 (unless *old-describe* (setq *old-describe* (symbol-function 'describe)))
70 (setf (symbol-function 'describe)
71 #+Lispm
72 #'(lambda (object &optional no-complaints)
73 (let ((*describe-no-complaints* no-complaints))
74 (declare (special *describe-no-complaints*))
75 (describe-object object *standard-output*)
76 (values)))
77 #-Lispm
78 #'(lambda (object)
79 (describe-object object *standard-output*)
80 (values))))
81
82 (defmethod describe-object (object stream)
83 (let ((*standard-output* stream))
84 (funcall *old-describe* object)))
85 )
86
87 (defmethod describe-object ((object standard-object) stream)
88 (let* ((class (class-of object))
89 (slotds (slots-to-inspect class object))
90 (max-slot-name-length 0)
91 (instance-slotds ())
92 (class-slotds ())
93 (other-slotds ()))
94 (flet ((adjust-slot-name-length (name)
95 (setq max-slot-name-length
96 (max max-slot-name-length
97 (length (the string (symbol-name name))))))
98 (describe-slot (name value &optional (allocation () alloc-p))
99 (if alloc-p
100 (format stream
101 "~% ~A ~S ~VT ~S"
102 name allocation (+ max-slot-name-length 7) value)
103 (format stream
104 "~% ~A~VT ~S"
105 name max-slot-name-length value))))
106 ;; Figure out a good width for the slot-name column.
107 (dolist (slotd slotds)
108 (adjust-slot-name-length (slotd-name slotd))
109 (case (slotd-allocation slotd)
110 (:instance (push slotd instance-slotds))
111 (:class (push slotd class-slotds))
112 (otherwise (push slotd other-slotds))))
113 (setq max-slot-name-length (min (+ max-slot-name-length 3) 30))
114 (format stream "~%~S is an instance of class ~S:" object class)
115
116 (when instance-slotds
117 (format stream "~% The following slots have :INSTANCE allocation:")
118 (dolist (slotd (nreverse instance-slotds))
119 (describe-slot (slotd-name slotd)
120 (slot-value-or-default object (slotd-name slotd)))))
121
122 (when class-slotds
123 (format stream "~% The following slots have :CLASS allocation:")
124 (dolist (slotd (nreverse class-slotds))
125 (describe-slot (slotd-name slotd)
126 (slot-value-or-default object (slotd-name slotd)))))
127
128 (when other-slotds
129 (format stream "~% The following slots have allocation as shown:")
130 (dolist (slotd (nreverse other-slotds))
131 (describe-slot (slotd-name slotd)
132 (slot-value-or-default object (slotd-name slotd))
133 (slotd-allocation slotd))))
134 (values))))
135
136 (defmethod slots-to-inspect ((class std-class) (object standard-object))
137 (class-slots class))
138
139 ;;;
140 ;;;
141 ;;;
142 (defmethod describe-object ((class class) stream)
143 (flet ((pretty-class (c) (or (class-name c) c)))
144 (macrolet ((ft (string &rest args) `(format stream ,string ,@args)))
145 (ft "~&~S is a class, it is an instance of ~S.~%"
146 class (pretty-class (class-of class)))
147 (let ((name (class-name class)))
148 (if name
149 (if (eq class (find-class name nil))
150 (ft "Its proper name is ~S.~%" name)
151 (ft "Its name is ~S, but this is not a proper name.~%" name))
152 (ft "It has no name (the name is NIL).~%")))
153 (ft "The direct superclasses are: ~:S, and the direct~%~
154 subclasses are: ~:S. The class precedence list is:~%~S~%~
155 There are ~D methods specialized for this class."
156 (mapcar #'pretty-class (class-direct-superclasses class))
157 (mapcar #'pretty-class (class-direct-subclasses class))
158 (mapcar #'pretty-class (class-precedence-list class))
159 (length (specializer-methods class))))))
160
161
162
163 ;;;
164 ;;; trace-method and untrace-method accept method specs as arguments. A
165 ;;; method-spec should be a list like:
166 ;;; (<generic-function-spec> qualifiers* (specializers*))
167 ;;; where <generic-function-spec> should be either a symbol or a list
168 ;;; of (SETF <symbol>).
169 ;;;
170 ;;; For example, to trace the method defined by:
171 ;;;
172 ;;; (defmethod foo ((x spaceship)) 'ss)
173 ;;;
174 ;;; You should say:
175 ;;;
176 ;;; (trace-method '(foo (spaceship)))
177 ;;;
178 ;;; You can also provide a method object in the place of the method
179 ;;; spec, in which case that method object will be traced.
180 ;;;
181 ;;; For untrace-method, if an argument is given, that method is untraced.
182 ;;; If no argument is given, all traced methods are untraced.
183 ;;;
184 (defclass traced-method (method)
185 ((method :initarg :method)
186 (function :initarg :function
187 :reader method-function)
188 (generic-function :initform nil
189 :accessor method-generic-function)))
190
191 (defmethod method-lambda-list ((m traced-method))
192 (with-slots (method) m (method-lambda-list method)))
193
194 (defmethod method-specializers ((m traced-method))
195 (with-slots (method) m (method-specializers method)))
196
197 (defmethod method-qualifiers ((m traced-method))
198 (with-slots (method) m (method-qualifiers method)))
199
200 (defmethod method-qualifiers ((m traced-method))
201 (with-slots (method) m (method-qualifiers method)))
202
203 (defmethod accessor-method-slot-name ((m traced-method))
204 (with-slots (method) m (accessor-method-slot-name method)))
205
206 (defvar *traced-methods* ())
207
208 (defun trace-method (spec &rest options)
209 (multiple-value-bind (gf omethod name)
210 (parse-method-or-spec spec)
211 (let* ((tfunction (trace-method-internal (method-function omethod)
212 name
213 options))
214 (tmethod (make-instance 'traced-method
215 :method omethod
216 :function tfunction)))
217 (remove-method gf omethod)
218 (add-method gf tmethod)
219 (pushnew tmethod *traced-methods*)
220 tmethod)))
221
222 (defun untrace-method (&optional spec)
223 (flet ((untrace-1 (m)
224 (let ((gf (method-generic-function m)))
225 (when gf
226 (remove-method gf m)
227 (add-method gf (slot-value m 'method))
228 (setq *traced-methods* (remove m *traced-methods*))))))
229 (if (not (null spec))
230 (multiple-value-bind (gf method)
231 (parse-method-or-spec spec)
232 (declare (ignore gf))
233 (if (memq method *traced-methods*)
234 (untrace-1 method)
235 (error "~S is not a traced method?" method)))
236 (dolist (m *traced-methods*) (untrace-1 m)))))
237
238 (defun trace-method-internal (ofunction name options)
239 (eval `(untrace ,name))
240 (setf (symbol-function name) ofunction)
241 (eval `(trace ,name ,@options))
242 (symbol-function name))
243
244
245
246
247 ;(defun compile-method (spec)
248 ; (multiple-value-bind (gf method name)
249 ; (parse-method-or-spec spec)
250 ; (declare (ignore gf))
251 ; (compile name (method-function method))
252 ; (setf (method-function method) (symbol-function name))))
253
254 (defmacro undefmethod (&rest args)
255 #+(or (not :lucid) :lcl3.0)
256 (declare (arglist name {method-qualifier}* specializers))
257 `(undefmethod-1 ',args))
258
259 (defun undefmethod-1 (args)
260 (multiple-value-bind (gf method)
261 (parse-method-or-spec args)
262 (when (and gf method)
263 (remove-method gf method)
264 method)))
265
266

  ViewVC Help
Powered by ViewVC 1.1.5