(cons nil nil))))
(values defstruct-form constructor reader-names writer-names)))
+(defun make-defstruct-allocation-function (class)
+ (let ((dd (get-structure-dd (class-name class))))
+ (lambda ()
+ (let ((instance (%make-instance (dd-length dd)))
+ (raw-index (dd-raw-index dd)))
+ (setf (%instance-layout instance)
+ (sb-kernel::compiler-layout-or-lose (dd-name dd)))
+ (when raw-index
+ (setf (%instance-ref instance raw-index)
+ (make-array (dd-raw-length dd)
+ :element-type '(unsigned-byte 32))))
+ instance))))
+
(defmethod shared-initialize :after
((class structure-class)
slot-names
(make-direct-slotd class pl))
direct-slots)))
(setq direct-slots (slot-value class 'direct-slots)))
- (when defstruct-p
- (let ((include (car (slot-value class 'direct-superclasses))))
- (multiple-value-bind (defstruct-form constructor reader-names writer-names)
- (make-structure-class-defstruct-form name direct-slots include)
- (unless (structure-type-p name) (eval defstruct-form))
- (mapc (lambda (dslotd reader-name writer-name)
- (let* ((reader (gdefinition reader-name))
- (writer (when (gboundp writer-name)
- (gdefinition writer-name))))
- (setf (slot-value dslotd 'internal-reader-function)
- reader)
- (setf (slot-value dslotd 'internal-writer-function)
- writer)))
- direct-slots reader-names writer-names)
- (setf (slot-value class 'defstruct-form) defstruct-form)
- (setf (slot-value class 'defstruct-constructor) constructor))))
+ (if defstruct-p
+ (let ((include (car (slot-value class 'direct-superclasses))))
+ (multiple-value-bind (defstruct-form constructor reader-names writer-names)
+ (make-structure-class-defstruct-form name direct-slots include)
+ (unless (structure-type-p name) (eval defstruct-form))
+ (mapc (lambda (dslotd reader-name writer-name)
+ (let* ((reader (gdefinition reader-name))
+ (writer (when (gboundp writer-name)
+ (gdefinition writer-name))))
+ (setf (slot-value dslotd 'internal-reader-function)
+ reader)
+ (setf (slot-value dslotd 'internal-writer-function)
+ writer)))
+ direct-slots reader-names writer-names)
+ (setf (slot-value class 'defstruct-form) defstruct-form)
+ (setf (slot-value class 'defstruct-constructor) constructor)))
+ (setf (slot-value class 'defstruct-constructor)
+ (make-defstruct-allocation-function class)))
(add-direct-subclasses class direct-superclasses)
(setf (slot-value class 'class-precedence-list)
(compute-class-precedence-list class))
(assert (= (slot-value x 'name) 1))
(assert (= (slot-value x 'cl-user::name) 2)))
\f
+;;; ALLOCATE-INSTANCE should work on structures, even if defined by
+;;; DEFSTRUCT (and not DEFCLASS :METACLASS STRUCTURE-CLASS).
+(defstruct allocatable-structure a)
+(assert (typep (allocate-instance (find-class 'allocatable-structure))
+ 'allocatable-structure))
+\f
;;;; success
(sb-ext:quit :unix-status 104)