r5266: *** 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.16 2003/06/25 20:11:54 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    #+openmcl #:openmcl-mop
47    ))
48
49 (in-package #:kmr-mop)
50
51 #+lispworks
52 (defun intern-eql-specializer (slot)
53   `(eql ,slot))
54
55   (defmacro process-class-option (metaclass slot-name &optional required)
56     #+lispworks
57     `(defmethod clos:process-a-class-option ((class ,metaclass)
58                                              (name (eql ,slot-name))
59                                              value)
60       (when (and ,required (null value))
61         (error "metaclass ~A class slot ~A must have a value" (quote ,metaclass) name))
62       (list name `',value))
63     #-lispworks
64     (declare (ignore metaclass slot-name required))
65     )
66
67   (defmacro process-slot-option (metaclass slot-name)
68     #+lispworks
69     `(defmethod clos:process-a-slot-option ((class ,metaclass)
70                                             (option (eql ,slot-name))
71                                             value
72                                             already-processed-options
73                                             slot)
74       (list* option `',value already-processed-options))
75     #-lispworks
76     (declare (ignore metaclass slot-name))
77     )
78
79
80 (eval-when (:compile-toplevel :load-toplevel :execute)
81   (shadowing-import
82    #+allegro
83    '(excl::compute-effective-slot-definition-initargs)
84    #+lispworks
85    '(clos::compute-effective-slot-definition-initargs)
86    #+sbcl
87    '(#+kmr-sbcl-mop class-of #-kmr-sbcl-mop sb-pcl:class-of
88      #+kmr-sbcl-mop class-name #-kmr-sbcl-mop sb-pcl:class-name
89      #+kmr-sbcl-mop class-slots #-kmr-sbcl-mop sb-pcl:class-slots
90      #+kmr-sbcl-mop find-class #-kmr-sbcl-mop sb-pcl:find-class
91      sb-pcl::standard-class
92      sb-pcl:slot-definition-name sb-pcl::finalize-inheritance
93      sb-pcl::standard-direct-slot-definition
94      sb-pcl::standard-effective-slot-definition sb-pcl::validate-superclass
95      sb-pcl::direct-slot-definition-class
96      sb-pcl::effective-slot-definition-class
97      sb-pcl::compute-effective-slot-definition
98      sb-pcl:class-direct-slots
99      sb-pcl::compute-effective-slot-definition-initargs
100      sb-pcl::slot-value-using-class
101      sb-pcl:class-prototype sb-pcl:generic-function-method-class sb-pcl:intern-eql-specializer
102      sb-pcl:make-method-lambda sb-pcl:generic-function-lambda-list
103      sb-pcl::compute-slots)
104    #+cmu
105    '(pcl:class-of  pcl:class-name pcl:class-slots pcl:find-class pcl::standard-class
106      pcl::slot-definition-name pcl:finalize-inheritance
107      pcl::standard-direct-slot-definition pcl::standard-effective-slot-definition
108      pcl::validate-superclass pcl:direct-slot-definition-class pcl::effective-slot-definition-class
109      pcl:compute-effective-slot-definition
110      pcl:class-direct-slots
111      pcl::compute-effective-slot-definition-initargs
112      pcl::slot-value-using-class
113      pcl:class-prototype pcl:generic-function-method-class pcl:intern-eql-specializer
114      pcl:make-method-lambda pcl:generic-function-lambda-list
115      pcl::compute-slots)
116    #+scl
117    '(class-of class-name class-slots find-class clos::standard-class
118      clos::slot-definition-name clos:finalize-inheritance
119      clos::standard-direct-slot-definition clos::standard-effective-slot-definition
120      clos::effective-slot-definition-class
121      clos:class-direct-slots
122      clos::validate-superclass clos:direct-slot-definition-class
123      clos:compute-effective-slot-definition
124      clos::compute-effective-slot-definition-initargs
125      clos::slot-value-using-class
126      clos::class-prototype clos:generic-function-method-class clos:intern-eql-specializer
127      clos:make-method-lambda clos:generic-function-lambda-list
128      clos::compute-slots
129      ;; note: make-method-lambda is not fbound
130      )
131    #+openmcl
132    '(openmcl-mop::slot-definition-name openmcl-mop:finalize-inheritance
133      openmcl-mop::standard-direct-slot-definition openmcl-mop::standard-effective-slot-definition
134      openmcl-mop::validate-superclass openmcl-mop:direct-slot-definition-class openmcl-mop::effective-slot-definition-class
135      openmcl-mop:compute-effective-slot-definition
136      openmcl-mop:class-direct-slots
137      openmcl-mop::compute-effective-slot-definition-initargs
138      openmcl-mop::slot-value-using-class
139      openmcl-mop:class-prototype openmcl-mop:generic-function-method-class openmcl-mop:intern-eql-specializer
140      openmcl-mop:make-method-lambda openmcl-mop:generic-function-lambda-list
141      openmcl-mop::compute-slots)   ))
142   
143 (eval-when (:compile-toplevel :load-toplevel :execute)
144   (export '(class-of class-name class-slots find-class
145             standard-class
146             slot-definition-name finalize-inheritance
147             standard-direct-slot-definition
148             standard-effective-slot-definition validate-superclass
149             compute-effective-slot-definition-initargs
150             direct-slot-definition-class effective-slot-definition-class
151             compute-effective-slot-definition
152             slot-value-using-class
153             class-prototype generic-function-method-class intern-eql-specializer
154             make-method-lambda generic-function-lambda-list
155             compute-slots
156             class-direct-slots
157             ;; KMR-MOP encapsulating macros
158             process-slot-option
159             process-class-option))
160   
161   #+sbcl
162   (if (find-package 'sb-mop)
163       (setq cl:*features* (delete :kmr-sbcl-mop cl:*features*))
164       (setq cl:*features* (delete :kmr-sbcl-pcl cl:*features*)))
165   
166   #+cmu
167   (if (find-package 'mop)
168       (setq cl:*features* (delete :kmr-cmucl-mop cl:*features*))
169       (setq cl:*features* (delete :kmr-cmucl-pcl cl:*features*)))
170   
171   (when (>= (length (generic-function-lambda-list
172                      (ensure-generic-function
173                       'compute-effective-slot-definition)))
174             3)
175     (pushnew :kmr-normal-cesd cl:*features*))
176   
177   (when (>= (length (generic-function-lambda-list
178                      (ensure-generic-function
179                       'direct-slot-definition-class)))
180             3)
181     (pushnew :kmr-normal-dsdc cl:*features*))
182
183   )  ;; eval-when