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