r4696: Auto commit for Debian build
[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.12 2003/04/29 10:33:32 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 (find-package 'mop)
33       (pushnew :kmr-cmucl-mop cl:*features*)
34       (pushnew :kmr-cmucl-pcl cl:*features*)))
35
36 (defpackage #:kmr-mop
37   (:use
38    #:cl
39    #:kmrcl
40    #+kmr-sbcl-mop #:sb-mop
41    #+kmr-cmucl-mop #:mop
42    #+allegro #:mop
43    #+lispworks #:clos
44    #+scl #:clos))
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     #+(or allegro sbcl cmu scl)
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   (shadowing-import
79    #+allegro
80    '(excl::compute-effective-slot-definition-initargs)
81    #+lispworks
82    '(clos::compute-effective-slot-definition-initargs)
83    #+sbcl
84    '(#+kmr-sbcl-mop class-of #-kmr-sbcl-mop sb-pcl:class-of
85      #+kmr-sbcl-mop class-name #-kmr-sbcl-mop sb-pcl:class-name
86      #+kmr-sbcl-mop class-slots #-kmr-sbcl-mop sb-pcl:class-slots
87      #+kmr-sbcl-mop find-class #-kmr-sbcl-mop sb-pcl:find-class
88      sb-pcl::standard-class
89      sb-pcl:slot-definition-name sb-pcl::finalize-inheritance
90      sb-pcl::standard-direct-slot-definition
91      sb-pcl::standard-effective-slot-definition sb-pcl::validate-superclass
92      sb-pcl::direct-slot-definition-class
93      sb-pcl::effective-slot-definition-class
94      sb-pcl::compute-effective-slot-definition
95      sb-pcl:class-direct-slots
96      sb-pcl::compute-effective-slot-definition-initargs
97      sb-pcl::slot-value-using-class
98      sb-pcl:class-prototype sb-pcl:generic-function-method-class sb-pcl:intern-eql-specializer
99      sb-pcl:make-method-lambda sb-pcl:generic-function-lambda-list
100      sb-pcl::compute-slots)
101    #+cmu
102    '(pcl:class-of  pcl:class-name pcl:class-slots pcl:find-class pcl::standard-class
103      pcl::slot-definition-name pcl:finalize-inheritance
104      pcl::standard-direct-slot-definition pcl::standard-effective-slot-definition
105      pcl::validate-superclass pcl:direct-slot-definition-class pcl::effective-slot-definition-class
106      pcl:compute-effective-slot-definition
107      pcl:class-direct-slots
108      pcl::compute-effective-slot-definition-initargs
109      pcl::slot-value-using-class
110      pcl:class-prototype pcl:generic-function-method-class pcl:intern-eql-specializer
111      pcl:make-method-lambda pcl:generic-function-lambda-list
112      pcl::compute-slots)
113    #+scl
114    '(class-of class-name class-slots find-class clos::standard-class
115      clos::slot-definition-name clos:finalize-inheritance
116      clos::standard-direct-slot-definition clos::standard-effective-slot-definition
117      clos::effective-slot-definition-class
118      clos:class-direct-slots
119      clos::validate-superclass clos:direct-slot-definition-class
120      clos:compute-effective-slot-definition
121      clos::compute-effective-slot-definition-initargs
122      clos::slot-value-using-class
123      clos:class-prototype clos:generic-function-method-class clos:intern-eql-specializer
124      clos:make-method-lambda clos:generic-function-lambda-list
125      clos::compute-slots
126      ;; note: make-method-lambda is not fbound
127      )))
128   
129 (eval-when (:compile-toplevel :load-toplevel :execute)
130   (export '(class-of class-name class-slots find-class
131             standard-class
132             slot-definition-name finalize-inheritance
133             standard-direct-slot-definition
134             standard-effective-slot-definition validate-superclass
135             compute-effective-slot-definition-initargs
136             direct-slot-definition-class effective-slot-definition-class
137             compute-effective-slot-definition
138             slot-value-using-class
139             class-prototype generic-function-method-class intern-eql-specializer
140             make-method-lambda generic-function-lambda-list
141             compute-slots
142             class-direct-slots
143             ;; KMR-MOP encapsulating macros
144             process-slot-option
145             process-class-option))
146   
147   #+sbcl
148   (if (find-package 'sb-mop)
149       (setq cl:*features* (delete :kmr-sbcl-mop cl:*features*))
150       (setq cl:*features* (delete :kmr-sbcl-pcl cl:*features*)))
151   
152   #+cmu
153   (if (find-package 'mop)
154       (setq cl:*features* (delete :kmr-cmucl-mop cl:*features*))
155       (setq cl:*features* (delete :kmr-cmucl-pcl cl:*features*)))
156   
157   (when (>= (length (generic-function-lambda-list
158                      (ensure-generic-function
159                       'compute-effective-slot-definition)))
160             3)
161     (pushnew :kmr-normal-cesd cl:*features*))
162   
163   (when (>= (length (generic-function-lambda-list
164                      (ensure-generic-function
165                       'direct-slot-definition-class)))
166             3)
167     (pushnew :kmr-normal-dsdc cl:*features*))
168
169   )  ;; eval-when