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