For SBCL, first check sb-mop for symbols to import, if not found check sb-pcl
[kmrcl.git] / mop.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          mop.lisp
6 ;;;; Purpose:       Imports standard MOP symbols into KMRCL
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Apr 2003
9 ;;;;
10 ;;;; This file, part of KMRCL, is Copyright (c) 2002-2010 by Kevin M. Rosenberg
11 ;;;;
12 ;;;; KMRCL users are granted the rights to distribute and use this software
13 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
14 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
15 ;;;; *************************************************************************
16
17 ;;; This file imports MOP symbols into KMR-MOP packages and then
18 ;;; re-exports them to hide differences in MOP implementations.
19
20 (in-package #:cl-user)
21
22 #+cmu
23 (eval-when (:compile-toplevel :load-toplevel :execute)
24   (if (eq (symbol-package 'pcl:find-class)
25           (find-package 'common-lisp))
26       (pushnew 'kmrcl::cmucl-mop cl:*features*)
27       (pushnew 'kmrcl::cmucl-pcl cl:*features*)))
28
29 (defpackage #:kmr-mop
30   (:use
31    #:cl
32    #:kmrcl
33    #+kmrcl::cmucl-mop #:mop
34    #+allegro #:mop
35    #+lispworks #:clos
36    #+clisp #:clos
37    #+scl #:clos
38    #+ccl #:openmcl-mop
39    )
40   )
41
42 (in-package #:kmr-mop)
43
44 #+lispworks
45 (defun intern-eql-specializer (slot)
46   `(eql ,slot))
47
48 (defmacro process-class-option (metaclass slot-name &optional required)
49   #+lispworks
50   `(defmethod clos:process-a-class-option ((class ,metaclass)
51                                            (name (eql ,slot-name))
52                                            value)
53     (when (and ,required (null value))
54       (error "metaclass ~A class slot ~A must have a value" (quote ,metaclass) name))
55     (list name `',value))
56   #-lispworks
57   (declare (ignore metaclass slot-name required))
58   )
59
60 (defmacro process-slot-option (metaclass slot-name)
61   #+lispworks
62   `(defmethod clos:process-a-slot-option ((class ,metaclass)
63                                           (option (eql ,slot-name))
64                                           value
65                                           already-processed-options
66                                           slot)
67     (list* option `',value already-processed-options))
68   #-lispworks
69   (declare (ignore metaclass slot-name))
70   )
71
72
73 (eval-when (:compile-toplevel :load-toplevel :execute)
74   #+sbcl
75   (dolist (name '("CLASS-OF"
76                   "CLASS-NAME"
77                   "CLASS-SLOTS"
78                   "FIND-CLASS"
79                   "STANDARD-CLASS"
80                   "SLOT-DEFINITION-NAME"
81                   "FINALIZE-INHERITANCE"
82                   "STANDARD-DIRECT-SLOT-DEFINITION"
83                   "STANDARD-EFFECTIVE-SLOT-DEFINITION"
84                   "VALIDATE-SUPERCLASS" "DIRECT-SLOT-DEFINITION-CLASS"
85                   "EFFECTIVE-SLOT-DEFINITION-CLASS"
86                   "COMPUTE-EFFECTIVE-SLOT-DEFINITION"
87                   "CLASS-DIRECT-SLOTS"
88                   "COMPUTE-EFFECTIVE-SLOT-DEFINITION-INITARGS"
89                   "SLOT-VALUE-USING-CLASS"
90                   "CLASS-PROTOTYPE"
91                   "GENERIC-FUNCTION-METHOD-CLASS"
92                   "INTERN-EQL-SPECIALIZER"
93                   "MAKE-METHOD-LAMBDA"
94                   "GENERIC-FUNCTION-LAMBDA-LIST"
95                   "COMPUTE-SLOTS"))
96     (let ((sym (find-symbol name "SB-MOP")))
97       (if sym
98           (shadowing-import sym)
99           (progn
100             (setq sym (find-symbol name "SB-PCL"))
101             (when sym
102               (shadowing-import sym))))))
103   #-sbcl
104   (shadowing-import
105    #+allegro
106    '(excl::compute-effective-slot-definition-initargs)
107    #+lispworks
108    '(clos::compute-effective-slot-definition-initargs)
109    #+clisp
110    '(clos::compute-effective-slot-definition-initargs)
111    #+cmu
112    '(pcl:class-of  pcl:class-name pcl:class-slots pcl:find-class pcl::standard-class
113      pcl::slot-definition-name pcl:finalize-inheritance
114      pcl::standard-direct-slot-definition pcl::standard-effective-slot-definition
115      pcl::validate-superclass pcl:direct-slot-definition-class pcl::effective-slot-definition-class
116      pcl:compute-effective-slot-definition
117      pcl:class-direct-slots
118      pcl::compute-effective-slot-definition-initargs
119      pcl::slot-value-using-class
120      pcl:class-prototype pcl:generic-function-method-class pcl:intern-eql-specializer
121      pcl:make-method-lambda pcl:generic-function-lambda-list
122      pcl::compute-slots)
123    #+scl
124    '(class-of class-name class-slots find-class clos::standard-class
125      clos::slot-definition-name clos:finalize-inheritance
126      clos::standard-direct-slot-definition clos::standard-effective-slot-definition
127      clos::effective-slot-definition-class
128      clos:class-direct-slots
129      clos::validate-superclass clos:direct-slot-definition-class
130      clos:compute-effective-slot-definition
131      clos::compute-effective-slot-definition-initargs
132      clos::slot-value-using-class
133      clos::class-prototype clos:generic-function-method-class clos:intern-eql-specializer
134      clos:make-method-lambda clos:generic-function-lambda-list
135      clos::compute-slots
136      ;; note: make-method-lambda is not fbound
137      )
138    #+ccl
139    '(openmcl-mop::slot-definition-name openmcl-mop:finalize-inheritance
140      openmcl-mop::standard-direct-slot-definition openmcl-mop::standard-effective-slot-definition
141      openmcl-mop::validate-superclass openmcl-mop:direct-slot-definition-class openmcl-mop::effective-slot-definition-class
142      openmcl-mop:compute-effective-slot-definition
143      openmcl-mop:class-direct-slots
144      openmcl-mop::compute-effective-slot-definition-initargs
145      openmcl-mop::slot-value-using-class
146      openmcl-mop:class-prototype openmcl-mop:generic-function-method-class openmcl-mop:intern-eql-specializer
147      openmcl-mop:make-method-lambda openmcl-mop:generic-function-lambda-list
148      openmcl-mop::compute-slots)   ))
149
150 (eval-when (:compile-toplevel :load-toplevel :execute)
151   (export '(class-of class-name class-slots find-class
152             standard-class
153             slot-definition-name finalize-inheritance
154             standard-direct-slot-definition
155             standard-effective-slot-definition validate-superclass
156             compute-effective-slot-definition-initargs
157             direct-slot-definition-class effective-slot-definition-class
158             compute-effective-slot-definition
159             slot-value-using-class
160             class-prototype generic-function-method-class intern-eql-specializer
161             make-method-lambda generic-function-lambda-list
162             compute-slots
163             class-direct-slots
164             ;; KMR-MOP encapsulating macros
165             process-slot-option
166             process-class-option))
167
168   #+cmu
169   (if (find-package 'mop)
170       (setq cl:*features* (delete 'kmrcl::cmucl-mop cl:*features*))
171       (setq cl:*features* (delete 'kmrcl::cmucl-pcl cl:*features*)))
172
173   (when (< (length (generic-function-lambda-list
174                      (ensure-generic-function
175                       'compute-effective-slot-definition)))
176             3)
177     (pushnew 'short-arg-cesd cl:*features*))
178
179   (when (< (length (generic-function-lambda-list
180                     (ensure-generic-function
181                      'direct-slot-definition-class)))
182            3)
183     (pushnew 'short-arg-dsdc cl:*features*))
184
185   )  ;; eval-when