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