r5198: *** empty log message ***
[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 ;;;; $Id: mop.lisp,v 1.15 2003/06/25 18:08:09 kevin Exp $
11 ;;;;
12 ;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; KMRCL users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19 ;;; This file imports MOP symbols into KMR-MOP packages and then
20 ;;; re-exports them to hide differences in MOP implementations.
21
22 (in-package #:cl-user)
23
24 #+sbcl
25 (eval-when (:compile-toplevel :load-toplevel :execute)
26   (if (find-package 'sb-mop)
27       (pushnew :kmr-sbcl-mop cl:*features*)
28       (pushnew :kmr-sbcl-pcl cl:*features*)))
29
30 #+cmu
31 (eval-when (:compile-toplevel :load-toplevel :execute)
32   (if (eq (symbol-package 'pcl:find-class)
33           (find-package 'common-lisp))
34       (pushnew :kmr-cmucl-mop cl:*features*)
35       (pushnew :kmr-cmucl-pcl cl:*features*)))
36
37 (defpackage #:kmr-mop
38   (:use
39    #:cl
40    #:kmrcl
41    #+kmr-sbcl-mop #:sb-mop
42    #+kmr-cmucl-mop #:mop
43    #+allegro #:mop
44    #+lispworks #:clos
45    #+scl #:clos))
46
47 (in-package #:kmr-mop)
48
49 #+lispworks
50 (defun intern-eql-specializer (slot)
51   `(eql ,slot))
52
53   (defmacro process-class-option (metaclass slot-name &optional required)
54     #+lispworks
55     `(defmethod clos:process-a-class-option ((class ,metaclass)
56                                              (name (eql ,slot-name))
57                                              value)
58       (when (and ,required (null value))
59         (error "metaclass ~A class slot ~A must have a value" (quote ,metaclass) name))
60       (list name `',value))
61     #-lispworks
62     (declare (ignore metaclass slot-name required))
63     )
64
65   (defmacro process-slot-option (metaclass slot-name)
66     #+lispworks
67     `(defmethod clos:process-a-slot-option ((class ,metaclass)
68                                             (option (eql ,slot-name))
69                                             value
70                                             already-processed-options
71                                             slot)
72       (list* option `',value already-processed-options))
73     #-lispworks
74     (declare (ignore metaclass slot-name))
75     )
76
77
78 (eval-when (:compile-toplevel :load-toplevel :execute)
79   (shadowing-import
80    #+allegro
81    '(excl::compute-effective-slot-definition-initargs)
82    #+lispworks
83    '(clos::compute-effective-slot-definition-initargs)
84    #+sbcl
85    '(#+kmr-sbcl-mop class-of #-kmr-sbcl-mop sb-pcl:class-of
86      #+kmr-sbcl-mop class-name #-kmr-sbcl-mop sb-pcl:class-name
87      #+kmr-sbcl-mop class-slots #-kmr-sbcl-mop sb-pcl:class-slots
88      #+kmr-sbcl-mop find-class #-kmr-sbcl-mop sb-pcl:find-class
89      sb-pcl::standard-class
90      sb-pcl:slot-definition-name sb-pcl::finalize-inheritance
91      sb-pcl::standard-direct-slot-definition
92      sb-pcl::standard-effective-slot-definition sb-pcl::validate-superclass
93      sb-pcl::direct-slot-definition-class
94      sb-pcl::effective-slot-definition-class
95      sb-pcl::compute-effective-slot-definition
96      sb-pcl:class-direct-slots
97      sb-pcl::compute-effective-slot-definition-initargs
98      sb-pcl::slot-value-using-class
99      sb-pcl:class-prototype sb-pcl:generic-function-method-class sb-pcl:intern-eql-specializer
100      sb-pcl:make-method-lambda sb-pcl:generic-function-lambda-list
101      sb-pcl::compute-slots)
102    #+cmu
103    '(pcl:class-of  pcl:class-name pcl:class-slots pcl:find-class pcl::standard-class
104      pcl::slot-definition-name pcl:finalize-inheritance
105      pcl::standard-direct-slot-definition pcl::standard-effective-slot-definition
106      pcl::validate-superclass pcl:direct-slot-definition-class pcl::effective-slot-definition-class
107      pcl:compute-effective-slot-definition
108      pcl:class-direct-slots
109      pcl::compute-effective-slot-definition-initargs
110      pcl::slot-value-using-class
111      pcl:class-prototype pcl:generic-function-method-class pcl:intern-eql-specializer
112      pcl:make-method-lambda pcl:generic-function-lambda-list
113      pcl::compute-slots)
114    #+scl
115    '(class-of class-name class-slots find-class clos::standard-class
116      clos::slot-definition-name clos:finalize-inheritance
117      clos::standard-direct-slot-definition clos::standard-effective-slot-definition
118      clos::effective-slot-definition-class
119      clos:class-direct-slots
120      clos::validate-superclass clos:direct-slot-definition-class
121      clos:compute-effective-slot-definition
122      clos::compute-effective-slot-definition-initargs
123      clos::slot-value-using-class
124      clos::class-prototype clos:generic-function-method-class clos:intern-eql-specializer
125      clos:make-method-lambda clos:generic-function-lambda-list
126      clos::compute-slots
127      ;; note: make-method-lambda is not fbound
128      )
129    #+openmcl
130    '(openmcl-mop::standard-class
131      openmcl-mop::slot-definition-name openmcl-mop:finalize-inheritance
132      openmcl-mop::standard-direct-slot-definition openmcl-mop::standard-effective-slot-definition
133      openmcl-mop::validate-superclass openmcl-mop:direct-slot-definition-class openmcl-mop::effective-slot-definition-class
134      openmcl-mop:compute-effective-slot-definition
135      openmcl-mop:class-direct-slots
136      openmcl-mop::compute-effective-slot-definition-initargs
137      openmcl-mop::slot-value-using-class
138      openmcl-mop:class-prototype openmcl-mop:generic-function-method-class openmcl-mop:intern-eql-specializer
139      openmcl-mop:make-method-lambda openmcl-mop:generic-function-lambda-list
140      openmcl-mop::compute-slots)   ))
141   
142 (eval-when (:compile-toplevel :load-toplevel :execute)
143   (export '(class-of class-name class-slots find-class
144             standard-class
145             slot-definition-name finalize-inheritance
146             standard-direct-slot-definition
147             standard-effective-slot-definition validate-superclass
148             compute-effective-slot-definition-initargs
149             direct-slot-definition-class effective-slot-definition-class
150             compute-effective-slot-definition
151             slot-value-using-class
152             class-prototype generic-function-method-class intern-eql-specializer
153             make-method-lambda generic-function-lambda-list
154             compute-slots
155             class-direct-slots
156             ;; KMR-MOP encapsulating macros
157             process-slot-option
158             process-class-option))
159   
160   #+sbcl
161   (if (find-package 'sb-mop)
162       (setq cl:*features* (delete :kmr-sbcl-mop cl:*features*))
163       (setq cl:*features* (delete :kmr-sbcl-pcl cl:*features*)))
164   
165   #+cmu
166   (if (find-package 'mop)
167       (setq cl:*features* (delete :kmr-cmucl-mop cl:*features*))
168       (setq cl:*features* (delete :kmr-cmucl-pcl cl:*features*)))
169   
170   (when (>= (length (generic-function-lambda-list
171                      (ensure-generic-function
172                       'compute-effective-slot-definition)))
173             3)
174     (pushnew :kmr-normal-cesd cl:*features*))
175   
176   (when (>= (length (generic-function-lambda-list
177                      (ensure-generic-function
178                       'direct-slot-definition-class)))
179             3)
180     (pushnew :kmr-normal-dsdc cl:*features*))
181
182   )  ;; eval-when