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 (defmethod shared-initialize :after ((slotd standard-slot-definition)
31 (declare (ignore slot-names))
32 (with-slots (allocation class)
34 (setq allocation (if (eq allocation :class) class allocation))))
36 (defmethod shared-initialize :after ((slotd structure-slot-definition)
38 &key (allocation :instance))
39 (declare (ignore slot-names))
40 (unless (eq allocation :instance)
41 (error "Structure slots must have :INSTANCE allocation.")))
43 (defmethod inform-type-system-about-class ((class structure-class) (name t))
48 ;;; Methods themselves are simple inanimate objects. Most properties of
49 ;;; methods are immutable, methods cannot be reinitialized. The following
50 ;;; properties of methods can be changed:
51 ;;; METHOD-GENERIC-FUNCTION
52 ;;; METHOD-FUNCTION ??
54 (defmethod method-function ((method standard-method))
55 (or (slot-value method 'function)
56 (let ((fmf (slot-value method 'fast-function)))
57 (unless fmf ; The :BEFORE SHARED-INITIALIZE method prevents this.
58 (error "~S doesn't seem to have a METHOD-FUNCTION." method))
59 (setf (slot-value method 'function)
60 (method-function-from-fast-function fmf)))))
62 (defmethod accessor-method-class ((method standard-accessor-method))
63 (car (slot-value method 'specializers)))
65 (defmethod accessor-method-class ((method standard-writer-method))
66 (cadr (slot-value method 'specializers)))
70 ;;; Error checking is done in before methods. Because of the simplicity of
71 ;;; standard method objects the standard primary method can fill the slots.
73 ;;; Methods are not reinitializable.
75 (defmethod reinitialize-instance ((method standard-method) &rest initargs)
76 (declare (ignore initargs))
77 (error "An attempt was made to reinitialize the method ~S.~%~
78 Method objects cannot be reinitialized."
81 (defmethod legal-documentation-p ((object standard-method) x)
82 (if (or (null x) (stringp x))
86 (defmethod legal-lambda-list-p ((object standard-method) x)
90 (defmethod legal-method-function-p ((object standard-method) x)
95 (defmethod legal-qualifiers-p ((object standard-method) x)
96 (flet ((improper-list ()
97 (return-from legal-qualifiers-p "Is not a proper list.")))
98 (dolist-carefully (q x improper-list)
99 (let ((ok (legal-qualifier-p object q)))
101 (return-from legal-qualifiers-p
102 (format nil "Contains ~S which ~A" q ok)))))
105 (defmethod legal-qualifier-p ((object standard-method) x)
108 "is not a non-null atom"))
110 (defmethod legal-slot-name-p ((object standard-method) x)
111 (cond ((not (symbolp x)) "is not a symbol and so cannot be bound")
112 ((keywordp x) "is a keyword and so cannot be bound")
113 ((memq x '(t nil)) "cannot be bound")
114 ((constantp x) "is a constant and so cannot be bound")
117 (defmethod legal-specializers-p ((object standard-method) x)
118 (flet ((improper-list ()
119 (return-from legal-specializers-p "Is not a proper list.")))
120 (dolist-carefully (s x improper-list)
121 (let ((ok (legal-specializer-p object s)))
123 (return-from legal-specializers-p
124 (format nil "Contains ~S which ~A" s ok)))))
127 (defvar *allow-experimental-specializers-p* nil)
129 (defmethod legal-specializer-p ((object standard-method) x)
130 (if (if *allow-experimental-specializers-p*
133 (eql-specializer-p x)))
135 "is neither a class object nor an EQL specializer"))
137 (defmethod shared-initialize :before ((method standard-method)
145 (declare (ignore slot-names))
146 (flet ((lose (initarg value string)
147 (error "when initializing the method ~S:~%~
148 The ~S initialization argument was: ~S.~%~
150 method initarg value string)))
151 (let ((check-qualifiers (legal-qualifiers-p method qualifiers))
152 (check-lambda-list (legal-lambda-list-p method lambda-list))
153 (check-specializers (legal-specializers-p method specializers))
154 (check-function (legal-method-function-p method
157 (check-documentation (legal-documentation-p method documentation)))
158 (unless (eq check-qualifiers t)
159 (lose :qualifiers qualifiers check-qualifiers))
160 (unless (eq check-lambda-list t)
161 (lose :lambda-list lambda-list check-lambda-list))
162 (unless (eq check-specializers t)
163 (lose :specializers specializers check-specializers))
164 (unless (eq check-function t)
165 (lose :function function check-function))
166 (unless (eq check-documentation t)
167 (lose :documentation documentation check-documentation)))))
169 (defmethod shared-initialize :before ((method standard-accessor-method)
171 &key slot-name slot-definition)
172 (declare (ignore slot-names))
173 (unless slot-definition
174 (let ((legalp (legal-slot-name-p method slot-name)))
175 ;; FIXME: nasty convention; should be renamed to ILLEGAL-SLOT-NAME-P and
176 ;; ILLEGALP, and the convention redone to be less twisty
177 (unless (eq legalp t)
178 (error "The value of the :SLOT-NAME initarg ~A." legalp)))))
180 (defmethod shared-initialize :after ((method standard-method) slot-names
182 &key qualifiers method-spec plist)
183 (declare (ignore slot-names method-spec plist))
184 (initialize-method-function initargs nil method)
185 (setf (plist-value method 'qualifiers) qualifiers)
187 (setf (slot-value method 'closure-generator)
188 (method-function-closure-generator (slot-value method 'function))))
190 (defmethod shared-initialize :after ((method standard-accessor-method)
193 (declare (ignore slot-names))
194 (with-slots (slot-name slot-definition)
196 (unless slot-definition
197 (let ((class (accessor-method-class method)))
198 (when (slot-class-p class)
199 (setq slot-definition (find slot-name (class-direct-slots class)
200 :key #'slot-definition-name)))))
201 (when (and slot-definition (null slot-name))
202 (setq slot-name (slot-definition-name slot-definition)))))
204 (defmethod method-qualifiers ((method standard-method))
205 (plist-value method 'qualifiers))
207 (defvar *the-class-generic-function*
208 (find-class 'generic-function))
209 (defvar *the-class-standard-generic-function*
210 (find-class 'standard-generic-function))
212 (defmethod shared-initialize :before
213 ((generic-function standard-generic-function)
215 &key (name nil namep)
216 (lambda-list () lambda-list-p)
217 argument-precedence-order
220 (method-class nil method-class-supplied-p)
221 (method-combination nil method-combination-supplied-p))
222 (declare (ignore slot-names
223 declarations argument-precedence-order documentation
224 lambda-list lambda-list-p))
227 (set-function-name generic-function name))
229 (flet ((initarg-error (initarg value string)
230 (error "when initializing the generic function ~S:~%~
231 The ~S initialization argument was: ~A.~%~
233 generic-function initarg value string)))
234 (cond (method-class-supplied-p
235 (when (symbolp method-class)
236 (setq method-class (find-class method-class)))
237 (unless (and (classp method-class)
238 (*subtypep (class-eq-specializer method-class)
240 (initarg-error :method-class
242 "a subclass of the class METHOD"))
243 (setf (slot-value generic-function 'method-class) method-class))
244 ((slot-boundp generic-function 'method-class))
246 (initarg-error :method-class
248 "a subclass of the class METHOD")))
249 (cond (method-combination-supplied-p
250 (unless (method-combination-p method-combination)
251 (initarg-error :method-combination
253 "a method combination object")))
254 ((slot-boundp generic-function 'method-combination))
256 (initarg-error :method-combination
258 "a method combination object")))))
261 (defmethod reinitialize-instance ((generic-function standard-generic-function)
265 argument-precedence-order
270 (declare (ignore documentation declarations argument-precedence-order
271 lambda-list name method-class method-combination))
272 (macrolet ((add-initarg (check name slot-name)
274 (push (slot-value generic-function ,slot-name) initargs)
275 (push ,name initargs))))
276 ; (add-initarg name :name 'name)
277 ; (add-initarg lambda-list :lambda-list 'lambda-list)
278 ; (add-initarg argument-precedence-order
279 ; :argument-precedence-order
280 ; 'argument-precedence-order)
281 ; (add-initarg declarations :declarations 'declarations)
282 ; (add-initarg documentation :documentation 'documentation)
283 ; (add-initarg method-class :method-class 'method-class)
284 ; (add-initarg method-combination :method-combination 'method-combination)
285 (apply #'call-next-method generic-function initargs)))
288 ;;; These three are scheduled for demolition.
290 (defmethod remove-named-method (generic-function-name argument-specifiers
292 (let ((generic-function ())
294 (cond ((or (null (fboundp generic-function-name))
295 (not (generic-function-p
296 (setq generic-function
297 (symbol-function generic-function-name)))))
298 (error "~S does not name a generic function."
299 generic-function-name))
300 ((null (setq method (get-method generic-function
305 (error "There is no method for the generic function ~S~%~
306 which matches the ARGUMENT-SPECIFIERS ~S."
308 argument-specifiers))
310 (remove-method generic-function method)))))
312 (defun real-add-named-method (generic-function-name
316 &rest other-initargs)
317 (unless (and (fboundp generic-function-name)
318 (typep (symbol-function generic-function-name)
320 (sb-kernel::style-warn "implicitly creating new generic function ~S"
321 generic-function-name))
322 ;; XXX What about changing the class of the generic function if
323 ;; there is one? Whose job is that, anyway? Do we need something
324 ;; kind of like CLASS-FOR-REDEFINITION?
325 (let* ((generic-function
326 (ensure-generic-function generic-function-name))
327 (specs (parse-specializers specializers))
328 (proto (method-prototype-for-gf generic-function-name))
329 (new (apply #'make-instance (class-of proto)
330 :qualifiers qualifiers
332 :lambda-list lambda-list
334 (add-method generic-function new)))
336 (defun real-get-method (generic-function qualifiers specializers
337 &optional (errorp t))
339 (dolist (method (generic-function-methods generic-function))
340 (when (and (equal qualifiers (method-qualifiers method))
341 (every #'same-specializer-p specializers
342 (method-specializers method)))
347 (error "no method on ~S with qualifiers ~:S and specializers ~:S"
348 generic-function qualifiers specializers)))))
350 (defmethod find-method ((generic-function standard-generic-function)
351 qualifiers specializers &optional (errorp t))
352 (real-get-method generic-function qualifiers
353 (parse-specializers specializers) errorp))
355 ;;; Compute various information about a generic-function's arglist by looking
356 ;;; at the argument lists of the methods. The hair for trying not to use
357 ;;; &REST arguments lives here.
358 ;;; The values returned are:
359 ;;; number-of-required-arguments
360 ;;; the number of required arguments to this generic-function's
361 ;;; discriminating function
363 ;;; whether or not this generic-function's discriminating
364 ;;; function takes an &rest argument.
365 ;;; specialized-argument-positions
366 ;;; a list of the positions of the arguments this generic-function
367 ;;; specializes (e.g. for a classical generic-function this is the
369 (defmethod compute-discriminating-function-arglist-info
370 ((generic-function standard-generic-function))
371 ;;(declare (values number-of-required-arguments &rest-argument-p
372 ;; specialized-argument-postions))
373 (let ((number-required nil)
375 (specialized-positions ())
376 (methods (generic-function-methods generic-function)))
377 (dolist (method methods)
378 (multiple-value-setq (number-required restp specialized-positions)
379 (compute-discriminating-function-arglist-info-internal
380 generic-function method number-required restp specialized-positions)))
381 (values number-required restp (sort specialized-positions #'<))))
383 (defun compute-discriminating-function-arglist-info-internal
384 (generic-function method number-of-requireds restp
385 specialized-argument-positions)
386 (declare (ignore generic-function)
387 (type (or null fixnum) number-of-requireds))
389 (declare (fixnum requireds))
390 ;; Go through this methods arguments seeing how many are required,
391 ;; and whether there is an &rest argument.
392 (dolist (arg (method-lambda-list method))
393 (cond ((eq arg '&aux) (return))
394 ((memq arg '(&optional &rest &key))
395 (return (setq restp t)))
396 ((memq arg lambda-list-keywords))
397 (t (incf requireds))))
398 ;; Now go through this method's type specifiers to see which
399 ;; argument positions are type specified. Treat T specially
400 ;; in the usual sort of way. For efficiency don't bother to
401 ;; keep specialized-argument-positions sorted, rather depend
402 ;; on our caller to do that.
403 (iterate ((type-spec (list-elements (method-specializers method)))
404 (pos (interval :from 0)))
405 (unless (eq type-spec *the-class-t*)
406 (pushnew pos specialized-argument-positions)))
407 ;; Finally merge the values for this method into the values
408 ;; for the exisiting methods and return them. Note that if
409 ;; num-of-requireds is NIL it means this is the first method
410 ;; and we depend on that.
411 (values (min (or number-of-requireds requireds) requireds)
413 (and number-of-requireds (/= number-of-requireds requireds)))
414 specialized-argument-positions)))
416 (defun make-discriminating-function-arglist (number-required-arguments restp)
417 (nconc (gathering ((args (collecting)))
418 (iterate ((i (interval :from 0 :below number-required-arguments)))
419 (gather (intern (format nil "Discriminating Function Arg ~D" i))
422 `(&rest ,(intern "Discriminating Function &rest Arg")))))
424 (defmethod generic-function-lambda-list ((gf generic-function))
427 (defmethod gf-fast-method-function-p ((gf standard-generic-function))
428 (gf-info-fast-mf-p (slot-value gf 'arg-info)))
430 (defmethod initialize-instance :after ((gf standard-generic-function)
431 &key (lambda-list nil lambda-list-p)
432 argument-precedence-order)
433 (with-slots (arg-info)
437 :lambda-list lambda-list
438 :argument-precedence-order argument-precedence-order)
440 (when (arg-info-valid-p arg-info)
443 (defmethod reinitialize-instance :after ((gf standard-generic-function)
445 &key (lambda-list nil lambda-list-p)
446 (argument-precedence-order
447 nil argument-precedence-order-p))
448 (with-slots (arg-info)
451 (if argument-precedence-order-p
453 :lambda-list lambda-list
454 :argument-precedence-order argument-precedence-order)
456 :lambda-list lambda-list))
458 (when (and (arg-info-valid-p arg-info)
460 (or lambda-list-p (cddr args)))
463 (declaim (special *lazy-dfun-compute-p*))
465 (defun set-methods (gf methods)
466 (setf (generic-function-methods gf) nil)
467 (loop (when (null methods) (return gf))
468 (real-add-method gf (pop methods) methods)))
470 (defun real-add-method (generic-function method &optional skip-dfun-update-p)
471 (if (method-generic-function method)
472 (error "The method ~S is already part of the generic~@
473 function ~S. It can't be added to another generic~@
474 function until it is removed from the first one."
475 method (method-generic-function method))
477 (let* ((name (generic-function-name generic-function))
478 (qualifiers (method-qualifiers method))
479 (specializers (method-specializers method))
480 (existing (get-method generic-function
485 ;; If there is already a method like this one then we must
486 ;; get rid of it before proceeding. Note that we call the
487 ;; generic function remove-method to remove it rather than
488 ;; doing it in some internal way.
489 (when existing (remove-method generic-function existing))
491 (setf (method-generic-function method) generic-function)
492 (pushnew method (generic-function-methods generic-function))
493 (dolist (specializer specializers)
494 (add-direct-method specializer method))
495 (set-arg-info generic-function :new-method method)
496 (unless skip-dfun-update-p
498 '(make-instance default-initargs
499 allocate-instance shared-initialize
500 initialize-instance))
501 (update-make-instance-function-table (type-class
502 (car specializers))))
503 (update-dfun generic-function))
506 (defun real-remove-method (generic-function method)
507 ;; Note: Error check prohibited by ANSI spec removed.
508 (when (eq generic-function (method-generic-function method))
509 (let* ((name (generic-function-name generic-function))
510 (specializers (method-specializers method))
511 (methods (generic-function-methods generic-function))
512 (new-methods (remove method methods)))
513 (setf (method-generic-function method) nil)
514 (setf (generic-function-methods generic-function) new-methods)
515 (dolist (specializer (method-specializers method))
516 (remove-direct-method specializer method))
517 (set-arg-info generic-function)
521 allocate-instance shared-initialize initialize-instance))
522 (update-make-instance-function-table (type-class (car specializers))))
523 (update-dfun generic-function)
526 (defun compute-applicable-methods-function (generic-function arguments)
527 (values (compute-applicable-methods-using-types
529 (types-from-arguments generic-function arguments 'eql))))
531 (defmethod compute-applicable-methods
532 ((generic-function generic-function) arguments)
533 (values (compute-applicable-methods-using-types
535 (types-from-arguments generic-function arguments 'eql))))
537 (defmethod compute-applicable-methods-using-classes
538 ((generic-function generic-function) classes)
539 (compute-applicable-methods-using-types
541 (types-from-arguments generic-function classes 'class-eq)))
543 (defun proclaim-incompatible-superclasses (classes)
544 (setq classes (mapcar #'(lambda (class)
549 (dolist (class classes)
550 (dolist (other-class classes)
551 (unless (eq class other-class)
552 (pushnew other-class (class-incompatible-superclass-list class))))))
554 (defun superclasses-compatible-p (class1 class2)
555 (let ((cpl1 (class-precedence-list class1))
556 (cpl2 (class-precedence-list class2)))
558 (dolist (ic (class-incompatible-superclass-list sc1))
560 (return-from superclasses-compatible-p nil))))))
563 #'proclaim-incompatible-superclasses
564 '(;; superclass class
565 (built-in-class std-class structure-class) ; direct subclasses of pcl-class
566 (standard-class funcallable-standard-class)
567 ;; superclass metaobject
568 (class eql-specializer class-eq-specializer method method-combination
569 generic-function slot-definition)
570 ;; metaclass built-in-class
571 (number sequence character ; direct subclasses of t, but not array
572 standard-object structure-object) ; or symbol
573 (number array character symbol ; direct subclasses of t, but not
574 standard-object structure-object) ; sequence
575 (complex float rational) ; direct subclasses of number
576 (integer ratio) ; direct subclasses of rational
577 (list vector) ; direct subclasses of sequence
578 (cons null) ; direct subclasses of list
579 (string bit-vector) ; direct subclasses of vector
582 (defmethod same-specializer-p ((specl1 specializer) (specl2 specializer))
585 (defmethod same-specializer-p ((specl1 class) (specl2 class))
588 (defmethod specializer-class ((specializer class))
591 (defmethod same-specializer-p ((specl1 class-eq-specializer)
592 (specl2 class-eq-specializer))
593 (eq (specializer-class specl1) (specializer-class specl2)))
595 (defmethod same-specializer-p ((specl1 eql-specializer)
596 (specl2 eql-specializer))
597 (eq (specializer-object specl1) (specializer-object specl2)))
599 (defmethod specializer-class ((specializer eql-specializer))
600 (class-of (slot-value specializer 'object)))
602 (defvar *in-gf-arg-info-p* nil)
603 (setf (gdefinition 'arg-info-reader)
604 (let ((mf (initialize-method-function
605 (make-internal-reader-method-function
606 'standard-generic-function 'arg-info)
608 #'(lambda (&rest args) (funcall mf args nil))))
610 (defun types-from-arguments (generic-function arguments
611 &optional type-modifier)
612 (multiple-value-bind (nreq applyp metatypes nkeys arg-info)
613 (get-generic-function-info generic-function)
614 (declare (ignore applyp metatypes nkeys))
615 (let ((types-rev nil))
616 (dotimes-fixnum (i nreq)
619 (error "The function ~S requires at least ~D arguments"
620 (generic-function-name generic-function)
622 (let ((arg (pop arguments)))
623 (push (if type-modifier `(,type-modifier ,arg) arg) types-rev)))
624 (values (nreverse types-rev) arg-info))))
626 (defun get-wrappers-from-classes (nkeys wrappers classes metatypes)
627 (let* ((w wrappers) (w-tail w) (mt-tail metatypes))
628 (dolist (class (if (listp classes) classes (list classes)))
629 (unless (eq 't (car mt-tail))
630 (let ((c-w (class-wrapper class)))
631 (unless c-w (return-from get-wrappers-from-classes nil))
634 (setf (car w-tail) c-w
635 w-tail (cdr w-tail)))))
636 (setq mt-tail (cdr mt-tail)))
639 (defun sdfun-for-caching (gf classes)
640 (let ((types (mapcar #'class-eq-type classes)))
641 (multiple-value-bind (methods all-applicable-and-sorted-p)
642 (compute-applicable-methods-using-types gf types)
643 (function-funcall (get-secondary-dispatch-function1
644 gf methods types nil t all-applicable-and-sorted-p)
645 nil (mapcar #'class-wrapper classes)))))
647 (defun value-for-caching (gf classes)
648 (let ((methods (compute-applicable-methods-using-types
649 gf (mapcar #'class-eq-type classes))))
650 (method-function-get (or (method-fast-function (car methods))
651 (method-function (car methods)))
654 (defun default-secondary-dispatch-function (generic-function)
655 #'(lambda (&rest args)
656 (let ((methods (compute-applicable-methods generic-function args)))
658 (let ((emf (get-effective-method-function generic-function
660 (invoke-emf emf args))
661 (apply #'no-applicable-method generic-function args)))))
664 (loop (when (atom x) (return (eq x y)))
665 (when (atom y) (return nil))
666 (unless (eq (car x) (car y)) (return nil))
667 (setq x (cdr x) y (cdr y))))
669 (defvar *std-cam-methods* nil)
671 (defun compute-applicable-methods-emf (generic-function)
672 (if (eq *boot-state* 'complete)
673 (let* ((cam (gdefinition 'compute-applicable-methods))
674 (cam-methods (compute-applicable-methods-using-types
675 cam (list `(eql ,generic-function) t))))
676 (values (get-effective-method-function cam cam-methods)
678 (or *std-cam-methods*
679 (setq *std-cam-methods*
680 (compute-applicable-methods-using-types
681 cam (list `(eql ,cam) t)))))))
682 (values #'compute-applicable-methods-function t)))
684 (defun compute-applicable-methods-emf-std-p (gf)
685 (gf-info-c-a-m-emf-std-p (gf-arg-info gf)))
687 (defvar *old-c-a-m-gf-methods* nil)
689 (defun update-all-c-a-m-gf-info (c-a-m-gf)
690 (let ((methods (generic-function-methods c-a-m-gf)))
691 (if (and *old-c-a-m-gf-methods*
692 (every #'(lambda (old-method)
693 (member old-method methods))
694 *old-c-a-m-gf-methods*))
695 (let ((gfs-to-do nil)
696 (gf-classes-to-do nil))
697 (dolist (method methods)
698 (unless (member method *old-c-a-m-gf-methods*)
699 (let ((specl (car (method-specializers method))))
700 (if (eql-specializer-p specl)
701 (pushnew (specializer-object specl) gfs-to-do)
702 (pushnew (specializer-class specl) gf-classes-to-do)))))
703 (map-all-generic-functions
705 (when (or (member gf gfs-to-do)
706 (dolist (class gf-classes-to-do nil)
708 (class-precedence-list (class-of gf)))))
709 (update-c-a-m-gf-info gf)))))
710 (map-all-generic-functions #'update-c-a-m-gf-info))
711 (setq *old-c-a-m-gf-methods* methods)))
713 (defun update-gf-info (gf)
714 (update-c-a-m-gf-info gf)
715 (update-gf-simple-accessor-type gf))
717 (defun update-c-a-m-gf-info (gf)
718 (unless (early-gf-p gf)
719 (multiple-value-bind (c-a-m-emf std-p)
720 (compute-applicable-methods-emf gf)
721 (let ((arg-info (gf-arg-info gf)))
722 (setf (gf-info-static-c-a-m-emf arg-info) c-a-m-emf)
723 (setf (gf-info-c-a-m-emf-std-p arg-info) std-p)))))
725 (defun update-gf-simple-accessor-type (gf)
726 (let ((arg-info (gf-arg-info gf)))
727 (setf (gf-info-simple-accessor-type arg-info)
728 (let* ((methods (generic-function-methods gf))
729 (class (and methods (class-of (car methods))))
732 *the-class-standard-reader-method*)
735 *the-class-standard-writer-method*)
738 *the-class-standard-boundp-method*)
740 (when (and (gf-info-c-a-m-emf-std-p arg-info)
742 (dolist (method (cdr methods) t)
743 (unless (eq class (class-of method)) (return nil)))
744 (eq (generic-function-method-combination gf)
745 *standard-method-combination*))
748 (defun get-accessor-method-function (gf type class slotd)
749 (let* ((std-method (standard-svuc-method type))
750 (str-method (structure-svuc-method type))
751 (types1 `((eql ,class) (class-eq ,class) (eql ,slotd)))
752 (types (if (eq type 'writer) `(t ,@types1) types1))
753 (methods (compute-applicable-methods-using-types gf types))
754 (std-p (null (cdr methods))))
757 (get-optimized-std-accessor-method-function class slotd type)
758 (get-accessor-from-svuc-method-function
760 (get-secondary-dispatch-function
762 `((,(car (or (member std-method methods)
763 (member str-method methods)
764 (error "error in get-accessor-method-function")))
765 ,(get-optimized-std-slot-value-using-class-method-function
767 (unless (and (eq type 'writer)
768 (dolist (method methods t)
769 (unless (eq (car (method-specializers method))
772 (let ((wrappers (list (wrapper-of class)
773 (class-wrapper class)
774 (wrapper-of slotd))))
775 (if (eq type 'writer)
776 (cons (class-wrapper *the-class-t*) wrappers)
781 ;;; used by OPTIMIZE-SLOT-VALUE-BY-CLASS-P (vector.lisp)
782 (defun update-slot-value-gf-info (gf type)
784 (update-std-or-str-methods gf type))
785 (when (and (standard-svuc-method type) (structure-svuc-method type))
786 (flet ((update-class (class)
787 (when (class-finalized-p class)
788 (dolist (slotd (class-slots class))
789 (compute-slot-accessor-info slotd type gf)))))
791 (update-class *new-class*)
792 (map-all-classes #'update-class 'slot-object)))))
794 (defvar *standard-slot-value-using-class-method* nil)
795 (defvar *standard-setf-slot-value-using-class-method* nil)
796 (defvar *standard-slot-boundp-using-class-method* nil)
797 (defvar *structure-slot-value-using-class-method* nil)
798 (defvar *structure-setf-slot-value-using-class-method* nil)
799 (defvar *structure-slot-boundp-using-class-method* nil)
801 (defun standard-svuc-method (type)
803 (reader *standard-slot-value-using-class-method*)
804 (writer *standard-setf-slot-value-using-class-method*)
805 (boundp *standard-slot-boundp-using-class-method*)))
807 (defun set-standard-svuc-method (type method)
809 (reader (setq *standard-slot-value-using-class-method* method))
810 (writer (setq *standard-setf-slot-value-using-class-method* method))
811 (boundp (setq *standard-slot-boundp-using-class-method* method))))
813 (defun structure-svuc-method (type)
815 (reader *structure-slot-value-using-class-method*)
816 (writer *structure-setf-slot-value-using-class-method*)
817 (boundp *structure-slot-boundp-using-class-method*)))
819 (defun set-structure-svuc-method (type method)
821 (reader (setq *structure-slot-value-using-class-method* method))
822 (writer (setq *structure-setf-slot-value-using-class-method* method))
823 (boundp (setq *structure-slot-boundp-using-class-method* method))))
825 (defun update-std-or-str-methods (gf type)
826 (dolist (method (generic-function-methods gf))
827 (let ((specls (method-specializers method)))
828 (when (and (or (not (eq type 'writer))
829 (eq (pop specls) *the-class-t*))
830 (every #'classp specls))
831 (cond ((and (eq (class-name (car specls))
833 (eq (class-name (cadr specls))
835 (eq (class-name (caddr specls))
836 'standard-effective-slot-definition))
837 (set-standard-svuc-method type method))
838 ((and (eq (class-name (car specls))
840 (eq (class-name (cadr specls))
842 (eq (class-name (caddr specls))
843 'structure-effective-slot-definition))
844 (set-structure-svuc-method type method)))))))
846 (defun mec-all-classes-internal (spec precompute-p)
847 (cons (specializer-class spec)
850 (not (or (eq spec *the-class-t*)
851 (eq spec *the-class-slot-object*)
852 (eq spec *the-class-std-object*)
853 (eq spec *the-class-standard-object*)
854 (eq spec *the-class-structure-object*)))
855 (let ((sc (class-direct-subclasses spec)))
857 (mapcan #'(lambda (class)
858 (mec-all-classes-internal class precompute-p))
861 (defun mec-all-classes (spec precompute-p)
862 (let ((classes (mec-all-classes-internal spec precompute-p)))
863 (if (null (cdr classes))
865 (let* ((a-classes (cons nil classes))
867 (loop (when (null (cdr tail))
868 (return (cdr a-classes)))
869 (let ((class (cadr tail))
871 (if (dolist (c ttail nil)
872 (when (eq class c) (return t)))
873 (setf (cdr tail) (cddr tail))
874 (setf tail (cdr tail)))))))))
876 (defun mec-all-class-lists (spec-list precompute-p)
879 (let* ((car-all-classes (mec-all-classes (car spec-list)
881 (all-class-lists (mec-all-class-lists (cdr spec-list)
883 (mapcan #'(lambda (list)
884 (mapcar #'(lambda (c) (cons c list)) car-all-classes))
887 (defun make-emf-cache (generic-function valuep cache classes-list new-class)
888 (let* ((arg-info (gf-arg-info generic-function))
889 (nkeys (arg-info-nkeys arg-info))
890 (metatypes (arg-info-metatypes arg-info))
891 (wrappers (unless (eq nkeys 1) (make-list nkeys)))
892 (precompute-p (gf-precompute-dfun-and-emf-p arg-info))
893 (default '(default)))
894 (flet ((add-class-list (classes)
895 (when (or (null new-class) (memq new-class classes))
896 (let ((wrappers (get-wrappers-from-classes
897 nkeys wrappers classes metatypes)))
899 (eq default (probe-cache cache wrappers default)))
900 (let ((value (cond ((eq valuep t)
901 (sdfun-for-caching generic-function
903 ((eq valuep :constant-value)
904 (value-for-caching generic-function
906 (setq cache (fill-cache cache wrappers value t))))))))
908 (mapc #'add-class-list classes-list)
909 (dolist (method (generic-function-methods generic-function))
910 (mapc #'add-class-list
911 (mec-all-class-lists (method-specializers method)
915 (defmacro class-test (arg class)
916 (cond ((eq class *the-class-t*)
918 ((eq class *the-class-slot-object*)
919 `(not (cl:typep (cl:class-of ,arg) 'cl:built-in-class)))
920 ((eq class *the-class-std-object*)
921 `(or (std-instance-p ,arg) (fsc-instance-p ,arg)))
922 ((eq class *the-class-standard-object*)
923 `(std-instance-p ,arg))
924 ((eq class *the-class-funcallable-standard-object*)
925 `(fsc-instance-p ,arg))
927 `(typep ,arg ',(class-name class)))))
929 (defmacro class-eq-test (arg class)
930 `(eq (class-of ,arg) ',class))
932 (defmacro eql-test (arg object)
933 `(eql ,arg ',object))
935 (defun dnet-methods-p (form)
937 (or (eq (car form) 'methods)
938 (eq (car form) 'unordered-methods))))
940 ;;; This is CASE, but without gensyms.
941 (defmacro scase (arg &rest clauses)
942 `(let ((.case-arg. ,arg))
943 (cond ,@(mapcar #'(lambda (clause)
944 (list* (cond ((null (car clause))
946 ((consp (car clause))
947 (if (null (cdar clause))
952 ((member (car clause) '(t otherwise))
955 `(eql .case-arg. ',(car clause))))
960 (defmacro mcase (arg &rest clauses) `(scase ,arg ,@clauses))
962 (defun generate-discrimination-net (generic-function methods types sorted-p)
963 (let* ((arg-info (gf-arg-info generic-function))
964 (precedence (arg-info-precedence arg-info)))
965 (generate-discrimination-net-internal
966 generic-function methods types
967 #'(lambda (methods known-types)
970 (let ((sorted-methods nil))
972 (copy-list methods) precedence
974 (when sorted-methods (return-from one-order-p nil))
975 (setq sorted-methods methods)))
976 (setq methods sorted-methods))
978 `(methods ,methods ,known-types)
979 `(unordered-methods ,methods ,known-types)))
980 #'(lambda (position type true-value false-value)
981 (let ((arg (dfun-arg-symbol position)))
982 (if (eq (car type) 'eql)
983 (let* ((false-case-p (and (consp false-value)
984 (or (eq (car false-value) 'scase)
985 (eq (car false-value) 'mcase))
986 (eq arg (cadr false-value))))
987 (false-clauses (if false-case-p
989 `((t ,false-value))))
990 (case-sym (if (and (dnet-methods-p true-value)
992 (eq (car false-value) 'mcase)
993 (dnet-methods-p false-value)))
996 (type-sym `(,(cadr type))))
998 (,type-sym ,true-value)
1000 `(if ,(let ((arg (dfun-arg-symbol position)))
1002 (class `(class-test ,arg ,(cadr type)))
1003 (class-eq `(class-eq-test ,arg ,(cadr type)))))
1008 (defun class-from-type (type)
1009 (if (or (atom type) (eq (car type) 't))
1012 (and (dolist (type (cdr type) *the-class-t*)
1013 (when (and (consp type) (not (eq (car type) 'not)))
1014 (return (class-from-type type)))))
1016 (eql (class-of (cadr type)))
1017 (class-eq (cadr type))
1018 (class (cadr type)))))
1020 (defun precompute-effective-methods (gf caching-p &optional classes-list-p)
1021 (let* ((arg-info (gf-arg-info gf))
1022 (methods (generic-function-methods gf))
1023 (precedence (arg-info-precedence arg-info))
1024 (*in-precompute-effective-methods-p* t)
1026 (generate-discrimination-net-internal
1028 #'(lambda (methods known-types)
1030 (when classes-list-p
1031 (push (mapcar #'class-from-type known-types) classes-list))
1032 (let ((no-eql-specls-p (not (methods-contain-eql-specializer-p
1037 (get-secondary-dispatch-function1
1038 gf methods known-types
1039 nil caching-p no-eql-specls-p))))))
1040 #'(lambda (position type true-value false-value)
1041 (declare (ignore position type true-value false-value))
1044 (if (and (consp type) (eq (car type) 'eql))
1045 `(class-eq ,(class-of (cadr type)))
1049 ;;; We know that known-type implies neither new-type nor `(not ,new-type).
1050 (defun augment-type (new-type known-type)
1051 (if (or (eq known-type 't)
1052 (eq (car new-type) 'eql))
1054 (let ((so-far (if (and (consp known-type) (eq (car known-type) 'and))
1056 (list known-type))))
1057 (unless (eq (car new-type) 'not)
1059 (mapcan #'(lambda (type)
1060 (unless (*subtypep new-type type)
1065 `(and ,new-type ,@so-far)))))
1067 (defun generate-discrimination-net-internal
1068 (gf methods types methods-function test-function type-function)
1069 (let* ((arg-info (gf-arg-info gf))
1070 (precedence (arg-info-precedence arg-info))
1071 (nreq (arg-info-number-required arg-info))
1072 (metatypes (arg-info-metatypes arg-info)))
1073 (labels ((do-column (p-tail contenders known-types)
1075 (let* ((position (car p-tail))
1076 (known-type (or (nth position types) t)))
1077 (if (eq (nth position metatypes) 't)
1078 (do-column (cdr p-tail) contenders
1079 (cons (cons position known-type)
1081 (do-methods p-tail contenders
1082 known-type () known-types)))
1083 (funcall methods-function contenders
1084 (let ((k-t (make-list nreq)))
1085 (dolist (index+type known-types)
1086 (setf (nth (car index+type) k-t)
1089 (do-methods (p-tail contenders known-type winners known-types)
1091 ;; is a (sorted) list of methods that must be discriminated.
1093 ;; is the type of this argument, constructed from tests
1096 ;; is a (sorted) list of methods that are potentially
1097 ;; applicable after the discrimination has been made.
1098 (if (null contenders)
1099 (do-column (cdr p-tail)
1101 (cons (cons (car p-tail) known-type)
1103 (let* ((position (car p-tail))
1104 (method (car contenders))
1105 (specl (nth position (method-specializers method)))
1106 (type (funcall type-function
1107 (type-from-specializer specl))))
1108 (multiple-value-bind (app-p maybe-app-p)
1109 (specializer-applicable-using-type-p type known-type)
1110 (flet ((determined-to-be (truth-value)
1111 (if truth-value app-p (not maybe-app-p)))
1112 (do-if (truth &optional implied)
1113 (let ((ntype (if truth type `(not ,type))))
1118 (augment-type ntype known-type))
1120 (append winners `(,method))
1123 (cond ((determined-to-be nil) (do-if nil t))
1124 ((determined-to-be t) (do-if t t))
1125 (t (funcall test-function position type
1126 (do-if t) (do-if nil))))))))))
1127 (do-column precedence methods ()))))
1129 (defun compute-secondary-dispatch-function (generic-function net &optional
1130 method-alist wrappers)
1131 (function-funcall (compute-secondary-dispatch-function1 generic-function net)
1132 method-alist wrappers))
1134 (defvar *eq-case-table-limit* 15)
1135 (defvar *case-table-limit* 10)
1137 (defun compute-mcase-parameters (case-list)
1138 (unless (eq 't (caar (last case-list)))
1139 (error "The key for the last case arg to mcase was not T"))
1140 (let* ((eq-p (dolist (case case-list t)
1141 (unless (or (eq (car case) 't)
1142 (symbolp (caar case)))
1144 (len (1- (length case-list)))
1145 (type (cond ((= len 1)
1149 *eq-case-table-limit*
1150 *case-table-limit*))
1156 (defmacro mlookup (key info default &optional eq-p type)
1157 (unless (or (eq eq-p 't) (null eq-p))
1158 (error "Invalid eq-p argument"))
1161 `(if (,(if eq-p 'eq 'eql) ,key (car ,info))
1165 `(dolist (e ,info ,default)
1166 (when (,(if eq-p 'eq 'eql) (car e) ,key)
1169 `(gethash ,key ,info ,default))))
1171 (defun net-test-converter (form)
1173 (default-test-converter form)
1175 ((invoke-effective-method-function invoke-fast-method-call)
1182 `(mlookup ,(cadr form)
1185 ,@(compute-mcase-parameters (cddr form))))
1186 (t (default-test-converter form)))))
1188 (defun net-code-converter (form)
1190 (default-code-converter form)
1192 ((methods unordered-methods)
1193 (let ((gensym (gensym)))
1197 (let ((mp (compute-mcase-parameters (cddr form)))
1198 (gensym (gensym)) (default (gensym)))
1199 (values `(mlookup ,(cadr form) ,gensym ,default ,@mp)
1200 (list gensym default))))
1202 (default-code-converter form)))))
1204 (defun net-constant-converter (form generic-function)
1205 (or (let ((c (methods-converter form generic-function)))
1208 (default-constant-converter form)
1211 (let* ((mp (compute-mcase-parameters (cddr form)))
1212 (list (mapcar #'(lambda (clause)
1213 (let ((key (car clause))
1214 (meth (cadr clause)))
1215 (cons (if (consp key) (car key) key)
1217 meth generic-function))))
1219 (default (car (last list))))
1220 (list (list* ':mcase mp (nbutlast list))
1223 (default-constant-converter form))))))
1225 (defun methods-converter (form generic-function)
1226 (cond ((and (consp form) (eq (car form) 'methods))
1228 (get-effective-method-function1 generic-function (cadr form))))
1229 ((and (consp form) (eq (car form) 'unordered-methods))
1230 (default-secondary-dispatch-function generic-function))))
1232 (defun convert-methods (constant method-alist wrappers)
1233 (if (and (consp constant)
1234 (eq (car constant) '.methods.))
1235 (funcall (cdr constant) method-alist wrappers)
1238 (defun convert-table (constant method-alist wrappers)
1239 (cond ((and (consp constant)
1240 (eq (car constant) ':mcase))
1241 (let ((alist (mapcar #'(lambda (k+m)
1243 (convert-methods (cdr k+m)
1247 (mp (cadr constant)))
1254 (let ((table (make-hash-table :test (if (car mp) 'eq 'eql))))
1256 (setf (gethash (car k+m) table) (cdr k+m)))
1259 (defun compute-secondary-dispatch-function1 (generic-function net
1260 &optional function-p)
1262 ((and (eq (car net) 'methods) (not function-p))
1263 (get-effective-method-function1 generic-function (cadr net)))
1265 (let* ((name (generic-function-name generic-function))
1266 (arg-info (gf-arg-info generic-function))
1267 (metatypes (arg-info-metatypes arg-info))
1268 (applyp (arg-info-applyp arg-info))
1269 (fmc-arg-info (cons (length metatypes) applyp))
1270 (arglist (if function-p
1271 (make-dfun-lambda-list metatypes applyp)
1272 (make-fast-method-call-lambda-list metatypes applyp))))
1273 (multiple-value-bind (cfunction constants)
1274 (get-function1 `(,(if function-p
1275 'sb-kernel:instance-lambda
1278 ,@(unless function-p
1279 `((declare (ignore .pv-cell.
1280 .next-method-call.))))
1281 (locally (declare #.*optimize-speed*)
1283 ,(make-emf-call metatypes applyp 'emf))))
1284 #'net-test-converter
1285 #'net-code-converter
1287 (net-constant-converter form generic-function)))
1288 #'(lambda (method-alist wrappers)
1289 (let* ((alist (list nil))
1291 (dolist (constant constants)
1292 (let* ((a (or (dolist (a alist nil)
1293 (when (eq (car a) constant)
1297 constant method-alist wrappers)
1299 constant method-alist wrappers)))))
1301 (setf (cdr alist-tail) new)
1302 (setf alist-tail new)))
1303 (let ((function (apply cfunction (mapcar #'cdr (cdr alist)))))
1306 (make-fast-method-call
1307 :function (set-function-name function
1308 `(sdfun-method ,name))
1309 :arg-info fmc-arg-info))))))))))
1311 (defvar *show-make-unordered-methods-emf-calls* nil)
1313 (defun make-unordered-methods-emf (generic-function methods)
1314 (when *show-make-unordered-methods-emf-calls*
1315 (format t "~&make-unordered-methods-emf ~S~%"
1316 (generic-function-name generic-function)))
1317 #'(lambda (&rest args)
1318 (let* ((types (types-from-arguments generic-function args 'eql))
1319 (smethods (sort-applicable-methods generic-function
1322 (emf (get-effective-method-function generic-function smethods)))
1323 (invoke-emf emf args))))
1325 ;;; The value returned by compute-discriminating-function is a function
1326 ;;; object. It is called a discriminating function because it is called
1327 ;;; when the generic function is called and its role is to discriminate
1328 ;;; on the arguments to the generic function and then call appropriate
1329 ;;; method functions.
1331 ;;; A discriminating function can only be called when it is installed as
1332 ;;; the funcallable instance function of the generic function for which
1333 ;;; it was computed.
1335 ;;; More precisely, if compute-discriminating-function is called with an
1336 ;;; argument <gf1>, and returns a result <df1>, that result must not be
1337 ;;; passed to apply or funcall directly. Rather, <df1> must be stored as
1338 ;;; the funcallable instance function of the same generic function <gf1>
1339 ;;; (using set-funcallable-instance-function). Then the generic function
1340 ;;; can be passed to funcall or apply.
1342 ;;; An important exception is that methods on this generic function are
1343 ;;; permitted to return a function which itself ends up calling the value
1344 ;;; returned by a more specific method. This kind of `encapsulation' of
1345 ;;; discriminating function is critical to many uses of the MOP.
1347 ;;; As an example, the following canonical case is legal:
1349 ;;; (defmethod compute-discriminating-function ((gf my-generic-function))
1350 ;;; (let ((std (call-next-method)))
1352 ;;; (print (list 'call-to-gf gf arg))
1353 ;;; (funcall std arg))))
1355 ;;; Because many discriminating functions would like to use a dynamic
1356 ;;; strategy in which the precise discriminating function changes with
1357 ;;; time it is important to specify how a discriminating function is
1358 ;;; permitted itself to change the funcallable instance function of the
1359 ;;; generic function.
1361 ;;; Discriminating functions may set the funcallable instance function
1362 ;;; of the generic function, but the new value must be generated by making
1363 ;;; a call to COMPUTE-DISCRIMINATING-FUNCTION. This is to ensure that any
1364 ;;; more specific methods which may have encapsulated the discriminating
1365 ;;; function will get a chance to encapsulate the new, inner discriminating
1368 ;;; This implies that if a discriminating function wants to modify itself
1369 ;;; it should first store some information in the generic function proper,
1370 ;;; and then call compute-discriminating-function. The appropriate method
1371 ;;; on compute-discriminating-function will see the information stored in
1372 ;;; the generic function and generate a discriminating function accordingly.
1374 ;;; The following is an example of a discriminating function which modifies
1375 ;;; itself in accordance with this protocol:
1377 ;;; (defmethod compute-discriminating-function ((gf my-generic-function))
1379 ;;; (cond (<some condition>
1380 ;;; <store some info in the generic function>
1381 ;;; (set-funcallable-instance-function
1383 ;;; (compute-discriminating-function gf))
1384 ;;; (funcall gf arg))
1386 ;;; <call-a-method-of-gf>))))
1388 ;;; Whereas this code would not be legal:
1390 ;;; (defmethod compute-discriminating-function ((gf my-generic-function))
1392 ;;; (cond (<some condition>
1393 ;;; (set-funcallable-instance-function
1395 ;;; #'(lambda (a) ..))
1396 ;;; (funcall gf arg))
1398 ;;; <call-a-method-of-gf>))))
1400 ;;; NOTE: All the examples above assume that all instances of the class
1401 ;;; my-generic-function accept only one argument.
1403 (defun slot-value-using-class-dfun (class object slotd)
1404 (declare (ignore class))
1405 (function-funcall (slot-definition-reader-function slotd) object))
1407 (defun setf-slot-value-using-class-dfun (new-value class object slotd)
1408 (declare (ignore class))
1409 (function-funcall (slot-definition-writer-function slotd) new-value object))
1411 (defun slot-boundp-using-class-dfun (class object slotd)
1412 (declare (ignore class))
1413 (function-funcall (slot-definition-boundp-function slotd) object))
1415 (defmethod compute-discriminating-function ((gf standard-generic-function))
1416 (with-slots (dfun-state arg-info) gf
1417 (typecase dfun-state
1418 (null (let ((name (generic-function-name gf)))
1419 (when (eq name 'compute-applicable-methods)
1420 (update-all-c-a-m-gf-info gf))
1421 (cond ((eq name 'slot-value-using-class)
1422 (update-slot-value-gf-info gf 'reader)
1423 #'slot-value-using-class-dfun)
1424 ((equal name '(setf slot-value-using-class))
1425 (update-slot-value-gf-info gf 'writer)
1426 #'setf-slot-value-using-class-dfun)
1427 ((eq name 'slot-boundp-using-class)
1428 (update-slot-value-gf-info gf 'boundp)
1429 #'slot-boundp-using-class-dfun)
1430 ((gf-precompute-dfun-and-emf-p arg-info)
1431 (make-final-dfun gf))
1433 (make-initial-dfun gf)))))
1434 (function dfun-state)
1435 (cons (car dfun-state)))))
1437 (defmethod update-gf-dfun ((class std-class) gf)
1438 (let ((*new-class* class)
1439 #|| (name (generic-function-name gf)) ||#
1440 (arg-info (gf-arg-info gf)))
1442 ((eq name 'slot-value-using-class)
1443 (update-slot-value-gf-info gf 'reader))
1444 ((equal name '(setf slot-value-using-class))
1445 (update-slot-value-gf-info gf 'writer))
1446 ((eq name 'slot-boundp-using-class)
1447 (update-slot-value-gf-info gf 'boundp))
1449 ((gf-precompute-dfun-and-emf-p arg-info)
1450 (multiple-value-bind (dfun cache info)
1451 (make-final-dfun-internal gf)
1452 (set-dfun gf dfun cache info) ; lest the cache be freed twice
1453 (update-dfun gf dfun cache info))))))
1455 (defmethod function-keywords ((method standard-method))
1456 (multiple-value-bind (nreq nopt keysp restp allow-other-keys-p keywords)
1457 (analyze-lambda-list (if (consp method)
1458 (early-method-lambda-list method)
1459 (method-lambda-list method)))
1460 (declare (ignore nreq nopt keysp restp))
1461 (values keywords allow-other-keys-p)))
1463 (defun method-ll->generic-function-ll (ll)
1464 (multiple-value-bind
1465 (nreq nopt keysp restp allow-other-keys-p keywords keyword-parameters)
1466 (analyze-lambda-list ll)
1467 (declare (ignore nreq nopt keysp restp allow-other-keys-p keywords))
1468 (remove-if #'(lambda (s)
1469 (or (memq s keyword-parameters)
1470 (eq s '&allow-other-keys)))
1473 ;;; This is based on the rules of method lambda list congruency defined in
1474 ;;; the spec. The lambda list it constructs is the pretty union of the
1475 ;;; lambda lists of all the methods. It doesn't take method applicability
1476 ;;; into account at all yet.
1477 (defmethod generic-function-pretty-arglist
1478 ((generic-function standard-generic-function))
1479 (let ((methods (generic-function-methods generic-function))
1482 (multiple-value-bind (required optional rest key allow-other-keys)
1483 (method-pretty-arglist (car methods))
1484 (dolist (m (cdr methods))
1485 (multiple-value-bind (method-key-keywords
1486 method-allow-other-keys
1488 (function-keywords m)
1489 ;; we've modified function-keywords to return what we want as
1490 ;; the third value, no other change here.
1491 (declare (ignore method-key-keywords))
1492 (setq key (union key method-key))
1493 (setq allow-other-keys (or allow-other-keys
1494 method-allow-other-keys))))
1495 (when allow-other-keys
1496 (setq arglist '(&allow-other-keys)))
1498 (setq arglist (nconc (list '&key) key arglist)))
1500 (setq arglist (nconc (list '&rest rest) arglist)))
1502 (setq arglist (nconc (list '&optional) optional arglist)))
1503 (nconc required arglist)))))
1505 (defmethod method-pretty-arglist ((method standard-method))
1510 (allow-other-keys nil)
1512 (arglist (method-lambda-list method)))
1513 (dolist (arg arglist)
1514 (cond ((eq arg '&optional) (setq state 'optional))
1515 ((eq arg '&rest) (setq state 'rest))
1516 ((eq arg '&key) (setq state 'key))
1517 ((eq arg '&allow-other-keys) (setq allow-other-keys 't))
1518 ((memq arg lambda-list-keywords))
1521 (required (push arg required))
1522 (optional (push arg optional))
1523 (key (push arg key))
1524 (rest (setq rest arg))))))
1525 (values (nreverse required)