1 ;;;; basic environmental stuff
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from software originally released by Xerox
7 ;;;; Corporation. Copyright and release statements follow. Later modifications
8 ;;;; to the software are in the public domain and are provided with
9 ;;;; absolutely no warranty. See the COPYING and CREDITS files for more
12 ;;;; copyright information from original PCL sources:
14 ;;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
15 ;;;; All rights reserved.
17 ;;;; Use and copying of this software and preparation of derivative works based
18 ;;;; upon this software are permitted. Any distribution of this software or
19 ;;;; derivative works must comply with all applicable United States export
22 ;;;; This software is made available AS IS, and Xerox Corporation makes no
23 ;;;; warranty about the software, its performance or its conformity to any
28 ;;; FIXME: This stuff isn't part of the ANSI spec, and isn't even
29 ;;; exported from PCL, but it looks as though it might be useful,
30 ;;; so I don't want to just delete it. Perhaps it should go in
31 ;;; a "contrib" directory eventually?
34 ;;; TRACE-METHOD and UNTRACE-METHOD accept method specs as arguments. A
35 ;;; method-spec should be a list like:
36 ;;; (<generic-function-spec> qualifiers* (specializers*))
37 ;;; where <generic-function-spec> should be either a symbol or a list
38 ;;; of (SETF <symbol>).
40 ;;; For example, to trace the method defined by:
42 ;;; (defmethod foo ((x spaceship)) 'ss)
46 ;;; (trace-method '(foo (spaceship)))
48 ;;; You can also provide a method object in the place of the method
49 ;;; spec, in which case that method object will be traced.
51 ;;; For UNTRACE-METHOD, if an argument is given, that method is untraced.
52 ;;; If no argument is given, all traced methods are untraced.
53 (defclass traced-method (method)
54 ((method :initarg :method)
55 (function :initarg :function
56 :reader method-function)
57 (generic-function :initform nil
58 :accessor method-generic-function)))
60 (defmethod method-lambda-list ((m traced-method))
61 (with-slots (method) m (method-lambda-list method)))
63 (defmethod method-specializers ((m traced-method))
64 (with-slots (method) m (method-specializers method)))
66 (defmethod method-qualifiers ((m traced-method))
67 (with-slots (method) m (method-qualifiers method)))
69 (defmethod accessor-method-slot-name ((m traced-method))
70 (with-slots (method) m (accessor-method-slot-name method)))
72 (defvar *traced-methods* ())
74 (defun trace-method (spec &rest options)
75 (multiple-value-bind (gf omethod name)
76 (parse-method-or-spec spec)
77 (let* ((tfunction (trace-method-internal (method-function omethod)
80 (tmethod (make-instance 'traced-method
82 :function tfunction)))
83 (remove-method gf omethod)
84 (add-method gf tmethod)
85 (pushnew tmethod *traced-methods*)
88 (defun untrace-method (&optional spec)
90 (let ((gf (method-generic-function m)))
93 (add-method gf (slot-value m 'method))
94 (setq *traced-methods* (remove m *traced-methods*))))))
96 (multiple-value-bind (gf method)
97 (parse-method-or-spec spec)
99 (if (memq method *traced-methods*)
101 (error "~S is not a traced method?" method)))
102 (dolist (m *traced-methods*) (untrace-1 m)))))
104 (defun trace-method-internal (ofunction name options)
105 (eval `(untrace ,name))
106 (setf (fdefinition name) ofunction)
107 (eval `(trace ,name ,@options))
113 ;; Overwrite the old bootstrap non-generic MAKE-LOAD-FORM function with a
114 ;; shiny new generic function.
115 (fmakunbound 'make-load-form)
116 (defgeneric make-load-form (object &optional environment))
118 ;; Link bootstrap-time how-to-dump-it information into the shiny new
120 (defmethod make-load-form ((obj sb-sys:structure!object)
121 &optional (env nil env-p))
123 (sb-sys:structure!object-make-load-form obj env)
124 (sb-sys:structure!object-make-load-form obj)))
126 (defmethod make-load-form ((object wrapper) &optional env)
127 (declare (ignore env))
128 (let ((pname (sb-kernel:class-proper-name (sb-kernel:layout-class object))))
130 (error "can't dump wrapper for anonymous class:~% ~S"
131 (sb-kernel:layout-class object)))
132 `(sb-kernel:class-layout (cl:find-class ',pname))))
134 ;;;; The following are hacks to deal with CMU CL having two different CLASS
137 (defun coerce-to-pcl-class (class)
138 (if (typep class 'cl:class)
139 (or (sb-kernel:class-pcl-class class)
140 (find-structure-class (cl:class-name class)))
143 (defmethod make-instance ((class cl:class) &rest stuff)
144 (apply #'make-instance (coerce-to-pcl-class class) stuff))
145 (defmethod change-class (instance (class cl:class) &rest initargs)
146 (apply #'change-class instance (coerce-to-pcl-class class) initargs))
148 (macrolet ((frob (&rest names)
150 ,@(mapcar (lambda (name)
151 `(defmethod ,name ((class cl:class))
153 (coerce-to-pcl-class class))))
158 class-precedence-list
159 class-direct-default-initargs
160 class-direct-superclasses
161 compute-class-precedence-list
162 class-default-initargs class-finalized-p
163 class-direct-subclasses class-slots
164 make-instances-obsolete))