Commit ead2abc1 authored by Pascal Costanza's avatar Pascal Costanza
Browse files

Initial revision (v0.2).

darcs-hash:e268d42f1d0bfb9c7ef64135393a2f63b243ed54
parents
(in-package :cl-user)
(defpackage #:closer-mop
(:use #:common-lisp #:lispworks)
(:nicknames #:c2mop)
(:shadow
#:defgeneric #:ensure-generic-function
#:standard-generic-function)
(:export
#:defgeneric #:ensure-generic-function
#:standard-generic-function)
(:import-from #:mop
#:direct-slot-definition
#:effective-slot-definition
#:eql-specializer
#:forward-referenced-class
#:funcallable-standard-class
#:funcallable-standard-object
#:metaobject
#:slot-definition
#:specializer
#:standard-accessor-method
#:standard-direct-slot-definition
#:standard-effective-slot-definition
#:standard-reader-method
#:standard-slot-definition
#:standard-writer-method
#:accessor-method-slot-definition
#:add-dependent
#:add-direct-method
#:add-direct-subclass
#:class-default-initargs
#:class-direct-default-initargs
#:class-direct-slots
#:class-direct-subclasses
#:class-direct-superclasses
#:class-finalized-p
#:class-precedence-list
#:class-prototype
#:class-slots
#:compute-applicable-methods-using-classes
#:compute-class-precedence-list
#:compute-default-initargs
#:compute-discriminating-function
#:compute-effective-method
#:compute-effective-slot-definition
#:compute-slots
#:direct-slot-definition-class
#:effective-slot-definition-class
#:ensure-class
#:ensure-class-using-class
#:ensure-generic-function-using-class
#:eql-specializer-object
#:extract-lambda-list
#:extract-specializer-names
#:finalize-inheritance
#:find-method-combination
#:funcallable-standard-instance-access
#:generic-function-argument-precedence-order
#:generic-function-declarations
#:generic-function-lambda-list
#:generic-function-method-class
#:generic-function-method-combination
#:generic-function-methods
#:generic-function-name
#:intern-eql-specializer
#-allegro #:make-method-lambda
#:map-dependents
#:method-function
#:method-generic-function
#:method-lambda-list
#:method-specializers
#:reader-method-class
#:remove-dependent
#:remove-direct-method
#:remove-direct-subclass
#:set-funcallable-instance-function
#:slot-boundp-using-class
#:slot-definition-allocation
#:slot-definition-initargs
#:slot-definition-initform
#:slot-definition-initfunction
#:slot-definition-location
#:slot-definition-name
#:slot-definition-readers
#:slot-definition-writers
#:slot-definition-type
#:slot-makunbound-using-class
#:slot-value-using-class
#:specializer-direct-generic-functions
#:specializer-direct-methods
#:standard-instance-access
#:update-dependent
#:validate-superclass
#:writer-method-class)
(:export
#:direct-slot-definition
#:effective-slot-definition
#:eql-specializer
#:forward-referenced-class
#:funcallable-standard-class
#:funcallable-standard-object
#:metaobject
#:slot-definition
#:specializer
#:standard-accessor-method
#:standard-direct-slot-definition
#:standard-effective-slot-definition
#:standard-reader-method
#:standard-slot-definition
#:standard-writer-method
#:ensure-method
#:fix-slot-initargs
#:accessor-method-slot-definition
#:add-dependent
#:add-direct-method
#:add-direct-subclass
#:class-default-initargs
#:class-direct-default-initargs
#:class-direct-slots
#:class-direct-subclasses
#:class-direct-superclasses
#:class-finalized-p
#:class-precedence-list
#:class-prototype
#:class-slots
#:compute-applicable-methods-using-classes
#:compute-class-precedence-list
#:compute-default-initargs
#:compute-discriminating-function
#:compute-effective-method
#:compute-effective-slot-definition
#:compute-slots
#:direct-slot-definition-class
#:effective-slot-definition-class
#:ensure-class
#:ensure-class-using-class
#:ensure-generic-function-using-class
#:eql-specializer-object
#:extract-lambda-list
#:extract-specializer-names
#:finalize-inheritance
#:find-method-combination
#:funcallable-standard-instance-access
#:generic-function-argument-precedence-order
#:generic-function-declarations
#:generic-function-lambda-list
#:generic-function-method-class
#:generic-function-method-combination
#:generic-function-methods
#:generic-function-name
#:intern-eql-specializer
#-allegro #:make-method-lambda
#:map-dependents
#:method-function
#:method-generic-function
#:method-lambda-list
#:method-specializers
#:reader-method-class
#:remove-dependent
#:remove-direct-method
#:remove-direct-subclass
#:set-funcallable-instance-function
#:slot-boundp-using-class
#:slot-definition-allocation
#:slot-definition-initargs
#:slot-definition-initform
#:slot-definition-initfunction
#:slot-definition-location
#:slot-definition-name
#:slot-definition-readers
#:slot-definition-writers
#:slot-definition-type
#:slot-makunbound-using-class
#:slot-value-using-class
#:specializer-direct-generic-functions
#:specializer-direct-methods
#:standard-instance-access
#:update-dependent
#:validate-superclass
#:writer-method-class))
(in-package :closer-mop)
;; We need a new standard-generic-function for various things.
(cl:defclass standard-generic-function (cl:standard-generic-function)
()
(:metaclass clos:funcallable-standard-class))
;; The following ensures that the new standard-generic-function is used.
(defun ensure-generic-function
(name &rest args
&key (generic-function-class 'standard-generic-function)
&allow-other-keys)
(declare (dynamic-extent args))
(when (fboundp name)
(let ((function (fdefinition name)))
(unless (typep function 'generic-function)
(cerror "Discard existing definition and create generic function."
"~S is already fbound, but not as a generic function." name)
(fmakunbound name))))
(if (fboundp name)
(let ((function (fdefinition name)))
(apply #'ensure-generic-function-using-class
function name args))
(apply #'ensure-generic-function-using-class nil name
:generic-function-class generic-function-class
args)))
;; The following macro ensures that the new standard-generic-function
;; is used by default.
(defmacro defgeneric (name (&rest args) &body options)
(if (member :generic-function-class options :key #'car)
`(cl:defgeneric ,name ,args ,@options)
`(cl:defgeneric ,name ,args ,@options
(:generic-function-class standard-generic-function))))
;;; The following three methods ensure that the dependent protocol
;;; for generic function works.
;; The following method additionally ensures that
;; compute-discriminating-function is triggered.
(cl:defmethod reinitialize-instance :after
((gf standard-generic-function) &rest initargs)
(declare (dynamic-extent initargs))
(set-funcallable-instance-function
gf (compute-discriminating-function gf))
(map-dependents
gf (lambda (dep) (apply #'update-dependent gf dep initargs))))
(cl:defmethod add-method :after
((gf standard-generic-function) method)
(map-dependents
gf (lambda (dep) (update-dependent gf dep 'add-method method))))
(cl:defmethod remove-method :after
((gf standard-generic-function) method)
(map-dependents
gf (lambda (dep) (update-dependent gf dep 'remove-method method))))
(defun ensure-method (gf lambda-expression
&key (qualifiers ())
(lambda-list (cadr lambda-expression))
(specializers (loop for arg in lambda-list
until (member arg lambda-list-keywords)
collect (find-class 't))))
(funcall (compile nil `(lambda ()
(defmethod ,(generic-function-name gf) ,@qualifiers
,(loop for (arg . rest) on lambda-list
for specializer in specializers
collect `(,arg ,specializer) into args
finally (return (nconc args rest)))
,@(cddr lambda-expression))))))
;; The following can be used in direct-slot-definition-class to get the correct initargs
;; for a slot. Use it like this:
;;
;; (defmethod direct-slot-definition-class
;; ((class my-standard-class) &rest initargs)
;; (declare (dynamic-extent initargs))
;; (destructuring-bind
;; (&key key-of-interest &allow-other-keys)
;; (fix-slot-initargs initargs)
;; ...))
(defvar *standard-slot-keys*
'(:name :documentation
:initargs :initform :initfunction
:readers :writers))
(defun fix-slot-initargs (initargs)
initargs)
(eval-when (:compile-toplevel :load-toplevel :execute)
(pushnew :closer-mop *features*))
(in-package :cl-user)
(defpackage #:closer-mop
(:use #:common-lisp #:lispworks)
(:nicknames #:c2mop)
(:import-from #:clos
#:direct-slot-definition
#:effective-slot-definition
#:eql-specializer
#:forward-referenced-class
#:funcallable-standard-class
#:funcallable-standard-object
#:metaobject
#:slot-definition
#:specializer
#:standard-accessor-method
#:standard-direct-slot-definition
#:standard-effective-slot-definition
#:standard-reader-method
#:standard-slot-definition
#:standard-writer-method
#:accessor-method-slot-definition
#:add-dependent
#:add-direct-method
#:add-direct-subclass
#:class-default-initargs
#:class-direct-default-initargs
#:class-direct-slots
#:class-direct-subclasses
#:class-direct-superclasses
#:class-finalized-p
#:class-precedence-list
#:class-prototype
#:class-slots
#:compute-applicable-methods-using-classes
#:compute-class-precedence-list
#:compute-default-initargs
#:compute-discriminating-function
#:compute-effective-method
#:compute-effective-slot-definition
#:compute-slots
#:direct-slot-definition-class
#:effective-slot-definition-class
#:ensure-class
#:ensure-class-using-class
#:ensure-generic-function-using-class
#:eql-specializer-object
#:extract-lambda-list
#:extract-specializer-names
#:finalize-inheritance
#:find-method-combination
#:funcallable-standard-instance-access
#:generic-function-argument-precedence-order
#:generic-function-declarations
#:generic-function-lambda-list
#:generic-function-method-class
#:generic-function-method-combination
#:generic-function-methods
#:generic-function-name
#:intern-eql-specializer
#-clisp #:make-method-lambda
#:map-dependents
#:method-function
#:method-generic-function
#:method-lambda-list
#:method-specializers
#:reader-method-class
#:remove-dependent
#:remove-direct-method
#:remove-direct-subclass
#:set-funcallable-instance-function
#:slot-boundp-using-class
#:slot-definition-allocation
#:slot-definition-initargs
#:slot-definition-initform
#:slot-definition-initfunction
#:slot-definition-location
#:slot-definition-name
#:slot-definition-readers
#:slot-definition-writers
#:slot-definition-type
#:slot-makunbound-using-class
#:slot-value-using-class
#:specializer-direct-generic-functions
#:specializer-direct-methods
#:standard-instance-access
#:update-dependent
#:validate-superclass
#:writer-method-class)
(:export
#:direct-slot-definition
#:effective-slot-definition
#:eql-specializer
#:forward-referenced-class
#:funcallable-standard-class
#:funcallable-standard-object
#:metaobject
#:slot-definition
#:specializer
#:standard-accessor-method
#:standard-direct-slot-definition
#:standard-effective-slot-definition
#:standard-reader-method
#:standard-slot-definition
#:standard-writer-method
#:ensure-method
#:fix-slot-initargs
#:accessor-method-slot-definition
#:add-dependent
#:add-direct-method
#:add-direct-subclass
#:class-default-initargs
#:class-direct-default-initargs
#:class-direct-slots
#:class-direct-subclasses
#:class-direct-superclasses
#:class-finalized-p
#:class-precedence-list
#:class-prototype
#:class-slots
#:compute-applicable-methods-using-classes
#:compute-class-precedence-list
#:compute-default-initargs
#:compute-discriminating-function
#:compute-effective-method
#:compute-effective-slot-definition
#:compute-slots
#:direct-slot-definition-class
#:effective-slot-definition-class
#:ensure-class
#:ensure-class-using-class
#:ensure-generic-function-using-class
#:eql-specializer-object
#:extract-lambda-list
#:extract-specializer-names
#:finalize-inheritance
#:find-method-combination
#:funcallable-standard-instance-access
#:generic-function-argument-precedence-order
#:generic-function-declarations
#:generic-function-lambda-list
#:generic-function-method-class
#:generic-function-method-combination
#:generic-function-methods
#:generic-function-name
#:intern-eql-specializer
#:intern-eql-specializer*
#-clisp #:make-method-lambda
#:map-dependents
#:method-function
#:method-generic-function
#:method-lambda-list
#:method-specializers
#:reader-method-class
#:remove-dependent
#:remove-direct-method
#:remove-direct-subclass
#:set-funcallable-instance-function
#:slot-boundp-using-class
#:slot-definition-allocation
#:slot-definition-initargs
#:slot-definition-initform
#:slot-definition-initfunction
#:slot-definition-location
#:slot-definition-name
#:slot-definition-readers
#:slot-definition-writers
#:slot-definition-type
#:slot-makunbound-using-class
#:slot-value-using-class
#:specializer-direct-generic-functions
#:specializer-direct-methods
#:standard-instance-access
#:update-dependent
#:validate-superclass
#:writer-method-class))
(in-package :closer-mop)
(defun ensure-method (gf lambda-expression
&key (qualifiers ())
(lambda-list (cadr lambda-expression))
(specializers (loop for arg in lambda-list
until (member arg lambda-list-keywords)
collect (find-class 't))))
(funcall (compile nil `(lambda ()
(defmethod ,(generic-function-name gf) ,@qualifiers
,(loop for (arg . rest) on lambda-list
for specializer in specializers
collect `(,arg ,specializer) into args
finally (return (nconc args rest)))
,@(cddr lambda-expression))))))
;; The following can be used in direct-slot-definition-class to get the correct initargs
;; for a slot. Use it like this:
;;
;; (defmethod direct-slot-definition-class
;; ((class my-standard-class) &rest initargs)
;; (declare (dynamic-extent initargs))
;; (destructuring-bind
;; (&key key-of-interest &allow-other-keys)
;; (fix-slot-initargs initargs)
;; ...))
(defvar *standard-slot-keys*
'(:name :documentation
:initargs :initform :initfunction
:readers :writers))
(defun fix-slot-initargs (initargs)
initargs)
(eval-when (:compile-toplevel :load-toplevel :execute)
(pushnew :closer-mop *features*))
(in-package :cl-user)
(defpackage #:closer-common-lisp
(:nicknames #:c2cl)
(:use))
(let ((syms (nunion (loop for sym being the external-symbols of :common-lisp
if (find-symbol (symbol-name sym) :c2mop)
collect it
else collect sym)
(loop for sym being the external-symbols of :c2mop
collect sym))))
(import syms :c2cl)
(export syms :c2cl))
(defpackage #:closer-common-lisp-user
(:nicknames #:c2cl-user)
(:use #:closer-common-lisp))
(in-package :cl-user)
(asdf:defsystem #:closer-mop
:name "Closer to MOP"
:author "Pascal Costanza"
:version "0.2"
:licence "
Copyright (c) 2005 Pascal Costanza
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the \"Software\"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
:depends-on (#-lispworks "lw-compat")
:components
((:module
#+allegro "allegro"
#+clisp "clisp"
#+lispworks "lispworks"
#+mcl "mcl"
#+(or cmu sbcl) "pcl"
:components ((:file "closer-mop-packages")
(:file "closer-mop"
:depends-on ("closer-mop-packages"))))
(:file "closer-mop-utility-packages"
:depends-on (#+allegro "allegro"
#+clisp "clisp"
#+lispworks "lispworks"
#+mcl "mcl"
#+(or cmu sbcl) "pcl"))))
:allegro
:compute-default-initargs -> :compute-default-initargs-allegro (no)
:defgeneric-calls-find-method-combination (no)
:defmethod-calls-make-method-lambda (no)
:dependent-protocol-for-generic-functions (fixed)
:function-invocation-calls-compute-applicable-methods (redef sgf)
:function-invocation-calls-compute-applicable-methods-using-classes (redef sgf)
:function-invocation-calls-compute-effective-method (redef sgf)
:make-method-lambda (no)
:method-functions-take-processed-parameters (no)
:method-lambdas-are-processed (no)
:reinitialize-instance-calls-compute-discriminating-function (fixed)
:setf-class-name-calls-reinitialize-instance (no)
:setf-generic-function-name-class-reinitialize-intance (no)
:standard-class-and-funcallable-standard-class-are-compatible (no)
:t-is-always-a-valid-superclass (no)
:clisp
:accessor-method-initialized-with-function (no)
:add-method-calls-compute-discriminating-function (no)
:defmethod-calls-make-method-lambda (no)
:forward-referenced-class-changed-by-change-class (no)
:initialize-instance-calls-compute-discriminating-function (no)
:make-method-lambda (no)
:method-initialized-with-function (no)
:method-lambdas-are-processed (no)
:reinitialize-instance-calls-compute-discriminating-function (no)
:remove-method-calls-compute-discriminating-function (no)
:cmu
:accessor-method-initialized-with-function (fixed)
:accessor-method-initialized-with-lambda-list (fixed)
:accessor-method-initialized-with-slot-definition (fixed)
:accessor-method-initialized-with-specializers (fixed)
:anonymous-classes (fixed)
:class-initialization-calls-reader-method-class (fixed)
:class-initialization-calls-writer-method-class (fixed)
:dependent-protocol-for-generic-functions (fixed)
:documentation-passed-to-effective-slot-definition-class (redef sc)
:effective-slot-definition-initialized-with-documentation (redef sc)
:method-initialized-with-function (no)
:multiple-slot-options-passed-as-list-to-direct-slot-definition-class (fix with fix-slot-initargs)
:reinitialize-instance-calls-compute-discriminating-function (fixed)
:setf-class-name-calls-reinitialize-instance (no)
:setf-generic-function-name-calls-reinitialize-instance (no)
:standard-class-and-funcallable-standard-class-are-compatible (no)
:lispworks4.3
:accessor-method-initialized-with-function (not fixed)
:accessor-method-initialized-with-lambda-list