1 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; This software is derived from software originally released by Xerox
5 ;;;; Corporation. Copyright and release statements follow. Later modifications
6 ;;;; to the software are in the public domain and are provided with
7 ;;;; absolutely no warranty. See the COPYING and CREDITS files for more
10 ;;;; copyright information from original PCL sources:
12 ;;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
13 ;;;; All rights reserved.
15 ;;;; Use and copying of this software and preparation of derivative works based
16 ;;;; upon this software are permitted. Any distribution of this software or
17 ;;;; derivative works must comply with all applicable United States export
20 ;;;; This software is made available AS IS, and Xerox Corporation makes no
21 ;;;; warranty about the software, its performance or its conformity to any
29 ;;; Methods themselves are simple inanimate objects. Most properties of
30 ;;; methods are immutable, methods cannot be reinitialized. The following
31 ;;; properties of methods can be changed:
32 ;;; METHOD-GENERIC-FUNCTION
33 ;;; METHOD-FUNCTION ??
35 (defmethod method-function ((method standard-method))
36 (or (slot-value method 'function)
37 (let ((fmf (slot-value method 'fast-function)))
38 (unless fmf ; The :BEFORE SHARED-INITIALIZE method prevents this.
39 (error "~S doesn't seem to have a METHOD-FUNCTION." method))
40 (setf (slot-value method 'function)
41 (method-function-from-fast-function fmf)))))
43 (defmethod accessor-method-class ((method standard-accessor-method))
44 (car (slot-value method 'specializers)))
46 (defmethod accessor-method-class ((method standard-writer-method))
47 (cadr (slot-value method 'specializers)))
51 ;;; Error checking is done in before methods. Because of the simplicity of
52 ;;; standard method objects the standard primary method can fill the slots.
54 ;;; Methods are not reinitializable.
56 (defmethod reinitialize-instance ((method standard-method) &rest initargs)
57 (declare (ignore initargs))
58 (error "An attempt was made to reinitialize the method ~S.~%~
59 Method objects cannot be reinitialized."
62 (defmethod legal-documentation-p ((object standard-method) x)
63 (if (or (null x) (stringp x))
67 (defmethod legal-lambda-list-p ((object standard-method) x)
71 (defmethod legal-method-function-p ((object standard-method) x)
76 (defmethod legal-qualifiers-p ((object standard-method) x)
77 (flet ((improper-list ()
78 (return-from legal-qualifiers-p "Is not a proper list.")))
79 (dolist-carefully (q x improper-list)
80 (let ((ok (legal-qualifier-p object q)))
82 (return-from legal-qualifiers-p
83 (format nil "Contains ~S which ~A" q ok)))))
86 (defmethod legal-qualifier-p ((object standard-method) x)
89 "is not a non-null atom"))
91 (defmethod legal-slot-name-p ((object standard-method) x)
92 (cond ((not (symbolp x)) "is not a symbol and so cannot be bound")
93 ((keywordp x) "is a keyword and so cannot be bound")
94 ((memq x '(t nil)) "cannot be bound")
95 ((constantp x) "is a constant and so cannot be bound")
98 (defmethod legal-specializers-p ((object standard-method) x)
99 (flet ((improper-list ()
100 (return-from legal-specializers-p "Is not a proper list.")))
101 (dolist-carefully (s x improper-list)
102 (let ((ok (legal-specializer-p object s)))
104 (return-from legal-specializers-p
105 (format nil "Contains ~S which ~A" s ok)))))
108 (defvar *allow-experimental-specializers-p* nil)
110 (defmethod legal-specializer-p ((object standard-method) x)
111 (if (if *allow-experimental-specializers-p*
114 (eql-specializer-p x)))
116 "is neither a class object nor an EQL specializer"))
118 (defmethod shared-initialize :before ((method standard-method)
126 (declare (ignore slot-names))
127 (flet ((lose (initarg value string)
128 (error "when initializing the method ~S:~%~
129 The ~S initialization argument was: ~S.~%~
131 method initarg value string)))
132 (let ((check-qualifiers (legal-qualifiers-p method qualifiers))
133 (check-lambda-list (legal-lambda-list-p method lambda-list))
134 (check-specializers (legal-specializers-p method specializers))
135 (check-fun (legal-method-function-p method
138 (check-documentation (legal-documentation-p method documentation)))
139 (unless (eq check-qualifiers t)
140 (lose :qualifiers qualifiers check-qualifiers))
141 (unless (eq check-lambda-list t)
142 (lose :lambda-list lambda-list check-lambda-list))
143 (unless (eq check-specializers t)
144 (lose :specializers specializers check-specializers))
145 (unless (eq check-fun t)
146 (lose :function function check-fun))
147 (unless (eq check-documentation t)
148 (lose :documentation documentation check-documentation)))))
150 (defmethod shared-initialize :before ((method standard-accessor-method)
152 &key slot-name slot-definition)
153 (declare (ignore slot-names))
154 (unless slot-definition
155 (let ((legalp (legal-slot-name-p method slot-name)))
156 ;; FIXME: nasty convention; should be renamed to ILLEGAL-SLOT-NAME-P and
157 ;; ILLEGALP, and the convention redone to be less twisty
158 (unless (eq legalp t)
159 (error "The value of the :SLOT-NAME initarg ~A." legalp)))))
161 (defmethod shared-initialize :after ((method standard-method) slot-names
163 &key qualifiers method-spec plist)
164 (declare (ignore slot-names method-spec plist))
165 (initialize-method-function initargs nil method)
166 (setf (plist-value method 'qualifiers) qualifiers)
168 (setf (slot-value method 'closure-generator)
169 (method-function-closure-generator (slot-value method 'function))))
171 (defmethod shared-initialize :after ((method standard-accessor-method)
174 (declare (ignore slot-names))
175 (with-slots (slot-name slot-definition)
177 (unless slot-definition
178 (let ((class (accessor-method-class method)))
179 (when (slot-class-p class)
180 (setq slot-definition (find slot-name (class-direct-slots class)
181 :key #'slot-definition-name)))))
182 (when (and slot-definition (null slot-name))
183 (setq slot-name (slot-definition-name slot-definition)))))
185 (defmethod method-qualifiers ((method standard-method))
186 (plist-value method 'qualifiers))
188 (defvar *the-class-generic-function*
189 (find-class 'generic-function))
190 (defvar *the-class-standard-generic-function*
191 (find-class 'standard-generic-function))
193 (defmethod shared-initialize :before
194 ((generic-function standard-generic-function)
196 &key (name nil namep)
197 (lambda-list () lambda-list-p)
198 argument-precedence-order
201 (method-class nil method-class-supplied-p)
202 (method-combination nil method-combination-supplied-p))
203 (declare (ignore slot-names
204 declarations argument-precedence-order documentation
205 lambda-list lambda-list-p))
208 (set-fun-name generic-function name))
210 (flet ((initarg-error (initarg value string)
211 (error "when initializing the generic function ~S:~%~
212 The ~S initialization argument was: ~A.~%~
214 generic-function initarg value string)))
215 (cond (method-class-supplied-p
216 (when (symbolp method-class)
217 (setq method-class (find-class method-class)))
218 (unless (and (classp method-class)
219 (*subtypep (class-eq-specializer method-class)
221 (initarg-error :method-class
223 "a subclass of the class METHOD"))
224 (setf (slot-value generic-function 'method-class) method-class))
225 ((slot-boundp generic-function 'method-class))
227 (initarg-error :method-class
229 "a subclass of the class METHOD")))
230 (cond (method-combination-supplied-p
231 (unless (method-combination-p method-combination)
232 (initarg-error :method-combination
234 "a method combination object")))
235 ((slot-boundp generic-function 'method-combination))
237 (initarg-error :method-combination
239 "a method combination object")))))
242 (defmethod reinitialize-instance ((generic-function standard-generic-function)
246 argument-precedence-order
251 (declare (ignore documentation declarations argument-precedence-order
252 lambda-list name method-class method-combination))
253 (macrolet ((add-initarg (check name slot-name)
255 (push (slot-value generic-function ,slot-name) initargs)
256 (push ,name initargs))))
257 ; (add-initarg name :name 'name)
258 ; (add-initarg lambda-list :lambda-list 'lambda-list)
259 ; (add-initarg argument-precedence-order
260 ; :argument-precedence-order
261 ; 'argument-precedence-order)
262 ; (add-initarg declarations :declarations 'declarations)
263 ; (add-initarg documentation :documentation 'documentation)
264 ; (add-initarg method-class :method-class 'method-class)
265 ; (add-initarg method-combination :method-combination 'method-combination)
266 (apply #'call-next-method generic-function initargs)))
269 ;;; These three are scheduled for demolition.
271 (defmethod remove-named-method (generic-function-name argument-specifiers
273 (let ((generic-function ())
275 (cond ((or (null (fboundp generic-function-name))
276 (not (generic-function-p
277 (setq generic-function
278 (fdefinition generic-function-name)))))
279 (error "~S does not name a generic function."
280 generic-function-name))
281 ((null (setq method (get-method generic-function
286 (error "There is no method for the generic function ~S~%~
287 which matches the ARGUMENT-SPECIFIERS ~S."
289 argument-specifiers))
291 (remove-method generic-function method)))))
293 (defun real-add-named-method (generic-function-name
297 &rest other-initargs)
298 (unless (and (fboundp generic-function-name)
299 (typep (fdefinition generic-function-name) 'generic-function))
300 (sb-kernel::style-warn "implicitly creating new generic function ~S"
301 generic-function-name))
302 ;; XXX What about changing the class of the generic function if
303 ;; there is one? Whose job is that, anyway? Do we need something
304 ;; kind of like CLASS-FOR-REDEFINITION?
305 (let* ((generic-function
306 (ensure-generic-function generic-function-name))
307 (specs (parse-specializers specializers))
308 (proto (method-prototype-for-gf generic-function-name))
309 (new (apply #'make-instance (class-of proto)
310 :qualifiers qualifiers
312 :lambda-list lambda-list
314 (add-method generic-function new)))
316 (defun real-get-method (generic-function qualifiers specializers
317 &optional (errorp t))
319 (dolist (method (generic-function-methods generic-function))
320 (when (and (equal qualifiers (method-qualifiers method))
321 (every #'same-specializer-p specializers
322 (method-specializers method)))
327 (error "no method on ~S with qualifiers ~:S and specializers ~:S"
328 generic-function qualifiers specializers)))))
330 (defmethod find-method ((generic-function standard-generic-function)
331 qualifiers specializers &optional (errorp t))
332 (real-get-method generic-function qualifiers
333 (parse-specializers specializers) errorp))
335 ;;; Compute various information about a generic-function's arglist by looking
336 ;;; at the argument lists of the methods. The hair for trying not to use
337 ;;; &REST arguments lives here.
338 ;;; The values returned are:
339 ;;; number-of-required-arguments
340 ;;; the number of required arguments to this generic-function's
341 ;;; discriminating function
343 ;;; whether or not this generic-function's discriminating
344 ;;; function takes an &rest argument.
345 ;;; specialized-argument-positions
346 ;;; a list of the positions of the arguments this generic-function
347 ;;; specializes (e.g. for a classical generic-function this is the
349 (defmethod compute-discriminating-function-arglist-info
350 ((generic-function standard-generic-function))
351 ;;(declare (values number-of-required-arguments &rest-argument-p
352 ;; specialized-argument-postions))
353 (let ((number-required nil)
355 (specialized-positions ())
356 (methods (generic-function-methods generic-function)))
357 (dolist (method methods)
358 (multiple-value-setq (number-required restp specialized-positions)
359 (compute-discriminating-function-arglist-info-internal
360 generic-function method number-required restp specialized-positions)))
361 (values number-required restp (sort specialized-positions #'<))))
363 (defun compute-discriminating-function-arglist-info-internal
364 (generic-function method number-of-requireds restp
365 specialized-argument-positions)
366 (declare (ignore generic-function)
367 (type (or null fixnum) number-of-requireds))
369 (declare (fixnum requireds))
370 ;; Go through this methods arguments seeing how many are required,
371 ;; and whether there is an &rest argument.
372 (dolist (arg (method-lambda-list method))
373 (cond ((eq arg '&aux) (return))
374 ((memq arg '(&optional &rest &key))
375 (return (setq restp t)))
376 ((memq arg lambda-list-keywords))
377 (t (incf requireds))))
378 ;; Now go through this method's type specifiers to see which
379 ;; argument positions are type specified. Treat T specially
380 ;; in the usual sort of way. For efficiency don't bother to
381 ;; keep specialized-argument-positions sorted, rather depend
382 ;; on our caller to do that.
384 (dolist (type-spec (method-specializers method))
385 (unless (eq type-spec *the-class-t*)
386 (pushnew pos specialized-argument-positions))
388 ;; Finally merge the values for this method into the values
389 ;; for the exisiting methods and return them. Note that if
390 ;; num-of-requireds is NIL it means this is the first method
391 ;; and we depend on that.
392 (values (min (or number-of-requireds requireds) requireds)
394 (and number-of-requireds (/= number-of-requireds requireds)))
395 specialized-argument-positions)))
397 (defun make-discriminating-function-arglist (number-required-arguments restp)
398 (nconc (let ((args nil))
399 (dotimes (i number-required-arguments)
400 (push (intern (format nil "Discriminating Function Arg ~D" i))
404 `(&rest ,(intern "Discriminating Function &rest Arg")))))
406 (defmethod generic-function-argument-precedence-order
407 ((gf standard-generic-function))
408 (aver (eq *boot-state* 'complete))
409 (loop with arg-info = (gf-arg-info gf)
410 with lambda-list = (arg-info-lambda-list arg-info)
411 for argument-position in (arg-info-precedence arg-info)
412 collect (nth argument-position lambda-list)))
414 (defmethod generic-function-lambda-list ((gf generic-function))
417 (defmethod gf-fast-method-function-p ((gf standard-generic-function))
418 (gf-info-fast-mf-p (slot-value gf 'arg-info)))
420 (defmethod initialize-instance :after ((gf standard-generic-function)
421 &key (lambda-list nil lambda-list-p)
422 argument-precedence-order)
423 (with-slots (arg-info)
427 :lambda-list lambda-list
428 :argument-precedence-order argument-precedence-order)
430 (when (arg-info-valid-p arg-info)
433 (defmethod reinitialize-instance :after ((gf standard-generic-function)
435 &key (lambda-list nil lambda-list-p)
436 (argument-precedence-order
437 nil argument-precedence-order-p))
438 (with-slots (arg-info)
441 (if argument-precedence-order-p
443 :lambda-list lambda-list
444 :argument-precedence-order argument-precedence-order)
446 :lambda-list lambda-list))
448 (when (and (arg-info-valid-p arg-info)
450 (or lambda-list-p (cddr args)))
453 (declaim (special *lazy-dfun-compute-p*))
455 (defun set-methods (gf methods)
456 (setf (generic-function-methods gf) nil)
457 (loop (when (null methods) (return gf))
458 (real-add-method gf (pop methods) methods)))
460 (defun real-add-method (generic-function method &optional skip-dfun-update-p)
461 (if (method-generic-function method)
462 (error "The method ~S is already part of the generic~@
463 function ~S. It can't be added to another generic~@
464 function until it is removed from the first one."
465 method (method-generic-function method))
467 (let* ((name (generic-function-name generic-function))
468 (qualifiers (method-qualifiers method))
469 (specializers (method-specializers method))
470 (existing (get-method generic-function
475 ;; If there is already a method like this one then we must
476 ;; get rid of it before proceeding. Note that we call the
477 ;; generic function remove-method to remove it rather than
478 ;; doing it in some internal way.
479 (when existing (remove-method generic-function existing))
481 (setf (method-generic-function method) generic-function)
482 (pushnew method (generic-function-methods generic-function))
483 (dolist (specializer specializers)
484 (add-direct-method specializer method))
485 (set-arg-info generic-function :new-method method)
486 (unless skip-dfun-update-p
488 '(make-instance default-initargs
489 allocate-instance shared-initialize
490 initialize-instance))
491 (update-make-instance-function-table (type-class
492 (car specializers))))
493 (update-dfun generic-function))
496 (defun real-remove-method (generic-function method)
497 ;; Note: Error check prohibited by ANSI spec removed.
498 (when (eq generic-function (method-generic-function method))
499 (let* ((name (generic-function-name generic-function))
500 (specializers (method-specializers method))
501 (methods (generic-function-methods generic-function))
502 (new-methods (remove method methods)))
503 (setf (method-generic-function method) nil)
504 (setf (generic-function-methods generic-function) new-methods)
505 (dolist (specializer (method-specializers method))
506 (remove-direct-method specializer method))
507 (set-arg-info generic-function)
511 allocate-instance shared-initialize initialize-instance))
512 (update-make-instance-function-table (type-class (car specializers))))
513 (update-dfun generic-function)
516 (defun compute-applicable-methods-function (generic-function arguments)
517 (values (compute-applicable-methods-using-types
519 (types-from-args generic-function arguments 'eql))))
521 (defmethod compute-applicable-methods
522 ((generic-function generic-function) arguments)
523 (values (compute-applicable-methods-using-types
525 (types-from-args generic-function arguments 'eql))))
527 (defmethod compute-applicable-methods-using-classes
528 ((generic-function generic-function) classes)
529 (compute-applicable-methods-using-types
531 (types-from-args generic-function classes 'class-eq)))
533 (defun proclaim-incompatible-superclasses (classes)
534 (setq classes (mapcar (lambda (class)
539 (dolist (class classes)
540 (dolist (other-class classes)
541 (unless (eq class other-class)
542 (pushnew other-class (class-incompatible-superclass-list class))))))
544 (defun superclasses-compatible-p (class1 class2)
545 (let ((cpl1 (class-precedence-list class1))
546 (cpl2 (class-precedence-list class2)))
548 (dolist (ic (class-incompatible-superclass-list sc1))
550 (return-from superclasses-compatible-p nil))))))
553 #'proclaim-incompatible-superclasses
554 '(;; superclass class
555 (built-in-class std-class structure-class) ; direct subclasses of pcl-class
556 (standard-class funcallable-standard-class)
557 ;; superclass metaobject
558 (class eql-specializer class-eq-specializer method method-combination
559 generic-function slot-definition)
560 ;; metaclass built-in-class
561 (number sequence character ; direct subclasses of t, but not array
562 standard-object structure-object) ; or symbol
563 (number array character symbol ; direct subclasses of t, but not
564 standard-object structure-object) ; sequence
565 (complex float rational) ; direct subclasses of number
566 (integer ratio) ; direct subclasses of rational
567 (list vector) ; direct subclasses of sequence
568 (cons null) ; direct subclasses of list
569 (string bit-vector) ; direct subclasses of vector
572 (defmethod same-specializer-p ((specl1 specializer) (specl2 specializer))
575 (defmethod same-specializer-p ((specl1 class) (specl2 class))
578 (defmethod specializer-class ((specializer class))
581 (defmethod same-specializer-p ((specl1 class-eq-specializer)
582 (specl2 class-eq-specializer))
583 (eq (specializer-class specl1) (specializer-class specl2)))
585 (defmethod same-specializer-p ((specl1 eql-specializer)
586 (specl2 eql-specializer))
587 (eq (specializer-object specl1) (specializer-object specl2)))
589 (defmethod specializer-class ((specializer eql-specializer))
590 (class-of (slot-value specializer 'object)))
592 (defvar *in-gf-arg-info-p* nil)
593 (setf (gdefinition 'arg-info-reader)
594 (let ((mf (initialize-method-function
595 (make-internal-reader-method-function
596 'standard-generic-function 'arg-info)
598 (lambda (&rest args) (funcall mf args nil))))
601 (defun error-need-at-least-n-args (function n)
602 (error "~@<The function ~2I~_~S ~I~_requires at least ~W argument~:P.~:>"
606 (defun types-from-args (generic-function arguments &optional type-modifier)
607 (multiple-value-bind (nreq applyp metatypes nkeys arg-info)
608 (get-generic-fun-info generic-function)
609 (declare (ignore applyp metatypes nkeys))
610 (let ((types-rev nil))
611 (dotimes-fixnum (i nreq)
614 (error-need-at-least-n-args (generic-function-name generic-function)
616 (let ((arg (pop arguments)))
617 (push (if type-modifier `(,type-modifier ,arg) arg) types-rev)))
618 (values (nreverse types-rev) arg-info))))
620 (defun get-wrappers-from-classes (nkeys wrappers classes metatypes)
621 (let* ((w wrappers) (w-tail w) (mt-tail metatypes))
622 (dolist (class (if (listp classes) classes (list classes)))
623 (unless (eq t (car mt-tail))
624 (let ((c-w (class-wrapper class)))
625 (unless c-w (return-from get-wrappers-from-classes nil))
628 (setf (car w-tail) c-w
629 w-tail (cdr w-tail)))))
630 (setq mt-tail (cdr mt-tail)))
633 (defun sdfun-for-caching (gf classes)
634 (let ((types (mapcar #'class-eq-type classes)))
635 (multiple-value-bind (methods all-applicable-and-sorted-p)
636 (compute-applicable-methods-using-types gf types)
637 (function-funcall (get-secondary-dispatch-function1
638 gf methods types nil t all-applicable-and-sorted-p)
639 nil (mapcar #'class-wrapper classes)))))
641 (defun value-for-caching (gf classes)
642 (let ((methods (compute-applicable-methods-using-types
643 gf (mapcar #'class-eq-type classes))))
644 (method-function-get (or (method-fast-function (car methods))
645 (method-function (car methods)))
648 (defun default-secondary-dispatch-function (generic-function)
650 (let ((methods (compute-applicable-methods generic-function args)))
652 (let ((emf (get-effective-method-function generic-function
654 (invoke-emf emf args))
655 (apply #'no-applicable-method generic-function args)))))
658 (loop (when (atom x) (return (eq x y)))
659 (when (atom y) (return nil))
660 (unless (eq (car x) (car y)) (return nil))
661 (setq x (cdr x) y (cdr y))))
663 (defvar *std-cam-methods* nil)
665 (defun compute-applicable-methods-emf (generic-function)
666 (if (eq *boot-state* 'complete)
667 (let* ((cam (gdefinition 'compute-applicable-methods))
668 (cam-methods (compute-applicable-methods-using-types
669 cam (list `(eql ,generic-function) t))))
670 (values (get-effective-method-function cam cam-methods)
672 (or *std-cam-methods*
673 (setq *std-cam-methods*
674 (compute-applicable-methods-using-types
675 cam (list `(eql ,cam) t)))))))
676 (values #'compute-applicable-methods-function t)))
678 (defun compute-applicable-methods-emf-std-p (gf)
679 (gf-info-c-a-m-emf-std-p (gf-arg-info gf)))
681 (defvar *old-c-a-m-gf-methods* nil)
683 (defun update-all-c-a-m-gf-info (c-a-m-gf)
684 (let ((methods (generic-function-methods c-a-m-gf)))
685 (if (and *old-c-a-m-gf-methods*
686 (every (lambda (old-method)
687 (member old-method methods))
688 *old-c-a-m-gf-methods*))
689 (let ((gfs-to-do nil)
690 (gf-classes-to-do nil))
691 (dolist (method methods)
692 (unless (member method *old-c-a-m-gf-methods*)
693 (let ((specl (car (method-specializers method))))
694 (if (eql-specializer-p specl)
695 (pushnew (specializer-object specl) gfs-to-do)
696 (pushnew (specializer-class specl) gf-classes-to-do)))))
697 (map-all-generic-functions
699 (when (or (member gf gfs-to-do)
700 (dolist (class gf-classes-to-do nil)
702 (class-precedence-list (class-of gf)))))
703 (update-c-a-m-gf-info gf)))))
704 (map-all-generic-functions #'update-c-a-m-gf-info))
705 (setq *old-c-a-m-gf-methods* methods)))
707 (defun update-gf-info (gf)
708 (update-c-a-m-gf-info gf)
709 (update-gf-simple-accessor-type gf))
711 (defun update-c-a-m-gf-info (gf)
712 (unless (early-gf-p gf)
713 (multiple-value-bind (c-a-m-emf std-p)
714 (compute-applicable-methods-emf gf)
715 (let ((arg-info (gf-arg-info gf)))
716 (setf (gf-info-static-c-a-m-emf arg-info) c-a-m-emf)
717 (setf (gf-info-c-a-m-emf-std-p arg-info) std-p)))))
719 (defun update-gf-simple-accessor-type (gf)
720 (let ((arg-info (gf-arg-info gf)))
721 (setf (gf-info-simple-accessor-type arg-info)
722 (let* ((methods (generic-function-methods gf))
723 (class (and methods (class-of (car methods))))
726 *the-class-standard-reader-method*)
729 *the-class-standard-writer-method*)
732 *the-class-standard-boundp-method*)
734 (when (and (gf-info-c-a-m-emf-std-p arg-info)
736 (dolist (method (cdr methods) t)
737 (unless (eq class (class-of method)) (return nil)))
738 (eq (generic-function-method-combination gf)
739 *standard-method-combination*))
742 (defun get-accessor-method-function (gf type class slotd)
743 (let* ((std-method (standard-svuc-method type))
744 (str-method (structure-svuc-method type))
745 (types1 `((eql ,class) (class-eq ,class) (eql ,slotd)))
746 (types (if (eq type 'writer) `(t ,@types1) types1))
747 (methods (compute-applicable-methods-using-types gf types))
748 (std-p (null (cdr methods))))
751 (get-optimized-std-accessor-method-function class slotd type)
752 (get-accessor-from-svuc-method-function
754 (get-secondary-dispatch-function
756 `((,(car (or (member std-method methods)
757 (member str-method methods)
758 (error "error in get-accessor-method-function")))
759 ,(get-optimized-std-slot-value-using-class-method-function
761 (unless (and (eq type 'writer)
762 (dolist (method methods t)
763 (unless (eq (car (method-specializers method))
766 (let ((wrappers (list (wrapper-of class)
767 (class-wrapper class)
768 (wrapper-of slotd))))
769 (if (eq type 'writer)
770 (cons (class-wrapper *the-class-t*) wrappers)
775 ;;; used by OPTIMIZE-SLOT-VALUE-BY-CLASS-P (vector.lisp)
776 (defun update-slot-value-gf-info (gf type)
778 (update-std-or-str-methods gf type))
779 (when (and (standard-svuc-method type) (structure-svuc-method type))
780 (flet ((update-class (class)
781 (when (class-finalized-p class)
782 (dolist (slotd (class-slots class))
783 (compute-slot-accessor-info slotd type gf)))))
785 (update-class *new-class*)
786 (map-all-classes #'update-class 'slot-object)))))
788 (defvar *standard-slot-value-using-class-method* nil)
789 (defvar *standard-setf-slot-value-using-class-method* nil)
790 (defvar *standard-slot-boundp-using-class-method* nil)
791 (defvar *structure-slot-value-using-class-method* nil)
792 (defvar *structure-setf-slot-value-using-class-method* nil)
793 (defvar *structure-slot-boundp-using-class-method* nil)
795 (defun standard-svuc-method (type)
797 (reader *standard-slot-value-using-class-method*)
798 (writer *standard-setf-slot-value-using-class-method*)
799 (boundp *standard-slot-boundp-using-class-method*)))
801 (defun set-standard-svuc-method (type method)
803 (reader (setq *standard-slot-value-using-class-method* method))
804 (writer (setq *standard-setf-slot-value-using-class-method* method))
805 (boundp (setq *standard-slot-boundp-using-class-method* method))))
807 (defun structure-svuc-method (type)
809 (reader *structure-slot-value-using-class-method*)
810 (writer *structure-setf-slot-value-using-class-method*)
811 (boundp *structure-slot-boundp-using-class-method*)))
813 (defun set-structure-svuc-method (type method)
815 (reader (setq *structure-slot-value-using-class-method* method))
816 (writer (setq *structure-setf-slot-value-using-class-method* method))
817 (boundp (setq *structure-slot-boundp-using-class-method* method))))
819 (defun update-std-or-str-methods (gf type)
820 (dolist (method (generic-function-methods gf))
821 (let ((specls (method-specializers method)))
822 (when (and (or (not (eq type 'writer))
823 (eq (pop specls) *the-class-t*))
824 (every #'classp specls))
825 (cond ((and (eq (class-name (car specls))
827 (eq (class-name (cadr specls))
829 (eq (class-name (caddr specls))
830 'standard-effective-slot-definition))
831 (set-standard-svuc-method type method))
832 ((and (eq (class-name (car specls))
834 (eq (class-name (cadr specls))
836 (eq (class-name (caddr specls))
837 'structure-effective-slot-definition))
838 (set-structure-svuc-method type method)))))))
840 (defun mec-all-classes-internal (spec precompute-p)
841 (cons (specializer-class spec)
844 (not (or (eq spec *the-class-t*)
845 (eq spec *the-class-slot-object*)
846 (eq spec *the-class-std-object*)
847 (eq spec *the-class-standard-object*)
848 (eq spec *the-class-structure-object*)))
849 (let ((sc (class-direct-subclasses spec)))
851 (mapcan (lambda (class)
852 (mec-all-classes-internal class precompute-p))
855 (defun mec-all-classes (spec precompute-p)
856 (let ((classes (mec-all-classes-internal spec precompute-p)))
857 (if (null (cdr classes))
859 (let* ((a-classes (cons nil classes))
861 (loop (when (null (cdr tail))
862 (return (cdr a-classes)))
863 (let ((class (cadr tail))
865 (if (dolist (c ttail nil)
866 (when (eq class c) (return t)))
867 (setf (cdr tail) (cddr tail))
868 (setf tail (cdr tail)))))))))
870 (defun mec-all-class-lists (spec-list precompute-p)
873 (let* ((car-all-classes (mec-all-classes (car spec-list)
875 (all-class-lists (mec-all-class-lists (cdr spec-list)
877 (mapcan (lambda (list)
878 (mapcar (lambda (c) (cons c list)) car-all-classes))
881 (defun make-emf-cache (generic-function valuep cache classes-list new-class)
882 (let* ((arg-info (gf-arg-info generic-function))
883 (nkeys (arg-info-nkeys arg-info))
884 (metatypes (arg-info-metatypes arg-info))
885 (wrappers (unless (eq nkeys 1) (make-list nkeys)))
886 (precompute-p (gf-precompute-dfun-and-emf-p arg-info))
887 (default '(default)))
888 (flet ((add-class-list (classes)
889 (when (or (null new-class) (memq new-class classes))
890 (let ((wrappers (get-wrappers-from-classes
891 nkeys wrappers classes metatypes)))
893 (eq default (probe-cache cache wrappers default)))
894 (let ((value (cond ((eq valuep t)
895 (sdfun-for-caching generic-function
897 ((eq valuep :constant-value)
898 (value-for-caching generic-function
900 (setq cache (fill-cache cache wrappers value t))))))))
902 (mapc #'add-class-list classes-list)
903 (dolist (method (generic-function-methods generic-function))
904 (mapc #'add-class-list
905 (mec-all-class-lists (method-specializers method)
909 (defmacro class-test (arg class)
910 (cond ((eq class *the-class-t*)
912 ((eq class *the-class-slot-object*)
913 `(not (cl:typep (cl:class-of ,arg) 'cl:built-in-class)))
914 ((eq class *the-class-std-object*)
915 `(or (std-instance-p ,arg) (fsc-instance-p ,arg)))
916 ((eq class *the-class-standard-object*)
917 `(std-instance-p ,arg))
918 ((eq class *the-class-funcallable-standard-object*)
919 `(fsc-instance-p ,arg))
921 `(typep ,arg ',(class-name class)))))
923 (defmacro class-eq-test (arg class)
924 `(eq (class-of ,arg) ',class))
926 (defmacro eql-test (arg object)
927 `(eql ,arg ',object))
929 (defun dnet-methods-p (form)
931 (or (eq (car form) 'methods)
932 (eq (car form) 'unordered-methods))))
934 ;;; This is CASE, but without gensyms.
935 (defmacro scase (arg &rest clauses)
936 `(let ((.case-arg. ,arg))
937 (cond ,@(mapcar (lambda (clause)
938 (list* (cond ((null (car clause))
940 ((consp (car clause))
941 (if (null (cdar clause))
946 ((member (car clause) '(t otherwise))
949 `(eql .case-arg. ',(car clause))))
954 (defmacro mcase (arg &rest clauses) `(scase ,arg ,@clauses))
956 (defun generate-discrimination-net (generic-function methods types sorted-p)
957 (let* ((arg-info (gf-arg-info generic-function))
958 (precedence (arg-info-precedence arg-info)))
959 (generate-discrimination-net-internal
960 generic-function methods types
961 (lambda (methods known-types)
964 (let ((sorted-methods nil))
966 (copy-list methods) precedence
968 (when sorted-methods (return-from one-order-p nil))
969 (setq sorted-methods methods)))
970 (setq methods sorted-methods))
972 `(methods ,methods ,known-types)
973 `(unordered-methods ,methods ,known-types)))
974 (lambda (position type true-value false-value)
975 (let ((arg (dfun-arg-symbol position)))
976 (if (eq (car type) 'eql)
977 (let* ((false-case-p (and (consp false-value)
978 (or (eq (car false-value) 'scase)
979 (eq (car false-value) 'mcase))
980 (eq arg (cadr false-value))))
981 (false-clauses (if false-case-p
983 `((t ,false-value))))
984 (case-sym (if (and (dnet-methods-p true-value)
986 (eq (car false-value) 'mcase)
987 (dnet-methods-p false-value)))
990 (type-sym `(,(cadr type))))
992 (,type-sym ,true-value)
994 `(if ,(let ((arg (dfun-arg-symbol position)))
996 (class `(class-test ,arg ,(cadr type)))
997 (class-eq `(class-eq-test ,arg ,(cadr type)))))
1002 (defun class-from-type (type)
1003 (if (or (atom type) (eq (car type) t))
1006 (and (dolist (type (cdr type) *the-class-t*)
1007 (when (and (consp type) (not (eq (car type) 'not)))
1008 (return (class-from-type type)))))
1010 (eql (class-of (cadr type)))
1011 (class-eq (cadr type))
1012 (class (cadr type)))))
1014 (defun precompute-effective-methods (gf caching-p &optional classes-list-p)
1015 (let* ((arg-info (gf-arg-info gf))
1016 (methods (generic-function-methods gf))
1017 (precedence (arg-info-precedence arg-info))
1018 (*in-precompute-effective-methods-p* t)
1020 (generate-discrimination-net-internal
1022 (lambda (methods known-types)
1024 (when classes-list-p
1025 (push (mapcar #'class-from-type known-types) classes-list))
1026 (let ((no-eql-specls-p (not (methods-contain-eql-specializer-p
1031 (get-secondary-dispatch-function1
1032 gf methods known-types
1033 nil caching-p no-eql-specls-p))))))
1034 (lambda (position type true-value false-value)
1035 (declare (ignore position type true-value false-value))
1038 (if (and (consp type) (eq (car type) 'eql))
1039 `(class-eq ,(class-of (cadr type)))
1043 ;;; We know that known-type implies neither new-type nor `(not ,new-type).
1044 (defun augment-type (new-type known-type)
1045 (if (or (eq known-type t)
1046 (eq (car new-type) 'eql))
1048 (let ((so-far (if (and (consp known-type) (eq (car known-type) 'and))
1050 (list known-type))))
1051 (unless (eq (car new-type) 'not)
1053 (mapcan (lambda (type)
1054 (unless (*subtypep new-type type)
1059 `(and ,new-type ,@so-far)))))
1061 (defun generate-discrimination-net-internal
1062 (gf methods types methods-function test-fun type-function)
1063 (let* ((arg-info (gf-arg-info gf))
1064 (precedence (arg-info-precedence arg-info))
1065 (nreq (arg-info-number-required arg-info))
1066 (metatypes (arg-info-metatypes arg-info)))
1067 (labels ((do-column (p-tail contenders known-types)
1069 (let* ((position (car p-tail))
1070 (known-type (or (nth position types) t)))
1071 (if (eq (nth position metatypes) t)
1072 (do-column (cdr p-tail) contenders
1073 (cons (cons position known-type)
1075 (do-methods p-tail contenders
1076 known-type () known-types)))
1077 (funcall methods-function contenders
1078 (let ((k-t (make-list nreq)))
1079 (dolist (index+type known-types)
1080 (setf (nth (car index+type) k-t)
1083 (do-methods (p-tail contenders known-type winners known-types)
1085 ;; is a (sorted) list of methods that must be discriminated.
1087 ;; is the type of this argument, constructed from tests
1090 ;; is a (sorted) list of methods that are potentially
1091 ;; applicable after the discrimination has been made.
1092 (if (null contenders)
1093 (do-column (cdr p-tail)
1095 (cons (cons (car p-tail) known-type)
1097 (let* ((position (car p-tail))
1098 (method (car contenders))
1099 (specl (nth position (method-specializers method)))
1100 (type (funcall type-function
1101 (type-from-specializer specl))))
1102 (multiple-value-bind (app-p maybe-app-p)
1103 (specializer-applicable-using-type-p type known-type)
1104 (flet ((determined-to-be (truth-value)
1105 (if truth-value app-p (not maybe-app-p)))
1106 (do-if (truth &optional implied)
1107 (let ((ntype (if truth type `(not ,type))))
1112 (augment-type ntype known-type))
1114 (append winners `(,method))
1117 (cond ((determined-to-be nil) (do-if nil t))
1118 ((determined-to-be t) (do-if t t))
1119 (t (funcall test-fun position type
1120 (do-if t) (do-if nil))))))))))
1121 (do-column precedence methods ()))))
1123 (defun compute-secondary-dispatch-function (generic-function net &optional
1124 method-alist wrappers)
1125 (function-funcall (compute-secondary-dispatch-function1 generic-function net)
1126 method-alist wrappers))
1128 (defvar *eq-case-table-limit* 15)
1129 (defvar *case-table-limit* 10)
1131 (defun compute-mcase-parameters (case-list)
1132 (unless (eq t (caar (last case-list)))
1133 (error "The key for the last case arg to mcase was not T"))
1134 (let* ((eq-p (dolist (case case-list t)
1135 (unless (or (eq (car case) t)
1136 (symbolp (caar case)))
1138 (len (1- (length case-list)))
1139 (type (cond ((= len 1)
1143 *eq-case-table-limit*
1144 *case-table-limit*))
1150 (defmacro mlookup (key info default &optional eq-p type)
1151 (unless (or (eq eq-p t) (null eq-p))
1152 (error "Invalid eq-p argument"))
1155 `(if (,(if eq-p 'eq 'eql) ,key (car ,info))
1159 `(dolist (e ,info ,default)
1160 (when (,(if eq-p 'eq 'eql) (car e) ,key)
1163 `(gethash ,key ,info ,default))))
1165 (defun net-test-converter (form)
1167 (default-test-converter form)
1169 ((invoke-effective-method-function invoke-fast-method-call)
1176 `(mlookup ,(cadr form)
1179 ,@(compute-mcase-parameters (cddr form))))
1180 (t (default-test-converter form)))))
1182 (defun net-code-converter (form)
1184 (default-code-converter form)
1186 ((methods unordered-methods)
1187 (let ((gensym (gensym)))
1191 (let ((mp (compute-mcase-parameters (cddr form)))
1192 (gensym (gensym)) (default (gensym)))
1193 (values `(mlookup ,(cadr form) ,gensym ,default ,@mp)
1194 (list gensym default))))
1196 (default-code-converter form)))))
1198 (defun net-constant-converter (form generic-function)
1199 (or (let ((c (methods-converter form generic-function)))
1202 (default-constant-converter form)
1205 (let* ((mp (compute-mcase-parameters (cddr form)))
1206 (list (mapcar (lambda (clause)
1207 (let ((key (car clause))
1208 (meth (cadr clause)))
1209 (cons (if (consp key) (car key) key)
1211 meth generic-function))))
1213 (default (car (last list))))
1214 (list (list* :mcase mp (nbutlast list))
1217 (default-constant-converter form))))))
1219 (defun methods-converter (form generic-function)
1220 (cond ((and (consp form) (eq (car form) 'methods))
1222 (get-effective-method-function1 generic-function (cadr form))))
1223 ((and (consp form) (eq (car form) 'unordered-methods))
1224 (default-secondary-dispatch-function generic-function))))
1226 (defun convert-methods (constant method-alist wrappers)
1227 (if (and (consp constant)
1228 (eq (car constant) '.methods.))
1229 (funcall (cdr constant) method-alist wrappers)
1232 (defun convert-table (constant method-alist wrappers)
1233 (cond ((and (consp constant)
1234 (eq (car constant) :mcase))
1235 (let ((alist (mapcar (lambda (k+m)
1237 (convert-methods (cdr k+m)
1241 (mp (cadr constant)))
1248 (let ((table (make-hash-table :test (if (car mp) 'eq 'eql))))
1250 (setf (gethash (car k+m) table) (cdr k+m)))
1253 (defun compute-secondary-dispatch-function1 (generic-function net
1254 &optional function-p)
1256 ((and (eq (car net) 'methods) (not function-p))
1257 (get-effective-method-function1 generic-function (cadr net)))
1259 (let* ((name (generic-function-name generic-function))
1260 (arg-info (gf-arg-info generic-function))
1261 (metatypes (arg-info-metatypes arg-info))
1262 (applyp (arg-info-applyp arg-info))
1263 (fmc-arg-info (cons (length metatypes) applyp))
1264 (arglist (if function-p
1265 (make-dfun-lambda-list metatypes applyp)
1266 (make-fast-method-call-lambda-list metatypes applyp))))
1267 (multiple-value-bind (cfunction constants)
1268 (get-fun1 `(,(if function-p
1269 'sb-kernel:instance-lambda
1272 ,@(unless function-p
1273 `((declare (ignore .pv-cell.
1274 .next-method-call.))))
1275 (locally (declare #.*optimize-speed*)
1277 ,(make-emf-call metatypes applyp 'emf))))
1278 #'net-test-converter
1279 #'net-code-converter
1281 (net-constant-converter form generic-function)))
1282 (lambda (method-alist wrappers)
1283 (let* ((alist (list nil))
1285 (dolist (constant constants)
1286 (let* ((a (or (dolist (a alist nil)
1287 (when (eq (car a) constant)
1291 constant method-alist wrappers)
1293 constant method-alist wrappers)))))
1295 (setf (cdr alist-tail) new)
1296 (setf alist-tail new)))
1297 (let ((function (apply cfunction (mapcar #'cdr (cdr alist)))))
1300 (make-fast-method-call
1301 :function (set-fun-name function `(sdfun-method ,name))
1302 :arg-info fmc-arg-info))))))))))
1304 (defvar *show-make-unordered-methods-emf-calls* nil)
1306 (defun make-unordered-methods-emf (generic-function methods)
1307 (when *show-make-unordered-methods-emf-calls*
1308 (format t "~&make-unordered-methods-emf ~S~%"
1309 (generic-function-name generic-function)))
1310 (lambda (&rest args)
1311 (let* ((types (types-from-args generic-function args 'eql))
1312 (smethods (sort-applicable-methods generic-function
1315 (emf (get-effective-method-function generic-function smethods)))
1316 (invoke-emf emf args))))
1318 ;;; The value returned by compute-discriminating-function is a function
1319 ;;; object. It is called a discriminating function because it is called
1320 ;;; when the generic function is called and its role is to discriminate
1321 ;;; on the arguments to the generic function and then call appropriate
1322 ;;; method functions.
1324 ;;; A discriminating function can only be called when it is installed as
1325 ;;; the funcallable instance function of the generic function for which
1326 ;;; it was computed.
1328 ;;; More precisely, if compute-discriminating-function is called with an
1329 ;;; argument <gf1>, and returns a result <df1>, that result must not be
1330 ;;; passed to apply or funcall directly. Rather, <df1> must be stored as
1331 ;;; the funcallable instance function of the same generic function <gf1>
1332 ;;; (using set-funcallable-instance-fun). Then the generic function
1333 ;;; can be passed to funcall or apply.
1335 ;;; An important exception is that methods on this generic function are
1336 ;;; permitted to return a function which itself ends up calling the value
1337 ;;; returned by a more specific method. This kind of `encapsulation' of
1338 ;;; discriminating function is critical to many uses of the MOP.
1340 ;;; As an example, the following canonical case is legal:
1342 ;;; (defmethod compute-discriminating-function ((gf my-generic-function))
1343 ;;; (let ((std (call-next-method)))
1345 ;;; (print (list 'call-to-gf gf arg))
1346 ;;; (funcall std arg))))
1348 ;;; Because many discriminating functions would like to use a dynamic
1349 ;;; strategy in which the precise discriminating function changes with
1350 ;;; time it is important to specify how a discriminating function is
1351 ;;; permitted itself to change the funcallable instance function of the
1352 ;;; generic function.
1354 ;;; Discriminating functions may set the funcallable instance function
1355 ;;; of the generic function, but the new value must be generated by making
1356 ;;; a call to COMPUTE-DISCRIMINATING-FUNCTION. This is to ensure that any
1357 ;;; more specific methods which may have encapsulated the discriminating
1358 ;;; function will get a chance to encapsulate the new, inner discriminating
1361 ;;; This implies that if a discriminating function wants to modify itself
1362 ;;; it should first store some information in the generic function proper,
1363 ;;; and then call compute-discriminating-function. The appropriate method
1364 ;;; on compute-discriminating-function will see the information stored in
1365 ;;; the generic function and generate a discriminating function accordingly.
1367 ;;; The following is an example of a discriminating function which modifies
1368 ;;; itself in accordance with this protocol:
1370 ;;; (defmethod compute-discriminating-function ((gf my-generic-function))
1372 ;;; (cond (<some condition>
1373 ;;; <store some info in the generic function>
1374 ;;; (set-funcallable-instance-fun
1376 ;;; (compute-discriminating-function gf))
1377 ;;; (funcall gf arg))
1379 ;;; <call-a-method-of-gf>))))
1381 ;;; Whereas this code would not be legal:
1383 ;;; (defmethod compute-discriminating-function ((gf my-generic-function))
1385 ;;; (cond (<some condition>
1386 ;;; (set-funcallable-instance-fun
1388 ;;; (lambda (a) ..))
1389 ;;; (funcall gf arg))
1391 ;;; <call-a-method-of-gf>))))
1393 ;;; NOTE: All the examples above assume that all instances of the class
1394 ;;; my-generic-function accept only one argument.
1396 (defun slot-value-using-class-dfun (class object slotd)
1397 (declare (ignore class))
1398 (function-funcall (slot-definition-reader-function slotd) object))
1400 (defun setf-slot-value-using-class-dfun (new-value class object slotd)
1401 (declare (ignore class))
1402 (function-funcall (slot-definition-writer-function slotd) new-value object))
1404 (defun slot-boundp-using-class-dfun (class object slotd)
1405 (declare (ignore class))
1406 (function-funcall (slot-definition-boundp-function slotd) object))
1408 (defmethod compute-discriminating-function ((gf standard-generic-function))
1409 (with-slots (dfun-state arg-info) gf
1410 (typecase dfun-state
1411 (null (let ((name (generic-function-name gf)))
1412 (when (eq name 'compute-applicable-methods)
1413 (update-all-c-a-m-gf-info gf))
1414 (cond ((eq name 'slot-value-using-class)
1415 (update-slot-value-gf-info gf 'reader)
1416 #'slot-value-using-class-dfun)
1417 ((equal name '(setf slot-value-using-class))
1418 (update-slot-value-gf-info gf 'writer)
1419 #'setf-slot-value-using-class-dfun)
1420 ((eq name 'slot-boundp-using-class)
1421 (update-slot-value-gf-info gf 'boundp)
1422 #'slot-boundp-using-class-dfun)
1423 ((gf-precompute-dfun-and-emf-p arg-info)
1424 (make-final-dfun gf))
1426 (make-initial-dfun gf)))))
1427 (function dfun-state)
1428 (cons (car dfun-state)))))
1430 (defmethod update-gf-dfun ((class std-class) gf)
1431 (let ((*new-class* class)
1432 #|| (name (generic-function-name gf)) ||#
1433 (arg-info (gf-arg-info gf)))
1435 ((eq name 'slot-value-using-class)
1436 (update-slot-value-gf-info gf 'reader))
1437 ((equal name '(setf slot-value-using-class))
1438 (update-slot-value-gf-info gf 'writer))
1439 ((eq name 'slot-boundp-using-class)
1440 (update-slot-value-gf-info gf 'boundp))
1442 ((gf-precompute-dfun-and-emf-p arg-info)
1443 (multiple-value-bind (dfun cache info)
1444 (make-final-dfun-internal gf)
1445 (set-dfun gf dfun cache info) ; lest the cache be freed twice
1446 (update-dfun gf dfun cache info))))))
1448 (defmethod function-keywords ((method standard-method))
1449 (multiple-value-bind (nreq nopt keysp restp allow-other-keys-p keywords)
1450 (analyze-lambda-list (if (consp method)
1451 (early-method-lambda-list method)
1452 (method-lambda-list method)))
1453 (declare (ignore nreq nopt keysp restp))
1454 (values keywords allow-other-keys-p)))
1456 (defun method-ll->generic-function-ll (ll)
1457 (multiple-value-bind
1458 (nreq nopt keysp restp allow-other-keys-p keywords keyword-parameters)
1459 (analyze-lambda-list ll)
1460 (declare (ignore nreq nopt keysp restp allow-other-keys-p keywords))
1461 (remove-if (lambda (s)
1462 (or (memq s keyword-parameters)
1463 (eq s '&allow-other-keys)))
1466 ;;; This is based on the rules of method lambda list congruency defined in
1467 ;;; the spec. The lambda list it constructs is the pretty union of the
1468 ;;; lambda lists of all the methods. It doesn't take method applicability
1469 ;;; into account at all yet.
1470 (defmethod generic-function-pretty-arglist
1471 ((generic-function standard-generic-function))
1472 (let ((methods (generic-function-methods generic-function)))
1475 ;; arglist is constructed from the GF's methods - maybe with
1476 ;; keys and rest stuff added
1477 (multiple-value-bind (required optional rest key allow-other-keys)
1478 (method-pretty-arglist (car methods))
1479 (dolist (m (cdr methods))
1480 (multiple-value-bind (method-key-keywords
1481 method-allow-other-keys
1483 (function-keywords m)
1484 ;; we've modified function-keywords to return what we want as
1485 ;; the third value, no other change here.
1486 (declare (ignore method-key-keywords))
1487 (setq key (union key method-key))
1488 (setq allow-other-keys (or allow-other-keys
1489 method-allow-other-keys))))
1490 (when allow-other-keys
1491 (setq arglist '(&allow-other-keys)))
1493 (setq arglist (nconc (list '&key) key arglist)))
1495 (setq arglist (nconc (list '&rest rest) arglist)))
1497 (setq arglist (nconc (list '&optional) optional arglist)))
1498 (nconc required arglist)))
1499 ;; otherwise we take the lambda-list from the GF directly, with no
1500 ;; other 'keys' added ...
1501 (let ((lambda-list (generic-function-lambda-list generic-function)))
1504 (defmethod method-pretty-arglist ((method standard-method))
1509 (allow-other-keys nil)
1511 (arglist (method-lambda-list method)))
1512 (dolist (arg arglist)
1513 (cond ((eq arg '&optional) (setq state 'optional))
1514 ((eq arg '&rest) (setq state 'rest))
1515 ((eq arg '&key) (setq state 'key))
1516 ((eq arg '&allow-other-keys) (setq allow-other-keys t))
1517 ((memq arg lambda-list-keywords))
1520 (required (push arg required))
1521 (optional (push arg optional))
1522 (key (push arg key))
1523 (rest (setq rest arg))))))
1524 (values (nreverse required)