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