Remove kmr-mop package before defining in event of redefining package
[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 (eval-when (:compile-toplevel :load-toplevel :execute)
30            (when (find-package '#:kmr-mop)
31              (delete-package '#:kmr-mop)))
32
33 (defpackage #:kmr-mop
34   (:use
35    #:cl
36    #:kmrcl
37    #+kmrcl::cmucl-mop #:mop
38    #+allegro #:mop
39    #+lispworks #:clos
40    #+clisp #:clos
41    #+scl #:clos
42    #+ccl #:openmcl-mop
43    )
44   )
45
46 (in-package #:kmr-mop)
47
48 #+lispworks
49 (defun intern-eql-specializer (slot)
50   `(eql ,slot))
51
52 (defmacro process-class-option (metaclass slot-name &optional required)
53   #+lispworks
54   `(defmethod clos:process-a-class-option ((class ,metaclass)
55                                            (name (eql ,slot-name))
56                                            value)
57     (when (and ,required (null value))
58       (error "metaclass ~A class slot ~A must have a value" (quote ,metaclass) name))
59     (list name `',value))
60   #-lispworks
61   (declare (ignore metaclass slot-name required))
62   )
63
64 (defmacro process-slot-option (metaclass slot-name)
65   #+lispworks
66   `(defmethod clos:process-a-slot-option ((class ,metaclass)
67                                           (option (eql ,slot-name))
68                                           value
69                                           already-processed-options
70                                           slot)
71     (list* option `',value already-processed-options))
72   #-lispworks
73   (declare (ignore metaclass slot-name))
74   )
75
76
77 (eval-when (:compile-toplevel :load-toplevel :execute)
78   #+sbcl
79   (dolist (name '("CLASS-OF"
80                   "CLASS-NAME"
81                   "CLASS-SLOTS"
82                   "FIND-CLASS"
83                   "STANDARD-CLASS"
84                   "SLOT-DEFINITION-NAME"
85                   "FINALIZE-INHERITANCE"
86                   "STANDARD-DIRECT-SLOT-DEFINITION"
87                   "STANDARD-EFFECTIVE-SLOT-DEFINITION"
88                   "VALIDATE-SUPERCLASS" "DIRECT-SLOT-DEFINITION-CLASS"
89                   "EFFECTIVE-SLOT-DEFINITION-CLASS"
90                   "COMPUTE-EFFECTIVE-SLOT-DEFINITION"
91                   "CLASS-DIRECT-SLOTS"
92                   "COMPUTE-EFFECTIVE-SLOT-DEFINITION-INITARGS"
93                   "SLOT-VALUE-USING-CLASS"
94                   "CLASS-PROTOTYPE"
95                   "GENERIC-FUNCTION-METHOD-CLASS"
96                   "INTERN-EQL-SPECIALIZER"
97                   "MAKE-METHOD-LAMBDA"
98                   "GENERIC-FUNCTION-LAMBDA-LIST"
99                   "COMPUTE-SLOTS"))
100     (let ((sym (find-symbol name "SB-MOP")))
101       (if sym
102           (shadowing-import sym)
103           (progn
104             (setq sym (find-symbol name "SB-PCL"))
105             (when sym
106               (shadowing-import sym))))))
107   #-sbcl
108   (shadowing-import
109    #+allegro
110    '(excl::compute-effective-slot-definition-initargs)
111    #+lispworks
112    '(clos::compute-effective-slot-definition-initargs)
113    #+clisp
114    '(clos::compute-effective-slot-definition-initargs)
115    #+cmu
116    '(pcl:class-of  pcl:class-name pcl:class-slots pcl:find-class pcl::standard-class
117      pcl::slot-definition-name pcl:finalize-inheritance
118      pcl::standard-direct-slot-definition pcl::standard-effective-slot-definition
119      pcl::validate-superclass pcl:direct-slot-definition-class pcl::effective-slot-definition-class
120      pcl:compute-effective-slot-definition
121      pcl:class-direct-slots
122      pcl::compute-effective-slot-definition-initargs
123      pcl::slot-value-using-class
124      pcl:class-prototype pcl:generic-function-method-class pcl:intern-eql-specializer
125      pcl:make-method-lambda pcl:generic-function-lambda-list
126      pcl::compute-slots)
127    #+scl
128    '(class-of class-name class-slots find-class clos::standard-class
129      clos::slot-definition-name clos:finalize-inheritance
130      clos::standard-direct-slot-definition clos::standard-effective-slot-definition
131      clos::effective-slot-definition-class
132      clos:class-direct-slots
133      clos::validate-superclass clos:direct-slot-definition-class
134      clos:compute-effective-slot-definition
135      clos::compute-effective-slot-definition-initargs
136      clos::slot-value-using-class
137      clos::class-prototype clos:generic-function-method-class clos:intern-eql-specializer
138      clos:make-method-lambda clos:generic-function-lambda-list
139      clos::compute-slots
140      ;; note: make-method-lambda is not fbound
141      )
142    #+ccl
143    '(openmcl-mop::slot-definition-name openmcl-mop:finalize-inheritance
144      openmcl-mop::standard-direct-slot-definition openmcl-mop::standard-effective-slot-definition
145      openmcl-mop::validate-superclass openmcl-mop:direct-slot-definition-class openmcl-mop::effective-slot-definition-class
146      openmcl-mop:compute-effective-slot-definition
147      openmcl-mop:class-direct-slots
148      openmcl-mop::compute-effective-slot-definition-initargs
149      openmcl-mop::slot-value-using-class
150      openmcl-mop:class-prototype openmcl-mop:generic-function-method-class openmcl-mop:intern-eql-specializer
151      openmcl-mop:make-method-lambda openmcl-mop:generic-function-lambda-list
152      openmcl-mop::compute-slots)   ))
153
154 (eval-when (:compile-toplevel :load-toplevel :execute)
155   (export '(class-of class-name class-slots find-class
156             standard-class
157             slot-definition-name finalize-inheritance
158             standard-direct-slot-definition
159             standard-effective-slot-definition validate-superclass
160             compute-effective-slot-definition-initargs
161             direct-slot-definition-class effective-slot-definition-class
162             compute-effective-slot-definition
163             slot-value-using-class
164             class-prototype generic-function-method-class intern-eql-specializer
165             make-method-lambda generic-function-lambda-list
166             compute-slots
167             class-direct-slots
168             ;; KMR-MOP encapsulating macros
169             process-slot-option
170             process-class-option))
171
172   #+cmu
173   (if (find-package 'mop)
174       (setq cl:*features* (delete 'kmrcl::cmucl-mop cl:*features*))
175       (setq cl:*features* (delete 'kmrcl::cmucl-pcl cl:*features*)))
176
177   (when (< (length (generic-function-lambda-list
178                      (ensure-generic-function
179                       'compute-effective-slot-definition)))
180             3)
181     (pushnew 'short-arg-cesd cl:*features*))
182
183   (when (< (length (generic-function-lambda-list
184                     (ensure-generic-function
185                      'direct-slot-definition-class)))
186            3)
187     (pushnew 'short-arg-dsdc cl:*features*))
188
189   )  ;; eval-when