-(defun find-classoid (name &optional (errorp t) environment)
- #!+sb-doc
- "Return the class with the specified NAME. If ERRORP is false, then NIL is
- returned when no such class exists."
- (declare (type symbol name) (ignore environment))
- (let ((res (classoid-cell-classoid (find-classoid-cell name))))
- (if (or res (not errorp))
- res
- (error "class not yet defined:~% ~S" name))))
-(defun (setf find-classoid) (new-value name)
- #-sb-xc (declare (type (or null classoid) new-value))
- (cond
- ((null new-value)
- (ecase (info :type :kind name)
- ((nil))
- (:defined)
- (:primitive
- (error "attempt to redefine :PRIMITIVE type: ~S" name))
- ((:forthcoming-defclass-type :instance)
- (setf (info :type :kind name) nil
- (info :type :classoid name) nil
- (info :type :documentation name) nil
- (info :type :compiler-layout name) nil))))
- (t
- (ecase (info :type :kind name)
- ((nil))
- (:forthcoming-defclass-type
- ;; XXX Currently, nothing needs to be done in this
- ;; case. Later, when PCL is integrated tighter into SBCL, this
- ;; might need more work.
- nil)
- (:instance
- ;; KLUDGE: The reason these clauses aren't directly parallel
- ;; is that we need to use the internal CLASSOID structure
- ;; ourselves, because we don't have CLASSes to work with until
- ;; PCL is built. In the host, CLASSes have an approximately
- ;; one-to-one correspondence with the target CLASSOIDs (as
- ;; well as with the target CLASSes, modulo potential
- ;; differences with respect to conditions).
- #+sb-xc-host
- (let ((old (class-of (find-classoid name)))
- (new (class-of new-value)))
- (unless (eq old new)
- (bug "trying to change the metaclass of ~S from ~S to ~S in the ~
- cross-compiler."
- name (class-name old) (class-name new))))
- #-sb-xc-host
- (let ((old (classoid-of (find-classoid name)))
- (new (classoid-of new-value)))
- (unless (eq old new)
- (warn "changing meta-class of ~S from ~S to ~S"
- name (classoid-name old) (classoid-name new)))))
- (:primitive
- (error "illegal to redefine standard type ~S" name))
- (:defined
- (warn "redefining DEFTYPE type to be a class: ~S" name)
- (setf (info :type :expander name) nil)))
-
- (remhash name *forward-referenced-layouts*)
- (%note-type-defined name)
- (setf (info :type :kind name) :instance)
- (setf (classoid-cell-classoid (find-classoid-cell name)) new-value)
- (unless (eq (info :type :compiler-layout name)
- (classoid-layout new-value))
- (setf (info :type :compiler-layout name) (classoid-layout new-value)))))
- new-value)
-) ; EVAL-WHEN
-
+
+ ;; Return the classoid with the specified NAME. If ERRORP is false,
+ ;; then NIL is returned when no such class exists."
+ (defun find-classoid (name &optional (errorp t))
+ (declare (type symbol name))
+ (let ((cell (find-classoid-cell name :errorp errorp)))
+ (when cell (classoid-cell-classoid cell))))
+
+ (defun (setf find-classoid) (new-value name)
+ #-sb-xc (declare (type (or null classoid) new-value))
+ (aver new-value)
+ (let ((table *forward-referenced-layouts*))
+ (with-world-lock ()
+ (let ((cell (find-classoid-cell name :create t)))
+ (ecase (info :type :kind name)
+ ((nil))
+ (:forthcoming-defclass-type
+ ;; FIXME: Currently, nothing needs to be done in this case.
+ ;; Later, when PCL is integrated tighter into SBCL, this
+ ;; might need more work.
+ nil)
+ (:instance
+ (aver cell)
+ (let ((old-value (classoid-cell-classoid cell)))
+ (aver old-value)
+ ;; KLUDGE: The reason these clauses aren't directly
+ ;; parallel is that we need to use the internal
+ ;; CLASSOID structure ourselves, because we don't
+ ;; have CLASSes to work with until PCL is built. In
+ ;; the host, CLASSes have an approximately
+ ;; one-to-one correspondence with the target
+ ;; CLASSOIDs (as well as with the target CLASSes,
+ ;; modulo potential differences with respect to
+ ;; conditions).
+ #+sb-xc-host
+ (let ((old (class-of old-value))
+ (new (class-of new-value)))
+ (unless (eq old new)
+ (bug "Trying to change the metaclass of ~S from ~S to ~S in the ~
+ cross-compiler."
+ name (class-name old) (class-name new))))
+ #-sb-xc-host
+ (let ((old (classoid-of old-value))
+ (new (classoid-of new-value)))
+ (unless (eq old new)
+ (warn "Changing meta-class of ~S from ~S to ~S."
+ name (classoid-name old) (classoid-name new))))))
+ (:primitive
+ (error "Cannot redefine standard type ~S." name))
+ (:defined
+ (warn "Redefining DEFTYPE type to be a class: ~S" name)
+ (setf (info :type :expander name) nil
+ (info :type :lambda-list name) nil
+ (info :type :source-location name) nil)))
+
+ (remhash name table)
+ (%note-type-defined name)
+ ;; we need to handle things like
+ ;; (setf (find-class 'foo) (find-class 'integer))
+ ;; and
+ ;; (setf (find-class 'integer) (find-class 'integer))
+ (cond ((built-in-classoid-p new-value)
+ (setf (info :type :kind name)
+ (or (info :type :kind name) :defined))
+ (let ((translation (built-in-classoid-translation new-value)))
+ (when translation
+ (setf (info :type :translator name)
+ (lambda (c) (declare (ignore c)) translation)))))
+ (t
+ (setf (info :type :kind name) :instance)))
+ (setf (classoid-cell-classoid cell) new-value)
+ (unless (eq (info :type :compiler-layout name)
+ (classoid-layout new-value))
+ (setf (info :type :compiler-layout name)
+ (classoid-layout new-value))))))
+ new-value)
+
+ (defun %clear-classoid (name cell)
+ (ecase (info :type :kind name)
+ ((nil))
+ (:defined)
+ (:primitive
+ (error "Attempt to remove :PRIMITIVE type: ~S" name))
+ ((:forthcoming-defclass-type :instance)
+ (when cell
+ ;; Note: We cannot remove the classoid cell from the table,
+ ;; since compiled code may refer directly to the cell, and
+ ;; getting a different cell for a classoid with the same name
+ ;; just would not do.
+
+ ;; Remove the proper name of the classoid.
+ (setf (classoid-name (classoid-cell-classoid cell)) nil)
+ ;; Clear the cell.
+ (setf (classoid-cell-classoid cell) nil
+ (classoid-cell-pcl-class cell) nil))
+ (setf (info :type :kind name) nil
+ (info :type :documentation name) nil
+ (info :type :compiler-layout name) nil)))))
+