-;;;; 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.
+;;;; PCL's view of funcallable instances
+
+(defstruct (pcl-funcallable-instance
+ (:alternate-metaclass sb-kernel:funcallable-instance
+ sb-kernel:random-pcl-class
+ sb-kernel:make-random-pcl-class)
+ (:type sb-kernel:funcallable-structure)
+ (:constructor allocate-funcallable-instance-1 ())
+ (:copier nil)
+ (:conc-name nil))
+ ;; Note: The PCL wrapper is in the layout slot.
+
+ ;; PCL data vector.
+ (pcl-funcallable-instance-slots nil)
+ ;; The debug-name for this function.
+ (funcallable-instance-name nil))
+
+(import 'sb-kernel:funcallable-instance-p)
+
+;;; This "works" on non-PCL FINs, which allows us to weaken
+;;; FUNCALLABLE-INSTANCE-P to return true for all FINs. This is also
+;;; necessary for bootstrapping to work, since the layouts for early
+;;; GFs are not initially initialized.
+(defmacro funcallable-instance-data-1 (fin slot)
+ (ecase (eval slot)
+ (wrapper `(sb-kernel:%funcallable-instance-layout ,fin))
+ (slots `(sb-kernel:%funcallable-instance-info ,fin 0))))
+
+;;; FIXME: Now that we no longer try to make our CLOS implementation
+;;; portable to other implementations of Common Lisp, all the
+;;; funcallable instance wrapper logic here can go away in favor
+;;; of direct calls to native SBCL funcallable instance operations.
+(defun set-funcallable-instance-function (fin new-value)
+ (declare (type function new-value))
+ (aver (funcallable-instance-p fin))
+ (setf (sb-kernel:funcallable-instance-function fin) new-value))
+(defmacro fsc-instance-p (fin)
+ `(funcallable-instance-p ,fin))
+(defmacro fsc-instance-class (fin)
+ `(wrapper-class (funcallable-instance-data-1 ,fin 'wrapper)))
+(defmacro fsc-instance-wrapper (fin)
+ `(funcallable-instance-data-1 ,fin 'wrapper))
+(defmacro fsc-instance-slots (fin)
+ `(funcallable-instance-data-1 ,fin 'slots))
+\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.