r4687: Automatic commit for debian_version_1_32-1
[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.10 2003/04/29 07:52:38 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 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 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::compute-effective-slot-definition-initargs
96      sb-pcl::slot-value-using-class
97      sb-pcl:class-prototype sb-pcl:generic-function-method-class sb-pcl:intern-eql-specializer
98      sb-pcl:make-method-lambda sb-pcl:generic-function-lambda-list
99      sb-pcl::compute-slots)
100    #+cmu
101    '(pcl:class-of  pcl:class-name pcl:class-slots pcl:find-class pcl::standard-class
102      pcl::slot-definition-name pcl:finalize-inheritance
103      pcl::standard-direct-slot-definition pcl::standard-effective-slot-definition
104      pcl::validate-superclass pcl:direct-slot-definition-class pcl::effective-slot-definition-class
105      pcl:compute-effective-slot-definition
106      pcl::compute-effective-slot-definition-initargs
107      pcl::slot-value-using-class
108      pcl:class-prototype pcl:generic-function-method-class pcl:intern-eql-specializer
109      pcl:make-method-lambda pcl:generic-function-lambda-list
110      pcl::compute-slots)
111    #+scl
112    '(class-of class-name class-slots find-class clos::standard-class
113      clos::slot-definition-name clos:finalize-inheritance
114      clos::standard-direct-slot-definition clos::standard-effective-slot-definition
115      clos::effective-slot-definition-class
116      clos::validate-superclass clos:direct-slot-definition-class
117      clos:compute-effective-slot-definition
118      clos::compute-effective-slot-definition-initargs
119      clos::slot-value-using-class
120      clos:class-prototype clos:generic-function-method-class clos:intern-eql-specializer
121      clos:make-method-lambda clos:generic-function-lambda-list
122      clos::compute-slots
123      ;; note: make-method-lambda is not fbound
124      )))
125   
126 (eval-when (:compile-toplevel :load-toplevel :execute)
127   (export '(class-of class-name class-slots find-class
128             standard-class
129             slot-definition-name finalize-inheritance
130             standard-direct-slot-definition
131             standard-effective-slot-definition validate-superclass
132             compute-effective-slot-definition-initargs
133             direct-slot-definition-class effective-slot-definition-class
134             compute-effective-slot-definition
135             slot-value-using-class
136             class-prototype generic-function-method-class intern-eql-specializer
137             make-method-lambda generic-function-lambda-list
138             compute-slots
139             ;; KMR-MOP encapsulating macros
140             process-slot-option
141             process-class-option))
142   
143   #+sbcl
144   (if (find-package 'sb-mop)
145       (setq cl:*features* (delete :kmr-sbcl-mop cl:*features*))
146       (setq cl:*features* (delete :kmr-sbcl-pcl cl:*features*)))
147   
148   #+cmu
149   (if (find-package 'mop)
150       (setq cl:*features* (delete :kmr-cmucl-mop cl:*features*))
151       (setq cl:*features* (delete :kmr-cmucl-pcl cl:*features*)))
152   
153   (when (>= (length (generic-function-lambda-list
154                      (ensure-generic-function
155                       'compute-effective-slot-definition)))
156             3)
157     (pushnew :kmr-normal-cesd cl:*features*))
158   
159   (when (>= (length (generic-function-lambda-list
160                      (ensure-generic-function
161                       'direct-slot-definition-class)))
162             3)
163     (pushnew :kmr-normal-dsdc cl:*features*))
164
165   )  ;; eval-when