0.8.18.14:
[sbcl.git] / src / code / target-defstruct.lisp
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
4 ;;;; This software is derived from the CMU CL system, which was
5 ;;;; written at Carnegie Mellon University and released into the
6 ;;;; public domain. The software is in the public domain and is
7 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
8 ;;;; files for more information.
9
10 (in-package "SB!KERNEL")
11
12 (/show0 "target-defstruct.lisp 12")
13 \f
14 ;;;; structure frobbing primitives
15
16 ;;; Allocate a new instance with LENGTH data slots.
17 (defun %make-instance (length)
18   (declare (type index length))
19   (%make-instance length))
20
21 ;;; Given an instance, return its length.
22 (defun %instance-length (instance)
23   (declare (type instance instance))
24   (%instance-length instance))
25
26 ;;; Return the value from the INDEXth slot of INSTANCE. This is SETFable.
27 (defun %instance-ref (instance index)
28   (%instance-ref instance index))
29
30 ;;; Set the INDEXth slot of INSTANCE to NEW-VALUE.
31 (defun %instance-set (instance index new-value)
32   (setf (%instance-ref instance index) new-value))
33
34 (defun %raw-ref-single (vec index)
35   (declare (type index index))
36   (%raw-ref-single vec index))
37
38 (defun %raw-ref-double (vec index)
39   (declare (type index index))
40   (%raw-ref-double vec index))
41
42 #!+long-float
43 (defun %raw-ref-long (vec index)
44   (declare (type index index))
45   (%raw-ref-long vec index))
46
47 (defun %raw-set-single (vec index val)
48   (declare (type index index))
49   (%raw-set-single vec index val))
50
51 (defun %raw-set-double (vec index val)
52   (declare (type index index))
53   (%raw-set-double vec index val))
54
55 #!+long-float
56 (defun %raw-set-long (vec index val)
57   (declare (type index index))
58   (%raw-set-long vec index val))
59
60 (defun %raw-ref-complex-single (vec index)
61   (declare (type index index))
62   (%raw-ref-complex-single vec index))
63
64 (defun %raw-ref-complex-double (vec index)
65   (declare (type index index))
66   (%raw-ref-complex-double vec index))
67
68 #!+long-float
69 (defun %raw-ref-complex-long (vec index)
70   (declare (type index index))
71   (%raw-ref-complex-long vec index))
72
73 (defun %raw-set-complex-single (vec index val)
74   (declare (type index index))
75   (%raw-set-complex-single vec index val))
76
77 (defun %raw-set-complex-double (vec index val)
78   (declare (type index index))
79   (%raw-set-complex-double vec index val))
80
81 #!+long-float
82 (defun %raw-set-complex-long (vec index val)
83   (declare (type index index))
84   (%raw-set-complex-long vec index val))
85
86 (defun %instance-layout (instance)
87   (%instance-layout instance))
88
89 (defun %set-instance-layout (instance new-value)
90   (%set-instance-layout instance new-value))
91
92 (defun %make-funcallable-instance (len layout)
93    (%make-funcallable-instance len layout))
94
95 (defun funcallable-instance-p (x) (funcallable-instance-p x))
96
97 (defun %funcallable-instance-info (fin i)
98   (%funcallable-instance-info fin i))
99
100 (defun %set-funcallable-instance-info (fin i new-value)
101   (%set-funcallable-instance-info fin i new-value))
102
103 (defun funcallable-instance-fun (fin)
104   (%funcallable-instance-lexenv fin))
105
106 ;;; The heart of the magic of funcallable instances ("FINs"). The
107 ;;; function for a FIN must be a magical INSTANCE-LAMBDA form. When
108 ;;; called (as with any other function), we grab the code pointer, and
109 ;;; call it, leaving the original function object in LEXENV (in case
110 ;;; it was a closure). If it is actually a FIN, then we need to do an
111 ;;; extra indirection with funcallable-instance-lexenv to get at any
112 ;;; closure environment. This extra indirection is set up when
113 ;;; accessing the closure environment of an INSTANCE-LAMBDA. Note that
114 ;;; the original FIN pointer is lost, so if the called function wants
115 ;;; to get at the original object to do some slot accesses, it must
116 ;;; close over the FIN object.
117 ;;;
118 ;;; If we set the FIN function to be a FIN, we directly copy across
119 ;;; both the code pointer and the lexenv, since that code pointer (for
120 ;;; an instance-lambda) is expecting that lexenv to be accessed. This
121 ;;; effectively pre-flattens what would otherwise be a chain of
122 ;;; indirections. (That used to happen when PCL dispatch functions
123 ;;; were byte-compiled; now that the byte compiler is gone, I can't
124 ;;; think of another example offhand. -- WHN 2001-10-06)
125 ;;;
126 ;;; The only loss is that if someone accesses the
127 ;;; FUNCALLABLE-INSTANCE-FUN, then won't get a FIN back. This probably
128 ;;; doesn't matter, since PCL only sets the FIN function.
129 (defun (setf funcallable-instance-fun) (new-value fin)
130   (setf (%funcallable-instance-fun fin)
131         (%closure-fun new-value))
132   (setf (%funcallable-instance-lexenv fin)
133         (if (funcallable-instance-p new-value)
134             (%funcallable-instance-lexenv new-value)
135             new-value)))
136
137 ;;; service function for structure constructors
138 (defun %make-instance-with-layout (layout)
139   (let ((result (%make-instance (layout-length layout))))
140     (setf (%instance-layout result) layout)
141     result))
142 \f
143 ;;;; target-only parts of the DEFSTRUCT top level code
144
145 ;;; A list of hooks designating functions of one argument, the
146 ;;; classoid, to be called when a defstruct is evaluated.
147 (defvar *defstruct-hooks* nil)
148
149 ;;; Catch attempts to mess up definitions of symbols in the CL package.
150 (defun protect-cl (symbol)
151   (/show0 "entering PROTECT-CL, SYMBOL=..")
152   (/hexstr symbol)
153   (when (and *cold-init-complete-p*
154              (eq (symbol-package symbol) *cl-package*))
155     (cerror "Go ahead and patch the system."
156             "attempting to modify a symbol in the COMMON-LISP package: ~S"
157             symbol))
158   (/show0 "leaving PROTECT-CL")
159   (values))
160
161 ;;; the part of %DEFSTRUCT which makes sense only on the target SBCL
162 ;;;
163 ;;; (The "static" in the name is because it needs to be done not only
164 ;;; in ordinary toplevel %DEFSTRUCT, but also in cold init as early as
165 ;;; possible, to simulate static linking of structure functions as
166 ;;; nearly as possible.)
167 (defun %target-defstruct (dd layout)
168   (declare (type defstruct-description dd))
169   (declare (type layout layout))
170
171   (/show0 "entering %TARGET-DEFSTRUCT")
172
173   (remhash (dd-name dd) *typecheckfuns*)
174
175   ;; (Constructors aren't set up here, because constructors are
176   ;; varied enough (possibly parsing any specified argument list)
177   ;; that we can't reasonably implement them as closures, so we
178   ;; implement them with DEFUN instead.)
179
180   ;; Set FDEFINITIONs for slot accessors.
181   (dolist (dsd (dd-slots dd))
182     (/show0 "doing FDEFINITION for slot accessor")
183     (let ((accessor-name (dsd-accessor-name dsd)))
184       ;; We mustn't step on any inherited accessors
185       (unless (accessor-inherited-data accessor-name dd)
186         (/show0 "ACCESSOR-NAME=..")
187         (/hexstr accessor-name)
188         (protect-cl accessor-name)
189         (/hexstr "getting READER-FUN and WRITER-FUN")
190         (multiple-value-bind (reader-fun writer-fun)
191             (slot-accessor-funs dd dsd)
192           (declare (type function reader-fun writer-fun))
193           (/show0 "got READER-FUN and WRITER-FUN=..")
194           (/hexstr reader-fun)
195           (setf (symbol-function accessor-name) reader-fun)
196           (unless (dsd-read-only dsd)
197             (/show0 "setting FDEFINITION for WRITER-FUN=..")
198             (/hexstr writer-fun)
199             (setf (fdefinition `(setf ,accessor-name)) writer-fun))))))
200
201   ;; Set FDEFINITION for copier.
202   (when (dd-copier-name dd)
203     (/show0 "doing FDEFINITION for copier")
204     (protect-cl (dd-copier-name dd))
205     ;; We can't use COPY-STRUCTURE for other kinds of objects, notably
206     ;; funcallable structures, since it returns a STRUCTURE-OBJECT.
207     ;; (And funcallable instances don't need copiers anyway.)
208     (aver (eql (dd-type dd) 'structure))
209     (setf (symbol-function (dd-copier-name dd))
210           ;; FIXME: should use a closure which checks arg type before copying
211           #'copy-structure))
212
213   ;; Set FDEFINITION for predicate.
214   (when (dd-predicate-name dd)
215     (/show0 "doing FDEFINITION for predicate")
216     (protect-cl (dd-predicate-name dd))
217     (setf (symbol-function (dd-predicate-name dd))
218           (ecase (dd-type dd)
219             ;; structures with LAYOUTs
220             ((structure funcallable-structure)
221              (/show0 "with-LAYOUT case")
222              (lambda (object)
223                (locally ; <- to keep SAFETY 0 from affecting arg count checking
224                  (declare (optimize (speed 3) (safety 0)))
225                  (/noshow0 "in with-LAYOUT structure predicate closure, OBJECT,LAYOUT=..")
226                  (/nohexstr object)
227                  (/nohexstr layout)
228                  (typep-to-layout object layout))))
229             ;; structures with no LAYOUT (i.e. :TYPE VECTOR or :TYPE LIST)
230             ;;
231             ;; FIXME: should handle the :NAMED T case in these cases
232             (vector
233              (/show0 ":TYPE VECTOR case")
234              #'vectorp)
235             (list
236              (/show0 ":TYPE LIST case")
237              #'listp))))
238
239   (when (dd-doc dd)
240     (setf (fdocumentation (dd-name dd) 'type)
241           (dd-doc dd)))
242
243   ;; the BOUNDP test here is to get past cold-init.
244   (when (boundp '*defstruct-hooks*)
245     (dolist (fun *defstruct-hooks*)
246       (funcall fun (find-classoid (dd-name dd)))))
247   
248   (/show0 "leaving %TARGET-DEFSTRUCT")
249   (values))
250 \f
251 ;;;; generating out-of-line slot accessor functions
252
253 ;;; FIXME: Ideally, the presence of the type checks in the functions
254 ;;; here would be conditional on the optimization policy at the point
255 ;;; of expansion of DEFSTRUCT. (For now we're just doing the simpler
256 ;;; thing, putting in the type checks unconditionally.)
257
258 ;;; Return (VALUES SLOT-READER-FUN SLOT-WRITER-FUN).
259 (defun slot-accessor-funs (dd dsd)
260
261   #+sb-xc (/show0 "entering SLOT-ACCESSOR-FUNS")
262
263   ;; various code generators
264   ;;
265   ;; Note: They're only minimally parameterized, and cavalierly grab
266   ;; things like INSTANCE and DSD-INDEX from the namespace they're
267   ;; expanded in.
268   (macrolet (;; code shared between funcallable instance case and the
269              ;; ordinary STRUCTURE-OBJECT case: Handle native
270              ;; structures with LAYOUTs and (possibly) raw slots.
271              (%native-slot-accessor-funs (dd-ref-fun-name)
272                (let ((instance-type-check-form
273                       '(%check-structure-type-from-layout instance layout)))
274                  (/show "macroexpanding %NATIVE-SLOT-ACCESSOR-FUNS" dd-ref-fun-name instance-type-check-form)
275                  `(let ((layout (dd-layout-or-lose dd))
276                         (dsd-raw-type (dsd-raw-type dsd)))
277                     #+sb-xc (/show0 "in %NATIVE-SLOT-ACCESSOR-FUNS macroexpanded code")
278                     ;; Map over all the possible RAW-TYPEs, compiling
279                     ;; a different closure function for each one, so
280                     ;; that once the COND over RAW-TYPEs happens (at
281                     ;; the time closure is allocated) there are no
282                     ;; more decisions to be made and things execute
283                     ;; reasonably efficiently.
284                     (cond
285                      ;; nonraw slot case
286                      ((eql dsd-raw-type t)
287                       #+sb-xc (/show0 "in nonraw slot case")
288                       (%slotplace-accessor-funs
289                        (,dd-ref-fun-name instance dsd-index)
290                        ,instance-type-check-form))
291                      ;; raw slot cases
292                      ,@(mapcar (lambda (rtd)
293                                  (let ((raw-type (raw-slot-data-raw-type rtd))
294                                        (accessor-name
295                                         (raw-slot-data-accessor-name rtd))
296                                        (n-words (raw-slot-data-n-words rtd)))
297                                    `((equal dsd-raw-type ',raw-type)
298                                      #+sb-xc (/show0 "in raw slot case")
299                                      (let ((raw-index (dd-raw-index dd)))
300                                        (multiple-value-bind (scaled-dsd-index
301                                                              misalignment)
302                                            (floor dsd-index ,n-words)
303                                          (aver (zerop misalignment))
304                                          (%slotplace-accessor-funs
305                                           (,accessor-name (,dd-ref-fun-name
306                                                            instance
307                                                            raw-index)
308                                                           scaled-dsd-index)
309                                           ,instance-type-check-form))))))
310                                *raw-slot-data-list*)
311                      ;; oops
312                      (t
313                       (bug "unexpected DSD-RAW-TYPE ~S" dsd-raw-type))))))
314              ;; code shared between DEFSTRUCT :TYPE LIST and
315              ;; DEFSTRUCT :TYPE VECTOR cases: Handle the "typed
316              ;; structure" case, with no LAYOUTs and no raw slots.
317              (%colontyped-slot-accessor-funs () (error "stub")) 
318              ;; the common structure of the raw-slot and not-raw-slot
319              ;; cases, defined in terms of the writable SLOTPLACE. All
320              ;; possible flavors of slot access should be able to pass
321              ;; through here.
322              (%slotplace-accessor-funs (slotplace instance-type-check-form)
323                (/show "macroexpanding %SLOTPLACE-ACCESSOR-FUNS" slotplace instance-type-check-form)
324                `(let ((typecheckfun (typespec-typecheckfun dsd-type)))
325                   (values (if (dsd-safe-p dsd)
326                               (lambda (instance)
327                                 (/noshow0 "in %SLOTPLACE-ACCESSOR-FUNS-defined reader")
328                                 ,instance-type-check-form
329                                 (/noshow0 "back from INSTANCE-TYPE-CHECK-FORM")
330                                 ,slotplace)
331                               (lambda (instance)
332                                 (/noshow0 "in %SLOTPLACE-ACCESSOR-FUNS-defined reader")
333                                 ,instance-type-check-form
334                                 (/noshow0 "back from INSTANCE-TYPE-CHECK-FORM")
335                                 (let ((value ,slotplace))
336                                   (funcall typecheckfun value)
337                                   value)))
338                           (lambda (new-value instance)
339                             (/noshow0 "in %SLOTPLACE-ACCESSOR-FUNS-defined writer")
340                             ,instance-type-check-form
341                             (/noshow0 "back from INSTANCE-TYPE-CHECK-FORM")
342                             (funcall typecheckfun new-value)
343                             (/noshow0 "back from TYPECHECKFUN")
344                             (setf ,slotplace new-value))))))
345
346     (let ((dsd-index (dsd-index dsd))
347           (dsd-type (dsd-type dsd)))
348
349       #+sb-xc (/show0 "got DSD-TYPE=..")
350       #+sb-xc (/hexstr dsd-type)
351       (ecase (dd-type dd)
352
353         ;; native structures
354         (structure
355          #+sb-xc (/show0 "case of DSD-TYPE = STRUCTURE")
356          (%native-slot-accessor-funs %instance-ref))
357
358         ;; structures with the :TYPE option
359
360         ;; FIXME: Worry about these later..
361         #|
362         ;; In :TYPE LIST and :TYPE VECTOR structures, ANSI specifies the
363         ;; layout completely, so that raw slots are impossible.
364         (list
365          (dd-type-slot-accessor-funs nth-but-with-sane-arg-order
366                                  `(%check-structure-type-from-dd
367                                  :maybe-raw-p nil))
368         (vector
369          (dd-type-slot-accessor-funs aref
370                                  :maybe-raw-p nil)))
371         |#
372         ))))
373 \f
374 ;;; Copy any old kind of structure.
375 (defun copy-structure (structure)
376   #!+sb-doc
377   "Return a copy of STRUCTURE with the same (EQL) slot values."
378   (declare (type structure-object structure))
379   (let* ((len (%instance-length structure))
380          (res (%make-instance len))
381          (layout (%instance-layout structure)))
382
383     (declare (type index len))
384     (when (layout-invalid layout)
385       (error "attempt to copy an obsolete structure:~%  ~S" structure))
386
387     ;; Copy ordinary slots.
388     (dotimes (i len)
389       (declare (type index i))
390       (setf (%instance-ref res i)
391             (%instance-ref structure i)))
392
393     ;; Copy raw slots.
394     (let ((raw-index (dd-raw-index (layout-info layout))))
395       (when raw-index
396         (let* ((data (%instance-ref structure raw-index))
397                (raw-len (length data))
398                (new (make-array raw-len :element-type 'sb!vm::word)))
399           (declare (type (simple-array sb!vm::word (*)) data))
400           (setf (%instance-ref res raw-index) new)
401           (dotimes (i raw-len)
402             (setf (aref new i) (aref data i))))))
403
404     res))
405 \f
406 ;;; default PRINT-OBJECT method
407
408 (defun %default-structure-pretty-print (structure stream)
409   (let* ((layout (%instance-layout structure))
410          (name (classoid-name (layout-classoid layout)))
411          (dd (layout-info layout)))
412     ;; KLUDGE: during the build process with SB-SHOW, we can sometimes
413     ;; attempt to print out a PCL object (with null LAYOUT-INFO).
414     #!+sb-show
415     (when (null dd)
416       (pprint-logical-block (stream nil :prefix "#<" :suffix ">")
417         (prin1 name stream)
418         (write-char #\space stream)
419         (write-string "(no LAYOUT-INFO)"))
420       (return-from %default-structure-pretty-print nil))
421     ;; the structure type doesn't count as a component for
422     ;; *PRINT-LEVEL* processing.  We can likewise elide the logical
423     ;; block processing, since all we have to print is the type name.
424     ;; -- CSR, 2004-10-05
425     (when (and dd (null (dd-slots dd)))
426       (write-string "#S(" stream)
427       (prin1 name stream)
428       (write-char #\) stream)
429       (return-from %default-structure-pretty-print nil))
430     (pprint-logical-block (stream nil :prefix "#S(" :suffix ")")
431       (prin1 name stream)
432       (let ((remaining-slots (dd-slots dd)))
433         (when remaining-slots
434           (write-char #\space stream)
435           ;; CMU CL had (PPRINT-INDENT :BLOCK 2 STREAM) here,
436           ;; but I can't see why. -- WHN 20000205
437           (pprint-newline :linear stream)
438           (loop
439            (pprint-pop)
440            (let ((slot (pop remaining-slots)))
441              (write-char #\: stream)
442              (output-symbol-name (symbol-name (dsd-name slot)) stream)
443              (write-char #\space stream)
444              (pprint-newline :miser stream)
445              (output-object (funcall (fdefinition (dsd-accessor-name slot))
446                                      structure)
447                             stream)
448              (when (null remaining-slots)
449                (return))
450              (write-char #\space stream)
451              (pprint-newline :linear stream))))))))
452 (defun %default-structure-ugly-print (structure stream)
453   (let* ((layout (%instance-layout structure))
454          (name (classoid-name (layout-classoid layout)))
455          (dd (layout-info layout)))
456     (when (and dd (null (dd-slots dd)))
457       (write-string "#S(" stream)
458       (prin1 name stream)
459       (write-char #\) stream)
460       (return-from %default-structure-ugly-print nil))
461     (descend-into (stream)
462       (write-string "#S(" stream)
463       (prin1 name stream)
464       (do ((index 0 (1+ index))
465            (remaining-slots (dd-slots dd) (cdr remaining-slots)))
466           ((or (null remaining-slots)
467                (and (not *print-readably*)
468                     *print-length*
469                     (>= index *print-length*)))
470            (if (null remaining-slots)
471                (write-string ")" stream)
472                (write-string " ...)" stream)))
473         (declare (type index index))
474         (write-char #\space stream)
475         (write-char #\: stream)
476         (let ((slot (first remaining-slots)))
477           (output-symbol-name (symbol-name (dsd-name slot)) stream)
478           (write-char #\space stream)
479           (output-object
480            (funcall (fdefinition (dsd-accessor-name slot))
481                     structure)
482            stream))))))
483 (defun default-structure-print (structure stream depth)
484   (declare (ignore depth))
485   (cond ((funcallable-instance-p structure)
486          (print-unreadable-object (structure stream :identity t :type t)))
487         (*print-pretty*
488          (%default-structure-pretty-print structure stream))
489         (t
490          (%default-structure-ugly-print structure stream))))
491 (def!method print-object ((x structure-object) stream)
492   (default-structure-print x stream *current-level-in-print*))
493 \f
494 ;;;; testing structure types
495
496 ;;; Return true if OBJ is an object of the structure type
497 ;;; corresponding to LAYOUT. This is called by the accessor closures,
498 ;;; which have a handle on the type's LAYOUT.
499 ;;;
500 ;;; FIXME: This is fairly big, so it should probably become
501 ;;; MAYBE-INLINE instead of INLINE, or its inlineness should become
502 ;;; conditional (probably through DEFTRANSFORM) on (> SPEED SPACE). Or
503 ;;; else we could fix things up so that the things which call it are
504 ;;; all closures, so that it's expanded only in a small number of
505 ;;; places.
506 #!-sb-fluid (declaim (inline typep-to-layout))
507 (defun typep-to-layout (obj layout)
508   (declare (type layout layout) (optimize (speed 3) (safety 0)))
509   (/noshow0 "entering TYPEP-TO-LAYOUT, OBJ,LAYOUT=..")
510   (/nohexstr obj)
511   (/nohexstr layout)
512   (when (layout-invalid layout)
513     (error "An obsolete structure accessor function was called."))
514   (/noshow0 "back from testing LAYOUT-INVALID LAYOUT")
515   ;; FIXME: CMU CL used (%INSTANCEP OBJ) here. Check that
516   ;; (TYPEP OBJ 'INSTANCE) is optimized to equally efficient code.
517   (and (typep obj 'instance)
518        (let ((obj-layout (%instance-layout obj)))
519          (cond ((eq obj-layout layout)
520                 ;; (In this case OBJ-LAYOUT can't be invalid, because
521                 ;; we determined LAYOUT is valid in the test above.)
522                 (/noshow0 "EQ case")
523                 t)
524                ((layout-invalid obj-layout)
525                 (/noshow0 "LAYOUT-INVALID case")
526                 (error 'layout-invalid
527                        :expected-type (layout-classoid obj-layout)
528                        :datum obj))
529                (t
530                 (let ((depthoid (layout-depthoid layout)))
531                   (/noshow0 "DEPTHOID case, DEPTHOID,LAYOUT-INHERITS=..")
532                   (/nohexstr depthoid)
533                   (/nohexstr layout-inherits)
534                   (and (> (layout-depthoid obj-layout) depthoid)
535                        (eq (svref (layout-inherits obj-layout) depthoid)
536                            layout))))))))
537 \f
538 ;;;; checking structure types
539
540 ;;; Check that X is an instance of the named structure type.
541 (defmacro %check-structure-type-from-name (x name)
542   `(%check-structure-type-from-layout ,x ,(compiler-layout-or-lose name)))
543
544 ;;; Check that X is a structure of the type described by DD.
545 (defmacro %check-structure-type-from-dd (x dd)
546   (declare (type defstruct-description dd))
547   (let ((class-name (dd-name dd)))
548     (ecase (dd-type dd)
549       ((structure funcallable-instance)
550        `(%check-structure-type-from-layout
551          ,x
552          ,(compiler-layout-or-lose class-name)))
553       ((vector)
554        (with-unique-names (xx)
555          `(let ((,xx ,x))
556             (declare (type vector ,xx))
557             ,@(when (dd-named dd)
558                 `((unless (eql (aref ,xx 0) ',class-name)
559                     (error
560                      'simple-type-error
561                      :datum (aref ,xx 0)
562                      :expected-type `(member ,class-name)
563                      :format-control
564                      "~@<missing name in instance of ~
565                       VECTOR-typed structure ~S: ~2I~_S~:>"
566                      :format-arguments (list ',class-name ,xx)))))
567             (values))))
568       ((list)
569        (with-unique-names (xx)
570          `(let ((,xx ,x))
571             (declare (type list ,xx))
572             ,@(when (dd-named dd)
573                 `((unless (eql (first ,xx) ',class-name)
574                     (error
575                      'simple-type-error
576                      :datum (aref ,xx 0)
577                      :expected-type `(member ,class-name)
578                      :format-control
579                      "~@<missing name in instance of LIST-typed structure ~S: ~
580                       ~2I~_S~:>"
581                      :format-arguments (list ',class-name ,xx)))))
582             (values)))))))
583
584 ;;; Check that X is an instance of the structure class with layout LAYOUT.
585 (defun %check-structure-type-from-layout (x layout)
586   (unless (typep-to-layout x layout)
587     (error 'type-error
588            :datum x
589            :expected-type (classoid-name (layout-classoid layout))))
590   (values))
591 \f
592 (/show0 "target-defstruct.lisp end of file")