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