| 1 |
;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil; Package: CLOS -*- |
| 2 |
;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab: |
| 3 |
|
| 4 |
;;;; |
| 5 |
;;;; Copyright (c) 1992, Giuseppe Attardi. |
| 6 |
;;;; Copyright (c) 2001, Juan Jose Garcia Ripoll. |
| 7 |
;;;; |
| 8 |
;;;; See file 'LICENSE' for the copyright details. |
| 9 |
|
| 10 |
(in-package "CLOS") |
| 11 |
|
| 12 |
;;;---------------------------------------------------------------------- |
| 13 |
;;; Method |
| 14 |
;;; ---------------------------------------------------------------------- |
| 15 |
|
| 16 |
(defmethod function-keywords ((method standard-method)) |
| 17 |
(multiple-value-bind (reqs opts rest-var key-flag keywords) |
| 18 |
(si::process-lambda-list (slot-value method 'lambda-list) 'function) |
| 19 |
(declare (ignore reqs opts rest-var)) |
| 20 |
(when key-flag |
| 21 |
(do* ((output '()) |
| 22 |
(l (cdr keywords) (cddddr l))) |
| 23 |
((endp l) |
| 24 |
output) |
| 25 |
(push (first l) output))))) |
| 26 |
|
| 27 |
(defmethod shared-initialize ((method standard-method) slot-names &rest initargs |
| 28 |
&key (specializers nil spec-supplied-p) |
| 29 |
(lambda-list nil lambda-supplied-p) |
| 30 |
generic-function) |
| 31 |
(declare (ignore initargs method slot-names generic-function)) |
| 32 |
(when slot-names |
| 33 |
(unless spec-supplied-p |
| 34 |
(error "Specializer list not supplied in method initialization")) |
| 35 |
(unless lambda-supplied-p |
| 36 |
(error "Lambda list not supplied in method initialization")) |
| 37 |
(unless (= (first (si::process-lambda-list lambda-list 'method)) |
| 38 |
(length specializers)) |
| 39 |
(error "The list of specializers does not match the number of required arguments in the lambda list ~A" |
| 40 |
lambda-list))) |
| 41 |
(when spec-supplied-p |
| 42 |
(loop for s in specializers |
| 43 |
unless (typep s 'specializer) |
| 44 |
do (error "Object ~A is not a valid specializer" s))) |
| 45 |
(setf method (call-next-method) |
| 46 |
(method-keywords method) (compute-method-keywords (method-lambda-list method))) |
| 47 |
method) |
| 48 |
|
| 49 |
#+threads |
| 50 |
(defparameter *eql-specializer-lock* (mp:make-lock :name 'eql-specializer)) |
| 51 |
(defparameter *eql-specializer-hash* |
| 52 |
(make-hash-table :size 128 :test #'eql)) |
| 53 |
|
| 54 |
(defun intern-eql-specializer (object) |
| 55 |
(let ((table *eql-specializer-hash*)) |
| 56 |
(mp:with-lock (*eql-specializer-lock*) |
| 57 |
(or (gethash object table nil) |
| 58 |
(setf (gethash object table) |
| 59 |
(make-instance 'eql-specializer :object object)))))) |
| 60 |
|
| 61 |
(defmethod add-direct-method ((spec specializer) (method method)) |
| 62 |
(let ((cell (specializer-method-holder spec))) |
| 63 |
(setf (cdr cell) nil |
| 64 |
(car cell) (adjoin method (car cell) :test #'eq))) |
| 65 |
(values)) |
| 66 |
|
| 67 |
(defmethod remove-direct-method ((spec specializer) (method method)) |
| 68 |
(let ((cell (specializer-method-holder spec))) |
| 69 |
(setf (cdr cell) nil |
| 70 |
(car cell) (delete method (car cell) :test #'eq))) |
| 71 |
(values)) |
| 72 |
|
| 73 |
(defmethod remove-direct-method ((spec eql-specializer) (method method)) |
| 74 |
(mp:with-lock (*eql-specializer-lock*) |
| 75 |
(call-next-method) |
| 76 |
(unless (specializer-direct-methods spec) |
| 77 |
(remhash spec *eql-specializer-hash*))) |
| 78 |
(values)) |
| 79 |
|
| 80 |
(defmethod specializer-direct-methods ((spec specializer)) |
| 81 |
(car (specializer-method-holder spec))) |
| 82 |
|
| 83 |
(defmethod specializer-direct-generic-functions ((spec specializer)) |
| 84 |
(let ((cell (specializer-method-holder spec))) |
| 85 |
(or (cdr cell) |
| 86 |
(when (car cell) |
| 87 |
(loop with acc = nil |
| 88 |
for method in (car cell) |
| 89 |
do (pushnew (method-generic-function method) acc :test #'eq) |
| 90 |
finally (return (setf (cdr cell) (nreverse acc)))))))) |