-;;;; very low-level representation of instances with meta-class
-;;;; STANDARD-CLASS
-
-;;; FIXME: more than one IN-PACKAGE in a source file, ick
-(in-package "SB-C")
-
-(defknown sb-pcl::pcl-instance-p (t) boolean
- (movable foldable flushable explicit-check))
-
-(deftransform sb-pcl::pcl-instance-p ((object))
- (let* ((otype (continuation-type object))
- (std-obj (specifier-type 'sb-pcl::std-object)))
- (cond
- ;; Flush tests whose result is known at compile time.
- ((csubtypep otype std-obj) 't)
- ((not (types-intersect otype std-obj)) 'nil)
- (t
- `(typep (sb-kernel:layout-of object) 'sb-pcl::wrapper)))))
-
-(in-package "SB-PCL")
-
-;;; FIXME: What do these do? Could we use SB-KERNEL:INSTANCE-REF instead?
-(defmacro %instance-ref (slots index)
- `(%svref ,slots ,index))
-(defmacro instance-ref (slots index)
- `(svref ,slots ,index))
-
-;;; Note on implementation under CMU CL >=17 and SBCL: STD-INSTANCE-P is
-;;; only used to discriminate between functions (including FINs) and
-;;; normal instances, so we can return true on structures also. A few
-;;; uses of (or std-instance-p fsc-instance-p) are changed to
-;;; pcl-instance-p.
+;;;; early definition of WRAPPER
+;;;;
+;;;; Most WRAPPER stuff is defined later, but the DEFSTRUCT itself
+;;;; is here early so that things like (TYPEP .. 'WRAPPER) can be
+;;;; compiled efficiently.
+
+;;; Note that for SBCL, as for CMU CL, the WRAPPER of a built-in or
+;;; structure class will be some other kind of SB-KERNEL:LAYOUT, but
+;;; this shouldn't matter, since the only two slots that WRAPPER adds
+;;; are meaningless in those cases.
+(defstruct (wrapper
+ (:include layout
+ ;; KLUDGE: In CMU CL, the initialization default
+ ;; for LAYOUT-INVALID was NIL. In SBCL, that has
+ ;; changed to :UNINITIALIZED, but PCL code might
+ ;; still expect NIL for the initialization
+ ;; default of WRAPPER-INVALID. Instead of trying
+ ;; to find out, I just overrode the LAYOUT
+ ;; default here. -- WHN 19991204
+ (invalid nil))
+ (:constructor make-wrapper-internal)
+ (:copier nil))
+ (instance-slots-layout nil :type list)
+ (class-slots nil :type list))
+#-sb-fluid (declaim (sb-ext:freeze-type wrapper))
+\f
+;;;; PCL's view of funcallable instances
+
+(!defstruct-with-alternate-metaclass standard-funcallable-instance
+ ;; KLUDGE: Note that neither of these slots is ever accessed by its
+ ;; accessor name as of sbcl-0.pre7.63. Presumably everything works
+ ;; by puns based on absolute locations. Fun fun fun.. -- WHN 2001-10-30
+ :slot-names (clos-slots name hash-code)
+ :boa-constructor %make-standard-funcallable-instance
+ :superclass-name function
+ :metaclass-name standard-classoid
+ :metaclass-constructor make-standard-classoid
+ :dd-type funcallable-structure
+ ;; Only internal implementation code will access these, and these
+ ;; accesses (slot readers in particular) could easily be a
+ ;; bottleneck, so it seems reasonable to suppress runtime type
+ ;; checks.
+ ;;
+ ;; (Except note KLUDGE above that these accessors aren't used at all
+ ;; (!) as of sbcl-0.pre7.63, so for now it's academic.)
+ :runtime-type-checks-p nil)
+
+(import 'sb-kernel:funcallable-instance-p)
+
+(defun set-funcallable-instance-function (fin new-value)
+ (declare (type function new-value))
+ (aver (funcallable-instance-p fin))
+ (setf (funcallable-instance-fun fin) new-value))
+;;; FIXME: these macros should just go away. It's not clear whether
+;;; the inline functions defined by
+;;; !DEFSTRUCT-WITH-ALTERNATE-METACLASS are as efficient as they could
+;;; be; ordinary defstruct accessors are defined as source transforms.
+(defmacro fsc-instance-p (fin)
+ `(funcallable-instance-p ,fin))
+(defmacro fsc-instance-wrapper (fin)
+ `(%funcallable-instance-layout ,fin))
+(defmacro fsc-instance-slots (fin)
+ `(%funcallable-instance-info ,fin 1))
+(defmacro fsc-instance-hash (fin)
+ `(%funcallable-instance-info ,fin 3))
+\f
+(declaim (inline clos-slots-ref (setf clos-slots-ref)))
+(declaim (ftype (function (simple-vector index) t) clos-slots-ref))
+(defun clos-slots-ref (slots index)
+ (svref slots index))
+(declaim (ftype (function (t simple-vector index) t) (setf clos-slots-ref)))
+(defun (setf clos-slots-ref) (new-value slots index)
+ (setf (svref slots index) new-value))
+
+;;; Note on implementation under CMU CL >=17 and SBCL: STD-INSTANCE-P
+;;; is only used to discriminate between functions (including FINs)
+;;; and normal instances, so we can return true on structures also. A
+;;; few uses of (OR STD-INSTANCE-P FSC-INSTANCE-P) are changed to
+;;; PCL-INSTANCE-P.