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
26 (defmethod shared-initialize :after ((slotd standard-slot-definition)
28 (declare (ignore slot-names))
29 (with-slots (allocation class)
31 (setq allocation (if (eq allocation :class) class allocation))))
33 (defmethod shared-initialize :after ((slotd structure-slot-definition)
35 &key (allocation :instance))
36 (declare (ignore slot-names))
37 (unless (eq allocation :instance)
38 (error "Structure slots must have :INSTANCE allocation.")))
40 (defmethod inform-type-system-about-class ((class structure-class) (name t))
45 ;;; Methods themselves are simple inanimate objects. Most properties of
46 ;;; methods are immutable, methods cannot be reinitialized. The following
47 ;;; properties of methods can be changed:
48 ;;; METHOD-GENERIC-FUNCTION
49 ;;; METHOD-FUNCTION ??
51 (defmethod method-function ((method standard-method))
52 (or (slot-value method 'function)
53 (let ((fmf (slot-value method 'fast-function)))
54 (unless fmf ; The :BEFORE SHARED-INITIALIZE method prevents this.
55 (error "~S doesn't seem to have a METHOD-FUNCTION." method))
56 (setf (slot-value method 'function)
57 (method-function-from-fast-function fmf)))))
59 (defmethod accessor-method-class ((method standard-accessor-method))
60 (car (slot-value method 'specializers)))
62 (defmethod accessor-method-class ((method standard-writer-method))
63 (cadr (slot-value method 'specializers)))
67 ;;; Error checking is done in before methods. Because of the simplicity of
68 ;;; standard method objects the standard primary method can fill the slots.
70 ;;; Methods are not reinitializable.
72 (defmethod reinitialize-instance ((method standard-method) &rest initargs)
73 (declare (ignore initargs))
74 (error "An attempt was made to reinitialize the method ~S.~%~
75 Method objects cannot be reinitialized."
78 (defmethod legal-documentation-p ((object standard-method) x)
79 (if (or (null x) (stringp x))
83 (defmethod legal-lambda-list-p ((object standard-method) x)
87 (defmethod legal-method-function-p ((object standard-method) x)
92 (defmethod legal-qualifiers-p ((object standard-method) x)
93 (flet ((improper-list ()
94 (return-from legal-qualifiers-p "Is not a proper list.")))
95 (dolist-carefully (q x improper-list)
96 (let ((ok (legal-qualifier-p object q)))
98 (return-from legal-qualifiers-p
99 (format nil "Contains ~S which ~A" q ok)))))
102 (defmethod legal-qualifier-p ((object standard-method) x)
105 "is not a non-null atom"))
107 (defmethod legal-slot-name-p ((object standard-method) x)
108 (cond ((not (symbolp x)) "is not a symbol and so cannot be bound")
109 ((keywordp x) "is a keyword and so cannot be bound")
110 ((memq x '(t nil)) "cannot be bound")
111 ((constantp x) "is a constant and so cannot be bound")
114 (defmethod legal-specializers-p ((object standard-method) x)
115 (flet ((improper-list ()
116 (return-from legal-specializers-p "Is not a proper list.")))
117 (dolist-carefully (s x improper-list)
118 (let ((ok (legal-specializer-p object s)))
120 (return-from legal-specializers-p
121 (format nil "Contains ~S which ~A" s ok)))))
124 (defvar *allow-experimental-specializers-p* nil)
126 (defmethod legal-specializer-p ((object standard-method) x)
127 (if (if *allow-experimental-specializers-p*
130 (eql-specializer-p x)))
132 "is neither a class object nor an EQL specializer"))
134 (defmethod shared-initialize :before ((method standard-method)
142 (declare (ignore slot-names))
143 (flet ((lose (initarg value string)
144 (error "when initializing the method ~S:~%~
145 The ~S initialization argument was: ~S.~%~
147 method initarg value string)))
148 (let ((check-qualifiers (legal-qualifiers-p method qualifiers))
149 (check-lambda-list (legal-lambda-list-p method lambda-list))
150 (check-specializers (legal-specializers-p method specializers))
151 (check-function (legal-method-function-p method
154 (check-documentation (legal-documentation-p method documentation)))
155 (unless (eq check-qualifiers t)
156 (lose :qualifiers qualifiers check-qualifiers))
157 (unless (eq check-lambda-list t)
158 (lose :lambda-list lambda-list check-lambda-list))
159 (unless (eq check-specializers t)
160 (lose :specializers specializers check-specializers))
161 (unless (eq check-function t)
162 (lose :function function check-function))
163 (unless (eq check-documentation t)
164 (lose :documentation documentation check-documentation)))))
166 (defmethod shared-initialize :before ((method standard-accessor-method)
168 &key slot-name slot-definition)
169 (declare (ignore slot-names))
170 (unless slot-definition
171 (let ((legalp (legal-slot-name-p method slot-name)))
172 ;; FIXME: nasty convention; should be renamed to ILLEGAL-SLOT-NAME-P and
173 ;; ILLEGALP, and the convention redone to be less twisty
174 (unless (eq legalp t)
175 (error "The value of the :SLOT-NAME initarg ~A." legalp)))))
177 (defmethod shared-initialize :after ((method standard-method) slot-names
179 &key qualifiers method-spec plist)
180 (declare (ignore slot-names method-spec plist))
181 (initialize-method-function initargs nil method)
182 (setf (plist-value method 'qualifiers) qualifiers)
184 (setf (slot-value method 'closure-generator)
185 (method-function-closure-generator (slot-value method 'function))))
187 (defmethod shared-initialize :after ((method standard-accessor-method)
190 (declare (ignore slot-names))
191 (with-slots (slot-name slot-definition)
193 (unless slot-definition
194 (let ((class (accessor-method-class method)))
195 (when (slot-class-p class)
196 (setq slot-definition (find slot-name (class-direct-slots class)
197 :key #'slot-definition-name)))))
198 (when (and slot-definition (null slot-name))
199 (setq slot-name (slot-definition-name slot-definition)))))
201 (defmethod method-qualifiers ((method standard-method))
202 (plist-value method 'qualifiers))
204 (defvar *the-class-generic-function*
205 (find-class 'generic-function))
206 (defvar *the-class-standard-generic-function*
207 (find-class 'standard-generic-function))
209 (defmethod shared-initialize :before
210 ((generic-function standard-generic-function)
212 &key (name nil namep)
213 (lambda-list () lambda-list-p)
214 argument-precedence-order
217 (method-class nil method-class-supplied-p)
218 (method-combination nil method-combination-supplied-p))
219 (declare (ignore slot-names
220 declarations argument-precedence-order documentation
221 lambda-list lambda-list-p))
224 (set-function-name generic-function name))
226 (flet ((initarg-error (initarg value string)
227 (error "when initializing the generic function ~S:~%~
228 The ~S initialization argument was: ~A.~%~
230 generic-function initarg value string)))
231 (cond (method-class-supplied-p
232 (when (symbolp method-class)
233 (setq method-class (find-class method-class)))
234 (unless (and (classp method-class)
235 (*subtypep (class-eq-specializer method-class)
237 (initarg-error :method-class
239 "a subclass of the class METHOD"))
240 (setf (slot-value generic-function 'method-class) method-class))
241 ((slot-boundp generic-function 'method-class))
243 (initarg-error :method-class
245 "a subclass of the class METHOD")))
246 (cond (method-combination-supplied-p
247 (unless (method-combination-p method-combination)
248 (initarg-error :method-combination
250 "a method combination object")))
251 ((slot-boundp generic-function 'method-combination))
253 (initarg-error :method-combination
255 "a method combination object")))))
258 (defmethod reinitialize-instance ((generic-function standard-generic-function)
262 argument-precedence-order
267 (declare (ignore documentation declarations argument-precedence-order
268 lambda-list name method-class method-combination))
269 (macrolet ((add-initarg (check name slot-name)
271 (push (slot-value generic-function ,slot-name) initargs)
272 (push ,name initargs))))
273 ; (add-initarg name :name 'name)
274 ; (add-initarg lambda-list :lambda-list 'lambda-list)
275 ; (add-initarg argument-precedence-order
276 ; :argument-precedence-order
277 ; 'argument-precedence-order)
278 ; (add-initarg declarations :declarations 'declarations)
279 ; (add-initarg documentation :documentation 'documentation)
280 ; (add-initarg method-class :method-class 'method-class)
281 ; (add-initarg method-combination :method-combination 'method-combination)
282 (apply #'call-next-method generic-function initargs)))
285 ;;; These three are scheduled for demolition.
287 (defmethod remove-named-method (generic-function-name argument-specifiers
289 (let ((generic-function ())
291 (cond ((or (null (fboundp generic-function-name))
292 (not (generic-function-p
293 (setq generic-function
294 (fdefinition generic-function-name)))))
295 (error "~S does not name a generic function."
296 generic-function-name))
297 ((null (setq method (get-method generic-function
302 (error "There is no method for the generic function ~S~%~
303 which matches the ARGUMENT-SPECIFIERS ~S."
305 argument-specifiers))
307 (remove-method generic-function method)))))
309 (defun real-add-named-method (generic-function-name
313 &rest other-initargs)
314 (unless (and (fboundp generic-function-name)
315 (typep (fdefinition generic-function-name) 'generic-function))
316 (sb-kernel::style-warn "implicitly creating new generic function ~S"
317 generic-function-name))
318 ;; XXX What about changing the class of the generic function if
319 ;; there is one? Whose job is that, anyway? Do we need something
320 ;; kind of like CLASS-FOR-REDEFINITION?
321 (let* ((generic-function
322 (ensure-generic-function generic-function-name))
323 (specs (parse-specializers specializers))
324 (proto (method-prototype-for-gf generic-function-name))
325 (new (apply #'make-instance (class-of proto)
326 :qualifiers qualifiers
328 :lambda-list lambda-list
330 (add-method generic-function new)))
332 (defun real-get-method (generic-function qualifiers specializers
333 &optional (errorp t))
335 (dolist (method (generic-function-methods generic-function))
336 (when (and (equal qualifiers (method-qualifiers method))
337 (every #'same-specializer-p specializers
338 (method-specializers method)))
343 (error "no method on ~S with qualifiers ~:S and specializers ~:S"
344 generic-function qualifiers specializers)))))
346 (defmethod find-method ((generic-function standard-generic-function)
347 qualifiers specializers &optional (errorp t))
348 (real-get-method generic-function qualifiers
349 (parse-specializers specializers) errorp))
351 ;;; Compute various information about a generic-function's arglist by looking
352 ;;; at the argument lists of the methods. The hair for trying not to use
353 ;;; &REST arguments lives here.
354 ;;; The values returned are:
355 ;;; number-of-required-arguments
356 ;;; the number of required arguments to this generic-function's
357 ;;; discriminating function
359 ;;; whether or not this generic-function's discriminating
360 ;;; function takes an &rest argument.
361 ;;; specialized-argument-positions
362 ;;; a list of the positions of the arguments this generic-function
363 ;;; specializes (e.g. for a classical generic-function this is the
365 (defmethod compute-discriminating-function-arglist-info
366 ((generic-function standard-generic-function))
367 ;;(declare (values number-of-required-arguments &rest-argument-p
368 ;; specialized-argument-postions))
369 (let ((number-required nil)
371 (specialized-positions ())
372 (methods (generic-function-methods generic-function)))
373 (dolist (method methods)
374 (multiple-value-setq (number-required restp specialized-positions)
375 (compute-discriminating-function-arglist-info-internal
376 generic-function method number-required restp specialized-positions)))
377 (values number-required restp (sort specialized-positions #'<))))
379 (defun compute-discriminating-function-arglist-info-internal
380 (generic-function method number-of-requireds restp
381 specialized-argument-positions)
382 (declare (ignore generic-function)
383 (type (or null fixnum) number-of-requireds))
385 (declare (fixnum requireds))
386 ;; Go through this methods arguments seeing how many are required,
387 ;; and whether there is an &rest argument.
388 (dolist (arg (method-lambda-list method))
389 (cond ((eq arg '&aux) (return))
390 ((memq arg '(&optional &rest &key))
391 (return (setq restp t)))
392 ((memq arg lambda-list-keywords))
393 (t (incf requireds))))
394 ;; Now go through this method's type specifiers to see which
395 ;; argument positions are type specified. Treat T specially
396 ;; in the usual sort of way. For efficiency don't bother to
397 ;; keep specialized-argument-positions sorted, rather depend
398 ;; on our caller to do that.
399 (iterate ((type-spec (list-elements (method-specializers method)))
400 (pos (interval :from 0)))
401 (unless (eq type-spec *the-class-t*)
402 (pushnew pos specialized-argument-positions)))
403 ;; Finally merge the values for this method into the values
404 ;; for the exisiting methods and return them. Note that if
405 ;; num-of-requireds is NIL it means this is the first method
406 ;; and we depend on that.
407 (values (min (or number-of-requireds requireds) requireds)
409 (and number-of-requireds (/= number-of-requireds requireds)))
410 specialized-argument-positions)))
412 (defun make-discriminating-function-arglist (number-required-arguments restp)
413 (nconc (gathering ((args (collecting)))
414 (iterate ((i (interval :from 0 :below number-required-arguments)))
415 (gather (intern (format nil "Discriminating Function Arg ~D" i))
418 `(&rest ,(intern "Discriminating Function &rest Arg")))))
420 (defmethod generic-function-lambda-list ((gf generic-function))
423 (defmethod gf-fast-method-function-p ((gf standard-generic-function))
424 (gf-info-fast-mf-p (slot-value gf 'arg-info)))
426 (defmethod initialize-instance :after ((gf standard-generic-function)
427 &key (lambda-list nil lambda-list-p)
428 argument-precedence-order)
429 (with-slots (arg-info)
433 :lambda-list lambda-list
434 :argument-precedence-order argument-precedence-order)
436 (when (arg-info-valid-p arg-info)
439 (defmethod reinitialize-instance :after ((gf standard-generic-function)
441 &key (lambda-list nil lambda-list-p)
442 (argument-precedence-order
443 nil argument-precedence-order-p))
444 (with-slots (arg-info)
447 (if argument-precedence-order-p
449 :lambda-list lambda-list
450 :argument-precedence-order argument-precedence-order)
452 :lambda-list lambda-list))
454 (when (and (arg-info-valid-p arg-info)
456 (or lambda-list-p (cddr args)))
459 (declaim (special *lazy-dfun-compute-p*))
461 (defun set-methods (gf methods)
462 (setf (generic-function-methods gf) nil)
463 (loop (when (null methods) (return gf))
464 (real-add-method gf (pop methods) methods)))
466 (defun real-add-method (generic-function method &optional skip-dfun-update-p)
467 (if (method-generic-function method)
468 (error "The method ~S is already part of the generic~@
469 function ~S. It can't be added to another generic~@
470 function until it is removed from the first one."
471 method (method-generic-function method))
473 (let* ((name (generic-function-name generic-function))
474 (qualifiers (method-qualifiers method))
475 (specializers (method-specializers method))
476 (existing (get-method generic-function
481 ;; If there is already a method like this one then we must
482 ;; get rid of it before proceeding. Note that we call the
483 ;; generic function remove-method to remove it rather than
484 ;; doing it in some internal way.
485 (when existing (remove-method generic-function existing))
487 (setf (method-generic-function method) generic-function)
488 (pushnew method (generic-function-methods generic-function))
489 (dolist (specializer specializers)
490 (add-direct-method specializer method))
491 (set-arg-info generic-function :new-method method)
492 (unless skip-dfun-update-p
494 '(make-instance default-initargs
495 allocate-instance shared-initialize
496 initialize-instance))
497 (update-make-instance-function-table (type-class
498 (car specializers))))
499 (update-dfun generic-function))
502 (defun real-remove-method (generic-function method)
503 ;; Note: Error check prohibited by ANSI spec removed.
504 (when (eq generic-function (method-generic-function method))
505 (let* ((name (generic-function-name generic-function))
506 (specializers (method-specializers method))
507 (methods (generic-function-methods generic-function))
508 (new-methods (remove method methods)))
509 (setf (method-generic-function method) nil)
510 (setf (generic-function-methods generic-function) new-methods)
511 (dolist (specializer (method-specializers method))
512 (remove-direct-method specializer method))
513 (set-arg-info generic-function)
517 allocate-instance shared-initialize initialize-instance))
518 (update-make-instance-function-table (type-class (car specializers))))
519 (update-dfun generic-function)
522 (defun compute-applicable-methods-function (generic-function arguments)
523 (values (compute-applicable-methods-using-types
525 (types-from-arguments generic-function arguments 'eql))))
527 (defmethod compute-applicable-methods
528 ((generic-function generic-function) arguments)
529 (values (compute-applicable-methods-using-types
531 (types-from-arguments generic-function arguments 'eql))))
533 (defmethod compute-applicable-methods-using-classes
534 ((generic-function generic-function) classes)
535 (compute-applicable-methods-using-types
537 (types-from-arguments generic-function classes 'class-eq)))
539 (defun proclaim-incompatible-superclasses (classes)
540 (setq classes (mapcar #'(lambda (class)
545 (dolist (class classes)
546 (dolist (other-class classes)
547 (unless (eq class other-class)
548 (pushnew other-class (class-incompatible-superclass-list class))))))
550 (defun superclasses-compatible-p (class1 class2)
551 (let ((cpl1 (class-precedence-list class1))
552 (cpl2 (class-precedence-list class2)))
554 (dolist (ic (class-incompatible-superclass-list sc1))
556 (return-from superclasses-compatible-p nil))))))
559 #'proclaim-incompatible-superclasses
560 '(;; superclass class
561 (built-in-class std-class structure-class) ; direct subclasses of pcl-class
562 (standard-class funcallable-standard-class)
563 ;; superclass metaobject
564 (class eql-specializer class-eq-specializer method method-combination
565 generic-function slot-definition)
566 ;; metaclass built-in-class
567 (number sequence character ; direct subclasses of t, but not array
568 standard-object structure-object) ; or symbol
569 (number array character symbol ; direct subclasses of t, but not
570 standard-object structure-object) ; sequence
571 (complex float rational) ; direct subclasses of number
572 (integer ratio) ; direct subclasses of rational
573 (list vector) ; direct subclasses of sequence
574 (cons null) ; direct subclasses of list
575 (string bit-vector) ; direct subclasses of vector
578 (defmethod same-specializer-p ((specl1 specializer) (specl2 specializer))
581 (defmethod same-specializer-p ((specl1 class) (specl2 class))
584 (defmethod specializer-class ((specializer class))
587 (defmethod same-specializer-p ((specl1 class-eq-specializer)
588 (specl2 class-eq-specializer))
589 (eq (specializer-class specl1) (specializer-class specl2)))
591 (defmethod same-specializer-p ((specl1 eql-specializer)
592 (specl2 eql-specializer))
593 (eq (specializer-object specl1) (specializer-object specl2)))
595 (defmethod specializer-class ((specializer eql-specializer))
596 (class-of (slot-value specializer 'object)))
598 (defvar *in-gf-arg-info-p* nil)
599 (setf (gdefinition 'arg-info-reader)
600 (let ((mf (initialize-method-function
601 (make-internal-reader-method-function
602 'standard-generic-function 'arg-info)
604 #'(lambda (&rest args) (funcall mf args nil))))
606 (defun types-from-arguments (generic-function arguments
607 &optional type-modifier)
608 (multiple-value-bind (nreq applyp metatypes nkeys arg-info)
609 (get-generic-function-info generic-function)
610 (declare (ignore applyp metatypes nkeys))
611 (let ((types-rev nil))
612 (dotimes-fixnum (i nreq)
615 (error "The function ~S requires at least ~D arguments"
616 (generic-function-name generic-function)
618 (let ((arg (pop arguments)))
619 (push (if type-modifier `(,type-modifier ,arg) arg) types-rev)))
620 (values (nreverse types-rev) arg-info))))
622 (defun get-wrappers-from-classes (nkeys wrappers classes metatypes)
623 (let* ((w wrappers) (w-tail w) (mt-tail metatypes))
624 (dolist (class (if (listp classes) classes (list classes)))
625 (unless (eq t (car mt-tail))
626 (let ((c-w (class-wrapper class)))
627 (unless c-w (return-from get-wrappers-from-classes nil))
630 (setf (car w-tail) c-w
631 w-tail (cdr w-tail)))))
632 (setq mt-tail (cdr mt-tail)))
635 (defun sdfun-for-caching (gf classes)
636 (let ((types (mapcar #'class-eq-type classes)))
637 (multiple-value-bind (methods all-applicable-and-sorted-p)
638 (compute-applicable-methods-using-types gf types)
639 (function-funcall (get-secondary-dispatch-function1
640 gf methods types nil t all-applicable-and-sorted-p)
641 nil (mapcar #'class-wrapper classes)))))
643 (defun value-for-caching (gf classes)
644 (let ((methods (compute-applicable-methods-using-types
645 gf (mapcar #'class-eq-type classes))))
646 (method-function-get (or (method-fast-function (car methods))
647 (method-function (car methods)))
650 (defun default-secondary-dispatch-function (generic-function)
651 #'(lambda (&rest args)
652 (let ((methods (compute-applicable-methods generic-function args)))
654 (let ((emf (get-effective-method-function generic-function
656 (invoke-emf emf args))
657 (apply #'no-applicable-method generic-function args)))))
660 (loop (when (atom x) (return (eq x y)))
661 (when (atom y) (return nil))
662 (unless (eq (car x) (car y)) (return nil))
663 (setq x (cdr x) y (cdr y))))
665 (defvar *std-cam-methods* nil)
667 (defun compute-applicable-methods-emf (generic-function)
668 (if (eq *boot-state* 'complete)
669 (let* ((cam (gdefinition 'compute-applicable-methods))
670 (cam-methods (compute-applicable-methods-using-types
671 cam (list `(eql ,generic-function) t))))
672 (values (get-effective-method-function cam cam-methods)
674 (or *std-cam-methods*
675 (setq *std-cam-methods*
676 (compute-applicable-methods-using-types
677 cam (list `(eql ,cam) t)))))))
678 (values #'compute-applicable-methods-function t)))
680 (defun compute-applicable-methods-emf-std-p (gf)
681 (gf-info-c-a-m-emf-std-p (gf-arg-info gf)))
683 (defvar *old-c-a-m-gf-methods* nil)
685 (defun update-all-c-a-m-gf-info (c-a-m-gf)
686 (let ((methods (generic-function-methods c-a-m-gf)))
687 (if (and *old-c-a-m-gf-methods*
688 (every #'(lambda (old-method)
689 (member old-method methods))
690 *old-c-a-m-gf-methods*))
691 (let ((gfs-to-do nil)
692 (gf-classes-to-do nil))
693 (dolist (method methods)
694 (unless (member method *old-c-a-m-gf-methods*)
695 (let ((specl (car (method-specializers method))))
696 (if (eql-specializer-p specl)
697 (pushnew (specializer-object specl) gfs-to-do)
698 (pushnew (specializer-class specl) gf-classes-to-do)))))
699 (map-all-generic-functions
701 (when (or (member gf gfs-to-do)
702 (dolist (class gf-classes-to-do nil)
704 (class-precedence-list (class-of gf)))))
705 (update-c-a-m-gf-info gf)))))
706 (map-all-generic-functions #'update-c-a-m-gf-info))
707 (setq *old-c-a-m-gf-methods* methods)))
709 (defun update-gf-info (gf)
710 (update-c-a-m-gf-info gf)
711 (update-gf-simple-accessor-type gf))
713 (defun update-c-a-m-gf-info (gf)
714 (unless (early-gf-p gf)
715 (multiple-value-bind (c-a-m-emf std-p)
716 (compute-applicable-methods-emf gf)
717 (let ((arg-info (gf-arg-info gf)))
718 (setf (gf-info-static-c-a-m-emf arg-info) c-a-m-emf)
719 (setf (gf-info-c-a-m-emf-std-p arg-info) std-p)))))
721 (defun update-gf-simple-accessor-type (gf)
722 (let ((arg-info (gf-arg-info gf)))
723 (setf (gf-info-simple-accessor-type arg-info)
724 (let* ((methods (generic-function-methods gf))
725 (class (and methods (class-of (car methods))))
728 *the-class-standard-reader-method*)
731 *the-class-standard-writer-method*)
734 *the-class-standard-boundp-method*)
736 (when (and (gf-info-c-a-m-emf-std-p arg-info)
738 (dolist (method (cdr methods) t)
739 (unless (eq class (class-of method)) (return nil)))
740 (eq (generic-function-method-combination gf)
741 *standard-method-combination*))
744 (defun get-accessor-method-function (gf type class slotd)
745 (let* ((std-method (standard-svuc-method type))
746 (str-method (structure-svuc-method type))
747 (types1 `((eql ,class) (class-eq ,class) (eql ,slotd)))
748 (types (if (eq type 'writer) `(t ,@types1) types1))
749 (methods (compute-applicable-methods-using-types gf types))
750 (std-p (null (cdr methods))))
753 (get-optimized-std-accessor-method-function class slotd type)
754 (get-accessor-from-svuc-method-function
756 (get-secondary-dispatch-function
758 `((,(car (or (member std-method methods)
759 (member str-method methods)
760 (error "error in get-accessor-method-function")))
761 ,(get-optimized-std-slot-value-using-class-method-function
763 (unless (and (eq type 'writer)
764 (dolist (method methods t)
765 (unless (eq (car (method-specializers method))
768 (let ((wrappers (list (wrapper-of class)
769 (class-wrapper class)
770 (wrapper-of slotd))))
771 (if (eq type 'writer)
772 (cons (class-wrapper *the-class-t*) wrappers)
777 ;;; used by OPTIMIZE-SLOT-VALUE-BY-CLASS-P (vector.lisp)
778 (defun update-slot-value-gf-info (gf type)
780 (update-std-or-str-methods gf type))
781 (when (and (standard-svuc-method type) (structure-svuc-method type))
782 (flet ((update-class (class)
783 (when (class-finalized-p class)
784 (dolist (slotd (class-slots class))
785 (compute-slot-accessor-info slotd type gf)))))
787 (update-class *new-class*)
788 (map-all-classes #'update-class 'slot-object)))))
790 (defvar *standard-slot-value-using-class-method* nil)
791 (defvar *standard-setf-slot-value-using-class-method* nil)
792 (defvar *standard-slot-boundp-using-class-method* nil)
793 (defvar *structure-slot-value-using-class-method* nil)
794 (defvar *structure-setf-slot-value-using-class-method* nil)
795 (defvar *structure-slot-boundp-using-class-method* nil)
797 (defun standard-svuc-method (type)
799 (reader *standard-slot-value-using-class-method*)
800 (writer *standard-setf-slot-value-using-class-method*)
801 (boundp *standard-slot-boundp-using-class-method*)))
803 (defun set-standard-svuc-method (type method)
805 (reader (setq *standard-slot-value-using-class-method* method))
806 (writer (setq *standard-setf-slot-value-using-class-method* method))
807 (boundp (setq *standard-slot-boundp-using-class-method* method))))
809 (defun structure-svuc-method (type)
811 (reader *structure-slot-value-using-class-method*)
812 (writer *structure-setf-slot-value-using-class-method*)
813 (boundp *structure-slot-boundp-using-class-method*)))
815 (defun set-structure-svuc-method (type method)
817 (reader (setq *structure-slot-value-using-class-method* method))
818 (writer (setq *structure-setf-slot-value-using-class-method* method))
819 (boundp (setq *structure-slot-boundp-using-class-method* method))))
821 (defun update-std-or-str-methods (gf type)
822 (dolist (method (generic-function-methods gf))
823 (let ((specls (method-specializers method)))
824 (when (and (or (not (eq type 'writer))
825 (eq (pop specls) *the-class-t*))
826 (every #'classp specls))
827 (cond ((and (eq (class-name (car specls))
829 (eq (class-name (cadr specls))
831 (eq (class-name (caddr specls))
832 'standard-effective-slot-definition))
833 (set-standard-svuc-method type method))
834 ((and (eq (class-name (car specls))
836 (eq (class-name (cadr specls))
838 (eq (class-name (caddr specls))
839 'structure-effective-slot-definition))
840 (set-structure-svuc-method type method)))))))
842 (defun mec-all-classes-internal (spec precompute-p)
843 (cons (specializer-class spec)
846 (not (or (eq spec *the-class-t*)
847 (eq spec *the-class-slot-object*)
848 (eq spec *the-class-std-object*)
849 (eq spec *the-class-standard-object*)
850 (eq spec *the-class-structure-object*)))
851 (let ((sc (class-direct-subclasses spec)))
853 (mapcan #'(lambda (class)
854 (mec-all-classes-internal class precompute-p))
857 (defun mec-all-classes (spec precompute-p)
858 (let ((classes (mec-all-classes-internal spec precompute-p)))
859 (if (null (cdr classes))
861 (let* ((a-classes (cons nil classes))
863 (loop (when (null (cdr tail))
864 (return (cdr a-classes)))
865 (let ((class (cadr tail))
867 (if (dolist (c ttail nil)
868 (when (eq class c) (return t)))
869 (setf (cdr tail) (cddr tail))
870 (setf tail (cdr tail)))))))))
872 (defun mec-all-class-lists (spec-list precompute-p)
875 (let* ((car-all-classes (mec-all-classes (car spec-list)
877 (all-class-lists (mec-all-class-lists (cdr spec-list)
879 (mapcan #'(lambda (list)
880 (mapcar #'(lambda (c) (cons c list)) car-all-classes))
883 (defun make-emf-cache (generic-function valuep cache classes-list new-class)
884 (let* ((arg-info (gf-arg-info generic-function))
885 (nkeys (arg-info-nkeys arg-info))
886 (metatypes (arg-info-metatypes arg-info))
887 (wrappers (unless (eq nkeys 1) (make-list nkeys)))
888 (precompute-p (gf-precompute-dfun-and-emf-p arg-info))
889 (default '(default)))
890 (flet ((add-class-list (classes)
891 (when (or (null new-class) (memq new-class classes))
892 (let ((wrappers (get-wrappers-from-classes
893 nkeys wrappers classes metatypes)))
895 (eq default (probe-cache cache wrappers default)))
896 (let ((value (cond ((eq valuep t)
897 (sdfun-for-caching generic-function
899 ((eq valuep :constant-value)
900 (value-for-caching generic-function
902 (setq cache (fill-cache cache wrappers value t))))))))
904 (mapc #'add-class-list classes-list)
905 (dolist (method (generic-function-methods generic-function))
906 (mapc #'add-class-list
907 (mec-all-class-lists (method-specializers method)
911 (defmacro class-test (arg class)
912 (cond ((eq class *the-class-t*)
914 ((eq class *the-class-slot-object*)
915 `(not (cl:typep (cl:class-of ,arg) 'cl:built-in-class)))
916 ((eq class *the-class-std-object*)
917 `(or (std-instance-p ,arg) (fsc-instance-p ,arg)))
918 ((eq class *the-class-standard-object*)
919 `(std-instance-p ,arg))
920 ((eq class *the-class-funcallable-standard-object*)
921 `(fsc-instance-p ,arg))
923 `(typep ,arg ',(class-name class)))))
925 (defmacro class-eq-test (arg class)
926 `(eq (class-of ,arg) ',class))
928 (defmacro eql-test (arg object)
929 `(eql ,arg ',object))
931 (defun dnet-methods-p (form)
933 (or (eq (car form) 'methods)
934 (eq (car form) 'unordered-methods))))
936 ;;; This is CASE, but without gensyms.
937 (defmacro scase (arg &rest clauses)
938 `(let ((.case-arg. ,arg))
939 (cond ,@(mapcar #'(lambda (clause)
940 (list* (cond ((null (car clause))
942 ((consp (car clause))
943 (if (null (cdar clause))
948 ((member (car clause) '(t otherwise))
951 `(eql .case-arg. ',(car clause))))
956 (defmacro mcase (arg &rest clauses) `(scase ,arg ,@clauses))
958 (defun generate-discrimination-net (generic-function methods types sorted-p)
959 (let* ((arg-info (gf-arg-info generic-function))
960 (precedence (arg-info-precedence arg-info)))
961 (generate-discrimination-net-internal
962 generic-function methods types
963 #'(lambda (methods known-types)
966 (let ((sorted-methods nil))
968 (copy-list methods) precedence
970 (when sorted-methods (return-from one-order-p nil))
971 (setq sorted-methods methods)))
972 (setq methods sorted-methods))
974 `(methods ,methods ,known-types)
975 `(unordered-methods ,methods ,known-types)))
976 #'(lambda (position type true-value false-value)
977 (let ((arg (dfun-arg-symbol position)))
978 (if (eq (car type) 'eql)
979 (let* ((false-case-p (and (consp false-value)
980 (or (eq (car false-value) 'scase)
981 (eq (car false-value) 'mcase))
982 (eq arg (cadr false-value))))
983 (false-clauses (if false-case-p
985 `((t ,false-value))))
986 (case-sym (if (and (dnet-methods-p true-value)
988 (eq (car false-value) 'mcase)
989 (dnet-methods-p false-value)))
992 (type-sym `(,(cadr type))))
994 (,type-sym ,true-value)
996 `(if ,(let ((arg (dfun-arg-symbol position)))
998 (class `(class-test ,arg ,(cadr type)))
999 (class-eq `(class-eq-test ,arg ,(cadr type)))))
1004 (defun class-from-type (type)
1005 (if (or (atom type) (eq (car type) t))
1008 (and (dolist (type (cdr type) *the-class-t*)
1009 (when (and (consp type) (not (eq (car type) 'not)))
1010 (return (class-from-type type)))))
1012 (eql (class-of (cadr type)))
1013 (class-eq (cadr type))
1014 (class (cadr type)))))
1016 (defun precompute-effective-methods (gf caching-p &optional classes-list-p)
1017 (let* ((arg-info (gf-arg-info gf))
1018 (methods (generic-function-methods gf))
1019 (precedence (arg-info-precedence arg-info))
1020 (*in-precompute-effective-methods-p* t)
1022 (generate-discrimination-net-internal
1024 #'(lambda (methods known-types)
1026 (when classes-list-p
1027 (push (mapcar #'class-from-type known-types) classes-list))
1028 (let ((no-eql-specls-p (not (methods-contain-eql-specializer-p
1033 (get-secondary-dispatch-function1
1034 gf methods known-types
1035 nil caching-p no-eql-specls-p))))))
1036 #'(lambda (position type true-value false-value)
1037 (declare (ignore position type true-value false-value))
1040 (if (and (consp type) (eq (car type) 'eql))
1041 `(class-eq ,(class-of (cadr type)))
1045 ;;; We know that known-type implies neither new-type nor `(not ,new-type).
1046 (defun augment-type (new-type known-type)
1047 (if (or (eq known-type t)
1048 (eq (car new-type) 'eql))
1050 (let ((so-far (if (and (consp known-type) (eq (car known-type) 'and))
1052 (list known-type))))
1053 (unless (eq (car new-type) 'not)
1055 (mapcan #'(lambda (type)
1056 (unless (*subtypep new-type type)
1061 `(and ,new-type ,@so-far)))))
1063 (defun generate-discrimination-net-internal
1064 (gf methods types methods-function test-function type-function)
1065 (let* ((arg-info (gf-arg-info gf))
1066 (precedence (arg-info-precedence arg-info))
1067 (nreq (arg-info-number-required arg-info))
1068 (metatypes (arg-info-metatypes arg-info)))
1069 (labels ((do-column (p-tail contenders known-types)
1071 (let* ((position (car p-tail))
1072 (known-type (or (nth position types) t)))
1073 (if (eq (nth position metatypes) t)
1074 (do-column (cdr p-tail) contenders
1075 (cons (cons position known-type)
1077 (do-methods p-tail contenders
1078 known-type () known-types)))
1079 (funcall methods-function contenders
1080 (let ((k-t (make-list nreq)))
1081 (dolist (index+type known-types)
1082 (setf (nth (car index+type) k-t)
1085 (do-methods (p-tail contenders known-type winners known-types)
1087 ;; is a (sorted) list of methods that must be discriminated.
1089 ;; is the type of this argument, constructed from tests
1092 ;; is a (sorted) list of methods that are potentially
1093 ;; applicable after the discrimination has been made.
1094 (if (null contenders)
1095 (do-column (cdr p-tail)
1097 (cons (cons (car p-tail) known-type)
1099 (let* ((position (car p-tail))
1100 (method (car contenders))
1101 (specl (nth position (method-specializers method)))
1102 (type (funcall type-function
1103 (type-from-specializer specl))))
1104 (multiple-value-bind (app-p maybe-app-p)
1105 (specializer-applicable-using-type-p type known-type)
1106 (flet ((determined-to-be (truth-value)
1107 (if truth-value app-p (not maybe-app-p)))
1108 (do-if (truth &optional implied)
1109 (let ((ntype (if truth type `(not ,type))))
1114 (augment-type ntype known-type))
1116 (append winners `(,method))
1119 (cond ((determined-to-be nil) (do-if nil t))
1120 ((determined-to-be t) (do-if t t))
1121 (t (funcall test-function position type
1122 (do-if t) (do-if nil))))))))))
1123 (do-column precedence methods ()))))
1125 (defun compute-secondary-dispatch-function (generic-function net &optional
1126 method-alist wrappers)
1127 (function-funcall (compute-secondary-dispatch-function1 generic-function net)
1128 method-alist wrappers))
1130 (defvar *eq-case-table-limit* 15)
1131 (defvar *case-table-limit* 10)
1133 (defun compute-mcase-parameters (case-list)
1134 (unless (eq t (caar (last case-list)))
1135 (error "The key for the last case arg to mcase was not T"))
1136 (let* ((eq-p (dolist (case case-list t)
1137 (unless (or (eq (car case) t)
1138 (symbolp (caar case)))
1140 (len (1- (length case-list)))
1141 (type (cond ((= len 1)
1145 *eq-case-table-limit*
1146 *case-table-limit*))
1152 (defmacro mlookup (key info default &optional eq-p type)
1153 (unless (or (eq eq-p t) (null eq-p))
1154 (error "Invalid eq-p argument"))
1157 `(if (,(if eq-p 'eq 'eql) ,key (car ,info))
1161 `(dolist (e ,info ,default)
1162 (when (,(if eq-p 'eq 'eql) (car e) ,key)
1165 `(gethash ,key ,info ,default))))
1167 (defun net-test-converter (form)
1169 (default-test-converter form)
1171 ((invoke-effective-method-function invoke-fast-method-call)
1178 `(mlookup ,(cadr form)
1181 ,@(compute-mcase-parameters (cddr form))))
1182 (t (default-test-converter form)))))
1184 (defun net-code-converter (form)
1186 (default-code-converter form)
1188 ((methods unordered-methods)
1189 (let ((gensym (gensym)))
1193 (let ((mp (compute-mcase-parameters (cddr form)))
1194 (gensym (gensym)) (default (gensym)))
1195 (values `(mlookup ,(cadr form) ,gensym ,default ,@mp)
1196 (list gensym default))))
1198 (default-code-converter form)))))
1200 (defun net-constant-converter (form generic-function)
1201 (or (let ((c (methods-converter form generic-function)))
1204 (default-constant-converter form)
1207 (let* ((mp (compute-mcase-parameters (cddr form)))
1208 (list (mapcar #'(lambda (clause)
1209 (let ((key (car clause))
1210 (meth (cadr clause)))
1211 (cons (if (consp key) (car key) key)
1213 meth generic-function))))
1215 (default (car (last list))))
1216 (list (list* ':mcase mp (nbutlast list))
1219 (default-constant-converter form))))))
1221 (defun methods-converter (form generic-function)
1222 (cond ((and (consp form) (eq (car form) 'methods))
1224 (get-effective-method-function1 generic-function (cadr form))))
1225 ((and (consp form) (eq (car form) 'unordered-methods))
1226 (default-secondary-dispatch-function generic-function))))
1228 (defun convert-methods (constant method-alist wrappers)
1229 (if (and (consp constant)
1230 (eq (car constant) '.methods.))
1231 (funcall (cdr constant) method-alist wrappers)
1234 (defun convert-table (constant method-alist wrappers)
1235 (cond ((and (consp constant)
1236 (eq (car constant) ':mcase))
1237 (let ((alist (mapcar #'(lambda (k+m)
1239 (convert-methods (cdr k+m)
1243 (mp (cadr constant)))
1250 (let ((table (make-hash-table :test (if (car mp) 'eq 'eql))))
1252 (setf (gethash (car k+m) table) (cdr k+m)))
1255 (defun compute-secondary-dispatch-function1 (generic-function net
1256 &optional function-p)
1258 ((and (eq (car net) 'methods) (not function-p))
1259 (get-effective-method-function1 generic-function (cadr net)))
1261 (let* ((name (generic-function-name generic-function))
1262 (arg-info (gf-arg-info generic-function))
1263 (metatypes (arg-info-metatypes arg-info))
1264 (applyp (arg-info-applyp arg-info))
1265 (fmc-arg-info (cons (length metatypes) applyp))
1266 (arglist (if function-p
1267 (make-dfun-lambda-list metatypes applyp)
1268 (make-fast-method-call-lambda-list metatypes applyp))))
1269 (multiple-value-bind (cfunction constants)
1270 (get-function1 `(,(if function-p
1271 'sb-kernel:instance-lambda
1274 ,@(unless function-p
1275 `((declare (ignore .pv-cell.
1276 .next-method-call.))))
1277 (locally (declare #.*optimize-speed*)
1279 ,(make-emf-call metatypes applyp 'emf))))
1280 #'net-test-converter
1281 #'net-code-converter
1283 (net-constant-converter form generic-function)))
1284 #'(lambda (method-alist wrappers)
1285 (let* ((alist (list nil))
1287 (dolist (constant constants)
1288 (let* ((a (or (dolist (a alist nil)
1289 (when (eq (car a) constant)
1293 constant method-alist wrappers)
1295 constant method-alist wrappers)))))
1297 (setf (cdr alist-tail) new)
1298 (setf alist-tail new)))
1299 (let ((function (apply cfunction (mapcar #'cdr (cdr alist)))))
1302 (make-fast-method-call
1303 :function (set-function-name function
1304 `(sdfun-method ,name))
1305 :arg-info fmc-arg-info))))))))))
1307 (defvar *show-make-unordered-methods-emf-calls* nil)
1309 (defun make-unordered-methods-emf (generic-function methods)
1310 (when *show-make-unordered-methods-emf-calls*
1311 (format t "~&make-unordered-methods-emf ~S~%"
1312 (generic-function-name generic-function)))
1313 #'(lambda (&rest args)
1314 (let* ((types (types-from-arguments generic-function args 'eql))
1315 (smethods (sort-applicable-methods generic-function
1318 (emf (get-effective-method-function generic-function smethods)))
1319 (invoke-emf emf args))))
1321 ;;; The value returned by compute-discriminating-function is a function
1322 ;;; object. It is called a discriminating function because it is called
1323 ;;; when the generic function is called and its role is to discriminate
1324 ;;; on the arguments to the generic function and then call appropriate
1325 ;;; method functions.
1327 ;;; A discriminating function can only be called when it is installed as
1328 ;;; the funcallable instance function of the generic function for which
1329 ;;; it was computed.
1331 ;;; More precisely, if compute-discriminating-function is called with an
1332 ;;; argument <gf1>, and returns a result <df1>, that result must not be
1333 ;;; passed to apply or funcall directly. Rather, <df1> must be stored as
1334 ;;; the funcallable instance function of the same generic function <gf1>
1335 ;;; (using set-funcallable-instance-function). Then the generic function
1336 ;;; can be passed to funcall or apply.
1338 ;;; An important exception is that methods on this generic function are
1339 ;;; permitted to return a function which itself ends up calling the value
1340 ;;; returned by a more specific method. This kind of `encapsulation' of
1341 ;;; discriminating function is critical to many uses of the MOP.
1343 ;;; As an example, the following canonical case is legal:
1345 ;;; (defmethod compute-discriminating-function ((gf my-generic-function))
1346 ;;; (let ((std (call-next-method)))
1348 ;;; (print (list 'call-to-gf gf arg))
1349 ;;; (funcall std arg))))
1351 ;;; Because many discriminating functions would like to use a dynamic
1352 ;;; strategy in which the precise discriminating function changes with
1353 ;;; time it is important to specify how a discriminating function is
1354 ;;; permitted itself to change the funcallable instance function of the
1355 ;;; generic function.
1357 ;;; Discriminating functions may set the funcallable instance function
1358 ;;; of the generic function, but the new value must be generated by making
1359 ;;; a call to COMPUTE-DISCRIMINATING-FUNCTION. This is to ensure that any
1360 ;;; more specific methods which may have encapsulated the discriminating
1361 ;;; function will get a chance to encapsulate the new, inner discriminating
1364 ;;; This implies that if a discriminating function wants to modify itself
1365 ;;; it should first store some information in the generic function proper,
1366 ;;; and then call compute-discriminating-function. The appropriate method
1367 ;;; on compute-discriminating-function will see the information stored in
1368 ;;; the generic function and generate a discriminating function accordingly.
1370 ;;; The following is an example of a discriminating function which modifies
1371 ;;; itself in accordance with this protocol:
1373 ;;; (defmethod compute-discriminating-function ((gf my-generic-function))
1375 ;;; (cond (<some condition>
1376 ;;; <store some info in the generic function>
1377 ;;; (set-funcallable-instance-function
1379 ;;; (compute-discriminating-function gf))
1380 ;;; (funcall gf arg))
1382 ;;; <call-a-method-of-gf>))))
1384 ;;; Whereas this code would not be legal:
1386 ;;; (defmethod compute-discriminating-function ((gf my-generic-function))
1388 ;;; (cond (<some condition>
1389 ;;; (set-funcallable-instance-function
1391 ;;; #'(lambda (a) ..))
1392 ;;; (funcall gf arg))
1394 ;;; <call-a-method-of-gf>))))
1396 ;;; NOTE: All the examples above assume that all instances of the class
1397 ;;; my-generic-function accept only one argument.
1399 (defun slot-value-using-class-dfun (class object slotd)
1400 (declare (ignore class))
1401 (function-funcall (slot-definition-reader-function slotd) object))
1403 (defun setf-slot-value-using-class-dfun (new-value class object slotd)
1404 (declare (ignore class))
1405 (function-funcall (slot-definition-writer-function slotd) new-value object))
1407 (defun slot-boundp-using-class-dfun (class object slotd)
1408 (declare (ignore class))
1409 (function-funcall (slot-definition-boundp-function slotd) object))
1411 (defmethod compute-discriminating-function ((gf standard-generic-function))
1412 (with-slots (dfun-state arg-info) gf
1413 (typecase dfun-state
1414 (null (let ((name (generic-function-name gf)))
1415 (when (eq name 'compute-applicable-methods)
1416 (update-all-c-a-m-gf-info gf))
1417 (cond ((eq name 'slot-value-using-class)
1418 (update-slot-value-gf-info gf 'reader)
1419 #'slot-value-using-class-dfun)
1420 ((equal name '(setf slot-value-using-class))
1421 (update-slot-value-gf-info gf 'writer)
1422 #'setf-slot-value-using-class-dfun)
1423 ((eq name 'slot-boundp-using-class)
1424 (update-slot-value-gf-info gf 'boundp)
1425 #'slot-boundp-using-class-dfun)
1426 ((gf-precompute-dfun-and-emf-p arg-info)
1427 (make-final-dfun gf))
1429 (make-initial-dfun gf)))))
1430 (function dfun-state)
1431 (cons (car dfun-state)))))
1433 (defmethod update-gf-dfun ((class std-class) gf)
1434 (let ((*new-class* class)
1435 #|| (name (generic-function-name gf)) ||#
1436 (arg-info (gf-arg-info gf)))
1438 ((eq name 'slot-value-using-class)
1439 (update-slot-value-gf-info gf 'reader))
1440 ((equal name '(setf slot-value-using-class))
1441 (update-slot-value-gf-info gf 'writer))
1442 ((eq name 'slot-boundp-using-class)
1443 (update-slot-value-gf-info gf 'boundp))
1445 ((gf-precompute-dfun-and-emf-p arg-info)
1446 (multiple-value-bind (dfun cache info)
1447 (make-final-dfun-internal gf)
1448 (set-dfun gf dfun cache info) ; lest the cache be freed twice
1449 (update-dfun gf dfun cache info))))))
1451 (defmethod function-keywords ((method standard-method))
1452 (multiple-value-bind (nreq nopt keysp restp allow-other-keys-p keywords)
1453 (analyze-lambda-list (if (consp method)
1454 (early-method-lambda-list method)
1455 (method-lambda-list method)))
1456 (declare (ignore nreq nopt keysp restp))
1457 (values keywords allow-other-keys-p)))
1459 (defun method-ll->generic-function-ll (ll)
1460 (multiple-value-bind
1461 (nreq nopt keysp restp allow-other-keys-p keywords keyword-parameters)
1462 (analyze-lambda-list ll)
1463 (declare (ignore nreq nopt keysp restp allow-other-keys-p keywords))
1464 (remove-if #'(lambda (s)
1465 (or (memq s keyword-parameters)
1466 (eq s '&allow-other-keys)))
1469 ;;; This is based on the rules of method lambda list congruency defined in
1470 ;;; the spec. The lambda list it constructs is the pretty union of the
1471 ;;; lambda lists of all the methods. It doesn't take method applicability
1472 ;;; into account at all yet.
1473 (defmethod generic-function-pretty-arglist
1474 ((generic-function standard-generic-function))
1475 (let ((methods (generic-function-methods generic-function))
1478 (multiple-value-bind (required optional rest key allow-other-keys)
1479 (method-pretty-arglist (car methods))
1480 (dolist (m (cdr methods))
1481 (multiple-value-bind (method-key-keywords
1482 method-allow-other-keys
1484 (function-keywords m)
1485 ;; we've modified function-keywords to return what we want as
1486 ;; the third value, no other change here.
1487 (declare (ignore method-key-keywords))
1488 (setq key (union key method-key))
1489 (setq allow-other-keys (or allow-other-keys
1490 method-allow-other-keys))))
1491 (when allow-other-keys
1492 (setq arglist '(&allow-other-keys)))
1494 (setq arglist (nconc (list '&key) key arglist)))
1496 (setq arglist (nconc (list '&rest rest) arglist)))
1498 (setq arglist (nconc (list '&optional) optional arglist)))
1499 (nconc required arglist)))))
1501 (defmethod method-pretty-arglist ((method standard-method))
1506 (allow-other-keys nil)
1508 (arglist (method-lambda-list method)))
1509 (dolist (arg arglist)
1510 (cond ((eq arg '&optional) (setq state 'optional))
1511 ((eq arg '&rest) (setq state 'rest))
1512 ((eq arg '&key) (setq state 'key))
1513 ((eq arg '&allow-other-keys) (setq allow-other-keys t))
1514 ((memq arg lambda-list-keywords))
1517 (required (push arg required))
1518 (optional (push arg optional))
1519 (key (push arg key))
1520 (rest (setq rest arg))))))
1521 (values (nreverse required)