/[cmucl]/src/code/defstruct.lisp
ViewVC logotype

Contents of /src/code/defstruct.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.67 - (hide annotations)
Mon Sep 20 11:12:59 1999 UTC (14 years, 7 months ago) by pw
Branch: MAIN
Changes since 1.66: +46 -41 lines
DEFAULT-STRUCTURE-PRINT was puking on certain cases of structures that
included other defstructs. An example of a failing case is:

(defstruct a1 s1)
(defstruct (a2 (:include a1)(:conc-name a1-)) s2)

as seen in Hemlock source. The problem was that the dsd-accessor slot
is documented to sometimes contain NIL but default-structure-print
blindly called fdefinition on the sometimes NIL value. The fix here
is to compute the slot accessor name from the conc-name and slot-name.

NOTE: There is code in ir1tran that also blindly calls fdefinition
on the contents of dsd-accessor. Don't know if this is a latent bug.
1 dtc 1.59 ;;; -*- Mode: Lisp; Package: KERNEL -*-
2 ram 1.1 ;;;
3     ;;; **********************************************************************
4 ram 1.22 ;;; This code was written as part of the CMU Common Lisp project at
5     ;;; Carnegie Mellon University, and has been placed in the public domain.
6     ;;;
7     (ext:file-comment
8 pw 1.67 "$Header: /tiger/var/lib/cvsroots/cmucl/src/code/defstruct.lisp,v 1.67 1999/09/20 11:12:59 pw Exp $")
9 ram 1.22 ;;;
10 ram 1.1 ;;; **********************************************************************
11     ;;;
12 ram 1.38 ;;; Defstruct structure definition package (Mark III).
13     ;;; Written by Rob MacLachlan, William Lott and Skef Wholey.
14 ram 1.1 ;;;
15 ram 1.35 (in-package "LISP")
16 ram 1.38 (export '(defstruct copy-structure structure-object))
17     (in-package "KERNEL")
18 dtc 1.60 (export '(default-structure-print make-structure-load-form
19 ram 1.38 %compiler-defstruct %%compiler-defstruct
20 ram 1.50 %compiler-only-defstruct
21 ram 1.38 %make-instance
22     %instance-length %instance-ref %instance-set %instance-layout
23 ram 1.40 %set-instance-layout
24     %make-funcallable-instance %funcallable-instance-info
25     %set-funcallable-instance-info
26     funcallable-instance-function funcallable-structure
27     funcallable-instance-p
28 ram 1.38 %raw-ref-single %raw-set-single
29     %raw-ref-double %raw-set-double
30     defstruct-description dd-name dd-default-constructor dd-copier
31     dd-predicate dd-slots dd-length dd-type dd-raw-index dd-raw-length
32     defstruct-slot-description dsd-name dsd-%name dsd-accessor dsd-type
33     dsd-index dsd-raw-type dsd-read-only undefine-structure))
34 ram 1.1
35 wlott 1.13
36     ;;;; Structure frobbing primitives.
37    
38 ram 1.38 (defun %make-instance (length)
39     "Allocate a new instance with LENGTH data slots."
40 wlott 1.18 (declare (type index length))
41 ram 1.38 (%make-instance length))
42 ram 1.1
43 ram 1.38 (defun %instance-length (instance)
44     "Given an instance, return its length."
45     (declare (type instance instance))
46     (%instance-length instance))
47 wlott 1.13
48 ram 1.38 (defun %instance-ref (instance index)
49     "Return the value from the INDEXth slot of INSTANCE. This is SETFable."
50     (%instance-ref instance index))
51 wlott 1.13
52 ram 1.38 (defun %instance-set (instance index new-value)
53     "Set the INDEXth slot of INSTANCE to NEW-VALUE."
54     (setf (%instance-ref instance index) new-value))
55 wlott 1.13
56 ram 1.38 (defun %raw-ref-single (vec index)
57     (declare (type index index))
58     (%raw-ref-single vec index))
59 wlott 1.13
60 ram 1.38 (defun %raw-ref-double (vec index)
61     (declare (type index index))
62     (%raw-ref-double vec index))
63 wlott 1.13
64 dtc 1.61 #+long-float
65     (defun %raw-ref-long (vec index)
66     (declare (type index index))
67     (%raw-ref-long vec index))
68    
69 ram 1.38 (defun %raw-set-single (vec index val)
70     (declare (type index index))
71     (%raw-set-single vec index val))
72    
73     (defun %raw-set-double (vec index val)
74     (declare (type index index))
75     (%raw-set-double vec index val))
76    
77 dtc 1.61 #+long-float
78     (defun %raw-set-long (vec index val)
79     (declare (type index index))
80     (%raw-set-long vec index val))
81    
82 dtc 1.60 (defun %raw-ref-complex-single (vec index)
83     (declare (type index index))
84     (%raw-ref-complex-single vec index))
85    
86     (defun %raw-ref-complex-double (vec index)
87     (declare (type index index))
88     (%raw-ref-complex-double vec index))
89    
90 dtc 1.61 #+long-float
91     (defun %raw-ref-complex-long (vec index)
92     (declare (type index index))
93     (%raw-ref-complex-long vec index))
94    
95 dtc 1.60 (defun %raw-set-complex-single (vec index val)
96     (declare (type index index))
97     (%raw-set-complex-single vec index val))
98    
99     (defun %raw-set-complex-double (vec index val)
100     (declare (type index index))
101     (%raw-set-complex-double vec index val))
102    
103 dtc 1.61 #+long-float
104     (defun %raw-set-complex-long (vec index val)
105     (declare (type index index))
106     (%raw-set-complex-long vec index val))
107    
108 ram 1.38 (defun %instance-layout (instance)
109     (%instance-layout instance))
110    
111     (defun %set-instance-layout (instance new-value)
112     (%set-instance-layout instance new-value))
113    
114 ram 1.43 (defun %make-funcallable-instance (len layout)
115     (%make-funcallable-instance len layout))
116    
117 ram 1.40 (defun funcallable-instance-p (x) (funcallable-instance-p x))
118    
119     (defun %funcallable-instance-info (fin i)
120     (%funcallable-instance-info fin i))
121    
122     (defun %set-funcallable-instance-info (fin i new-value)
123     (%set-funcallable-instance-info fin i new-value))
124    
125     (defun funcallable-instance-function (fin)
126     (%funcallable-instance-lexenv fin))
127    
128 ram 1.57 ;;; The heart of the magic of funcallable instances. The function for a FIN
129     ;;; must be a magical INSTANCE-LAMBDA form. When called (as with any other
130     ;;; function), we grab the code pointer, and call it, leaving the original
131     ;;; function object in LEXENV (in case it was a closure). If it is actually a
132     ;;; FIN, then we need to do an extra indirection with
133     ;;; funcallable-instance-lexenv to get at any closure environment. This extra
134     ;;; indirection is set up when accessing the closure environment of an
135     ;;; INSTANCE-LAMBDA. Note that the original FIN pointer is lost, so if the
136     ;;; called function wants to get at the original object to do some slot
137     ;;; accesses, it must close over the FIN object.
138     ;;;
139     ;;; If we set the FIN function to be a FIN, we directly copy across both the
140     ;;; code pointer and the lexenv, since that code pointer (for an
141     ;;; instance-lambda) is expecting that lexenv to be accessed. This effectively
142     ;;; pre-flattens what would otherwise be a chain of indirections. Lest this
143     ;;; sound like an excessively obscure case, note that it happens when PCL
144     ;;; dispatch functions are byte-compiled.
145     ;;;
146     ;;; The only loss is that if someone accesses the
147     ;;; funcallable-instance-function, then won't get a FIN back. This probably
148     ;;; doesn't matter, since PCL only sets the FIN function. And the only reason
149     ;;; that interpreted functions are FINs instead of bare closures is for
150     ;;; debuggability.
151     ;;;
152 ram 1.40 (defun (setf funcallable-instance-function) (new-value fin)
153     (setf (%funcallable-instance-function fin)
154     (%closure-function new-value))
155 ram 1.57 (setf (%funcallable-instance-lexenv fin)
156     (if (funcallable-instance-p new-value)
157     (%funcallable-instance-lexenv new-value)
158     new-value)))
159 ram 1.40
160 ram 1.38 (defsetf %instance-ref %instance-set)
161     (defsetf %raw-ref-single %raw-set-single)
162     (defsetf %raw-ref-double %raw-set-double)
163 dtc 1.61 #+long-float
164     (defsetf %raw-ref-long %raw-set-long)
165 dtc 1.60 (defsetf %raw-ref-complex-single %raw-set-complex-single)
166     (defsetf %raw-ref-complex-double %raw-set-complex-double)
167 dtc 1.64 #+long-float
168 dtc 1.61 (defsetf %raw-ref-complex-long %raw-set-complex-long)
169 ram 1.38 (defsetf %instance-layout %set-instance-layout)
170 ram 1.40 (defsetf %funcallable-instance-info %set-funcallable-instance-info)
171    
172 ram 1.1
173     ;;; This version of Defstruct is implemented using Defstruct, and is free of
174     ;;; Maclisp compatability nonsense. For bootstrapping, you're on your own.
175    
176 ram 1.38 ;;; The DEFSTRUCT-DESCRIPTION structure holds compile-time information about a
177     ;;; structure type.
178     ;;;
179     (defstruct (defstruct-description
180     (:conc-name dd-)
181     (:print-function print-defstruct-description)
182     (:make-load-form-fun :just-dump-it-normally)
183     (:pure t)
184     (:constructor make-defstruct-description (name)))
185     ;;
186     ;; name of the structure
187     (name (required-argument) :type symbol)
188     ;;
189     ;; documentation on the structure
190     (doc nil :type (or string null))
191     ;;
192     ;; prefix for slot names. If NIL, none.
193     (conc-name (concat-pnames name '-) :type (or symbol null))
194     ;;
195     ;; The name of the primary standard keyword constructor, or NIL if none.
196     (default-constructor nil :type (or symbol null))
197     ;;
198     ;; All the explicit :CONSTRUCTOR specs, with name defaulted.
199     (constructors () :type list)
200     ;;
201     ;; name of copying function
202     (copier (concat-pnames 'copy- name) :type (or symbol null))
203     ;;
204     ;; Name of type predictate
205     (predicate (concat-pnames name '-p) :type (or symbol null))
206     ;;
207     ;; The arguments to the :INCLUDE option, or NIL if no included structure.
208     (include nil :type list)
209     ;;
210     ;; The arguments to the :ALTERNATE-METACLASS option (an extension used to
211     ;; define structure-like objects with an arbitrary superclass and that may
212     ;; not have STRUCTURE-CLASS as the metaclass.) Syntax is:
213     ;; (superclass-name metaclass-name metaclass-constructor)
214     ;;
215     (alternate-metaclass nil :type list)
216     ;;
217     ;; list of defstruct-slot-description objects for all slots (including
218     ;; included ones.)
219     (slots () :type list)
220     ;;
221     ;; Number of elements we've allocated (see also raw-length.)
222     (length 0 :type index)
223     ;;
224     ;; General kind of implementation.
225 ram 1.40 (type 'structure :type (member structure vector list
226     funcallable-structure))
227 ram 1.38 ;;
228     ;; The next three slots are for :TYPE'd structures (which aren't classes,
229 ram 1.40 ;; CLASS-STRUCTURE-P = NIL)
230 ram 1.38 ;;
231     ;; Vector element type.
232     (element-type 't)
233     ;;
234     ;; T if :NAMED was explicitly specified, Nil otherwise.
235     (named nil :type boolean)
236     ;;
237     ;; Any INITIAL-OFFSET option on this direct type.
238     (offset nil :type (or index null))
239     ;;
240     ;; The argument to the PRINT-FUNCTION option, or NIL if none. If we see an
241     ;; explicit (:PRINT-FUNCTION) option, then this is DEFAULT-STRUCTURE-PRINT.
242 ram 1.44 ;; See also BASIC-STRUCTURE-CLASS-PRINTER. Only for classed structures.
243     ;;
244 ram 1.38 (print-function nil :type (or cons symbol null))
245     ;;
246 ram 1.44 ;; The next four slots are only meaningful in real default structures (TYPE =
247     ;; STRUCTURE).
248     ;;
249 ram 1.38 ;; Make-load-form function option. See also STRUCTURE-CLASS-LOAD-FORM-MAKER.
250     (make-load-form-fun nil :type (or symbol cons null))
251     ;;
252     ;; The index of the raw data vector and the number of words in it. NIL and 0
253     ;; if not allocated yet.
254     (raw-index nil :type (or index null))
255     (raw-length 0 :type index)
256     ;;
257 ram 1.40 ;; Value of the :PURE option, or :UNSPECIFIED. Only meaningful if
258     ;; CLASS-STRUCTURE-P = T.
259 dtc 1.58 (pure :unspecified :type (member t nil :substructure :unspecified)))
260 ram 1.38
261 ram 1.44
262 ram 1.38 ;;; DEFSTRUCT-SLOT-DESCRIPTION holds compile-time information about structure
263     ;;; slots.
264     ;;;
265     (defstruct (defstruct-slot-description
266     (:conc-name dsd-)
267     (:print-function print-defstruct-slot-description)
268     (:pure t)
269     (:make-load-form-fun :just-dump-it-normally))
270     %name ; string name of slot
271     ;;
272     ;; its position in the implementation sequence
273     (index (required-argument) :type fixnum)
274     ;;
275     ;; Name of accesor, or NIL if this accessor has the same name as an inherited
276     ;; accessor (which we don't want to shadow.)
277     (accessor nil)
278     default ; default value expression
279     (type t) ; declared type specifier
280     ;;
281     ;; If a raw slot, what it holds. T means not raw.
282 dtc 1.61 (raw-type t :type (member t single-float double-float #+long-float long-float
283 dtc 1.64 complex-single-float complex-double-float
284     #+long-float complex-long-float
285 dtc 1.60 unsigned-byte))
286 ram 1.38 (read-only nil :type (member t nil)))
287    
288 ram 1.1 (defun print-defstruct-description (structure stream depth)
289     (declare (ignore depth))
290     (format stream "#<Defstruct-Description for ~S>" (dd-name structure)))
291    
292 ram 1.38
293 ram 1.40 ;;; CLASS-STRUCTURE-P -- Internal
294     ;;;
295     ;;; Return true if Defstruct is a structure with a class.
296     ;;;
297     (defun class-structure-p (defstruct)
298     (member (dd-type defstruct) '(structure funcallable-structure)))
299    
300    
301     ;;; COMPILER-LAYOUT-OR-LOSE -- Internal
302     ;;;
303     ;;; Return the compiler layout for Name. Must be a structure-like class.
304     ;;;
305 ram 1.38 (defun compiler-layout-or-lose (name)
306     (let ((res (info type compiler-layout name)))
307     (cond ((not res)
308     (error "Class not yet defined or was undefined: ~S" name))
309 ram 1.40 ((not (typep (layout-info res) 'defstruct-description))
310     (error "Class is not a structure class: ~S" name))
311 ram 1.38 (t res))))
312    
313    
314     ;;; DSD-Name -- External
315 ram 1.1 ;;;
316 dtc 1.59 ;;; Return the name of a defstruct slot as a symbol. We store it
317 ram 1.1 ;;; as a string to avoid creating lots of worthless symbols at load time.
318     ;;;
319     (defun dsd-name (dsd)
320 ram 1.32 (intern (string (dsd-%name dsd))
321     (if (dsd-accessor dsd)
322     (symbol-package (dsd-accessor dsd))
323     *package*)))
324 ram 1.1
325     (defun print-defstruct-slot-description (structure stream depth)
326     (declare (ignore depth))
327     (format stream "#<Defstruct-Slot-Description for ~S>" (dsd-name structure)))
328 ram 1.5
329 ram 1.1
330     ;;; The legendary macro itself.
331    
332 ram 1.38 ;;; DEFINE-CLASS-METHODS -- Internal
333     ;;;
334     ;;; Return a list of forms to install print and make-load-form funs, mentioning
335     ;;; them in the expansion so that they can be compiled.
336     ;;;
337     (defun define-class-methods (defstruct)
338     (let ((name (dd-name defstruct)))
339     `(,@(let ((pf (dd-print-function defstruct)))
340     (when pf
341 wlott 1.47 `((setf (basic-structure-class-print-function (find-class ',name))
342 ram 1.38 ,(if (symbolp pf)
343     `',pf
344     `#',pf)))))
345 ram 1.40 ,@(let ((mlff (dd-make-load-form-fun defstruct)))
346     (when mlff
347     `((setf (structure-class-make-load-form-fun (find-class ',name))
348     ,(if (symbolp mlff)
349     `',mlff
350     `#',mlff)))))
351     ,@(let ((pure (dd-pure defstruct)))
352 dtc 1.58 (cond ((eq pure 't)
353     `((setf (layout-pure (class-layout (find-class ',name)))
354     t)))
355     ((eq pure :substructure)
356     `((setf (layout-pure (class-layout (find-class ',name)))
357     0)))))
358 ram 1.40 ,@(let ((def-con (dd-default-constructor defstruct)))
359     (when (and def-con (not (dd-alternate-metaclass defstruct)))
360     `((setf (structure-class-constructor (find-class ',name))
361     #',def-con)))))))
362 ram 1.38
363    
364     ;;; DEFSTRUCT -- Public
365     ;;;
366 ram 1.1 (defmacro defstruct (name-and-options &rest slot-descriptions)
367 ram 1.38 "DEFSTRUCT {Name | (Name Option*)} {Slot | (Slot [Default] {Key Value}*)}
368     Define the structure type Name. Instances are created by MAKE-<name>, which
369     takes keyword arguments allowing initial slot values to the specified.
370     A SETF'able function <name>-<slot> is defined for each slot to read&write
371     slot values. <name>-p is a type predicate.
372    
373     Popular DEFSTRUCT options (see manual for others):
374    
375     (:CONSTRUCTOR Name)
376     (:PREDICATE Name)
377     Specify an alternate name for the constructor or predicate.
378    
379     (:CONSTRUCTOR Name Lambda-List)
380     Explicitly specify the name and arguments to create a BOA constructor
381     (which is more efficient when keyword syntax isn't necessary.)
382    
383     (:INCLUDE Supertype Slot-Spec*)
384     Make this type a subtype of the structure type Supertype. The optional
385     Slot-Specs override inherited slot options.
386    
387     Slot options:
388    
389     :TYPE Type-Spec
390     Asserts that the value of this slot is always of the specified type.
391    
392     :READ-ONLY {T | NIL}
393     If true, no setter function is defined for this slot."
394    
395     (let* ((defstruct (parse-name-and-options
396     (if (atom name-and-options)
397     (list name-and-options)
398     name-and-options)))
399 ram 1.1 (name (dd-name defstruct)))
400 ram 1.38 (when (stringp (car slot-descriptions))
401     (setf (dd-doc defstruct) (pop slot-descriptions)))
402     (dolist (slot slot-descriptions)
403     (allocate-1-slot defstruct (parse-1-dsd defstruct slot)))
404 ram 1.40 (if (class-structure-p defstruct)
405 ram 1.38 (let ((inherits (inherits-for-structure defstruct)))
406     `(progn
407     (%defstruct ',defstruct ',inherits)
408 ram 1.50 (%compiler-only-defstruct ',defstruct ',inherits)
409 ram 1.40 ,@(when (eq (dd-type defstruct) 'structure)
410     `((%compiler-defstruct ',defstruct)))
411 ram 1.38 ,@(define-raw-accessors defstruct)
412     ,@(define-constructors defstruct)
413     ,@(define-class-methods defstruct)
414     ',name))
415 ram 1.1 `(progn
416     (eval-when (compile load eval)
417 ram 1.38 (setf (info typed-structure info ',name) ',defstruct))
418 ram 1.23 ,@(define-constructors defstruct)
419 ram 1.1 ,@(define-predicate defstruct)
420     ,@(define-accessors defstruct)
421     ,@(define-copier defstruct)
422     ',name))))
423    
424    
425     ;;;; Parsing:
426    
427 ram 1.38 ;;; PARSE-1-OPTION -- Internal
428     ;;;
429     ;;; Parse a single defstruct option and store the results in Defstruct.
430     ;;;
431     (defun parse-1-option (option defstruct)
432     (let ((args (rest option))
433     (name (dd-name defstruct)))
434     (case (first option)
435     (:conc-name
436     (destructuring-bind (conc-name) args
437     (setf (dd-conc-name defstruct)
438     (if (symbolp conc-name)
439     conc-name
440     (make-symbol (string conc-name))))))
441     (:constructor
442     (destructuring-bind (&optional (cname (concat-pnames 'make- name))
443     &rest stuff)
444     args
445     (push (cons cname stuff) (dd-constructors defstruct))))
446     (:copier
447     (destructuring-bind (&optional (copier (concat-pnames 'copy- name)))
448     args
449     (setf (dd-copier defstruct) copier)))
450     (:predicate
451     (destructuring-bind (&optional (pred (concat-pnames name '-p)))
452     args
453     (setf (dd-predicate defstruct) pred)))
454     (:include
455     (when (dd-include defstruct)
456     (error "Can't have more than one :INCLUDE option."))
457     (setf (dd-include defstruct) args))
458     (:alternate-metaclass
459     (setf (dd-alternate-metaclass defstruct) args))
460     (:print-function
461     (destructuring-bind (&optional (fun 'default-structure-print)) args
462     (setf (dd-print-function defstruct) fun)))
463     (:type
464     (destructuring-bind (type) args
465 ram 1.40 (cond ((eq type 'funcallable-structure)
466     (setf (dd-type defstruct) type))
467     ((member type '(list vector))
468 ram 1.38 (setf (dd-element-type defstruct) 't)
469     (setf (dd-type defstruct) type))
470     ((and (consp type) (eq (first type) 'vector))
471     (destructuring-bind (vector vtype) type
472     (declare (ignore vector))
473     (setf (dd-element-type defstruct) vtype)
474     (setf (dd-type defstruct) 'vector)))
475     (t
476     (error "~S is a bad :TYPE for Defstruct." type)))))
477     (:named
478     (error "The Defstruct option :NAMED takes no arguments."))
479     (:initial-offset
480     (destructuring-bind (offset) args
481     (setf (dd-offset defstruct) offset)))
482     (:make-load-form-fun
483     (destructuring-bind (fun) args
484     (setf (dd-make-load-form-fun defstruct) fun)))
485     (:pure
486     (destructuring-bind (fun) args
487     (setf (dd-pure defstruct) fun)))
488     (t (error "Unknown DEFSTRUCT option~% ~S" option)))))
489    
490    
491     ;;; PARSE-NAME-AND-OPTIONS -- Internal
492     ;;;
493     ;;; Given name and options, return a DD holding that info.
494     ;;;
495 ram 1.1 (defun parse-name-and-options (name-and-options)
496 ram 1.38 (destructuring-bind (name &rest options) name-and-options
497     (let ((defstruct (make-defstruct-description name)))
498     (dolist (option options)
499     (cond ((consp option)
500     (parse-1-option option defstruct))
501     ((eq option :named)
502     (setf (dd-named defstruct) t))
503     ((member option '(:constructor :copier :predicate :named))
504     (parse-1-option (list option) defstruct))
505     (t
506     (error "Unrecognized DEFSTRUCT option: ~S" option))))
507 ram 1.5
508 ram 1.43 (case (dd-type defstruct)
509     (structure
510     (when (dd-offset defstruct)
511     (error "Can't specify :OFFSET unless :TYPE is specified."))
512     (unless (dd-include defstruct)
513     (incf (dd-length defstruct))))
514     (funcallable-structure)
515     (t
516     (when (dd-print-function defstruct)
517     (warn "Silly to specify :PRINT-FUNCTION with :TYPE."))
518     (when (dd-make-load-form-fun defstruct)
519     (warn "Silly to specify :MAKE-LOAD-FORM-FUN with :TYPE."))
520     (when (dd-named defstruct) (incf (dd-length defstruct)))
521     (let ((offset (dd-offset defstruct)))
522     (when offset (incf (dd-length defstruct) offset)))))
523 ram 1.5
524 ram 1.38 (when (dd-include defstruct)
525     (do-inclusion-stuff defstruct))
526    
527     defstruct)))
528    
529 ram 1.1
530 ram 1.5 ;;;; Stuff to parse slot descriptions.
531    
532 ram 1.30 ;;; PARSE-1-DSD -- Internal
533     ;;;
534 ram 1.38 ;;; Parse a slot description for DEFSTRUCT, add it to the description and
535     ;;; return it. If supplied, ISLOT is a pre-initialized DSD that we modify to
536     ;;; get the new slot. This is supplied when handling included slots. If the
537     ;;; new accessor name is already an accessor for same slot in some included
538     ;;; structure, then set the DSD-ACCESSOR to NIL so that we don't clobber the
539     ;;; more general accessor.
540 ram 1.30 ;;;
541     (defun parse-1-dsd (defstruct spec &optional
542     (islot (make-defstruct-slot-description
543     :%name "" :index 0 :type t)))
544     (multiple-value-bind
545     (name default default-p type type-p read-only ro-p)
546     (cond
547     ((listp spec)
548     (destructuring-bind (name &optional (default nil default-p)
549     &key (type nil type-p) (read-only nil ro-p))
550     spec
551     (values name default default-p type type-p read-only ro-p)))
552     (t
553     (when (keywordp spec)
554 ram 1.38 (warn "Keyword slot name indicates probable syntax ~
555 ram 1.30 error in DEFSTRUCT -- ~S."
556     spec))
557     spec))
558     (when (find name (dd-slots defstruct) :test #'string= :key #'dsd-%name)
559 dtc 1.66 (error 'simple-program-error
560 pw 1.62 :format-control "Duplicate slot name ~S."
561     :format-arguments (list name)))
562 ram 1.30 (setf (dsd-%name islot) (string name))
563     (setf (dd-slots defstruct) (nconc (dd-slots defstruct) (list islot)))
564 ram 1.31
565     (let* ((aname (concat-pnames (dd-conc-name defstruct) name))
566     (existing (info function accessor-for aname)))
567 ram 1.39 (if (and (structure-class-p existing)
568 ram 1.38 (not (eq (class-name existing) (dd-name defstruct)))
569     (string= (dsd-%name (find aname
570     (dd-slots
571     (layout-info
572     (class-layout existing)))
573     :key #'dsd-accessor))
574     name))
575 ram 1.31 (setf (dsd-accessor islot) nil)
576     (setf (dsd-accessor islot) aname)))
577 ram 1.30
578     (when default-p
579     (setf (dsd-default islot) default))
580     (when type-p
581 ram 1.38 (setf (dsd-type islot)
582     (if (eq (dsd-type islot) 't)
583     type
584     `(and ,(dsd-type islot) ,type))))
585 ram 1.30 (when ro-p
586 ram 1.38 (if read-only
587     (setf (dsd-read-only islot) t)
588     (when (dsd-read-only islot)
589     (error "Slot ~S must be read-only in subtype ~S." name
590     (dsd-name islot)))))
591     islot))
592 ram 1.30
593    
594 ram 1.38 ;;; ALLOCATE-1-SLOT -- Internal
595 ram 1.5 ;;;
596 ram 1.38 ;;; Allocate storage for a DSD in Defstruct. This is where we decide if a
597     ;;; slot is raw or not. If raw, and we haven't allocated a raw-index yet for
598     ;;; the raw data vector, then do it. Raw objects are aligned on the unit of
599     ;;; their size.
600     ;;;
601     (defun allocate-1-slot (defstruct dsd)
602     (let ((type (dsd-type dsd)))
603     (multiple-value-bind
604     (raw-type words)
605     (cond ((not (eq (dd-type defstruct) 'structure))
606     (values nil nil))
607     ((and (subtypep type '(unsigned-byte 32))
608     (not (subtypep type 'fixnum)))
609     (values 'unsigned-byte 1))
610     ((subtypep type 'single-float)
611     (values 'single-float 1))
612     ((subtypep type 'double-float)
613     (values 'double-float 2))
614 dtc 1.61 #+long-float
615     ((subtypep type 'long-float)
616     (values 'long-float #+x86 3 #+sparc 4))
617 dtc 1.60 ((subtypep type '(complex single-float))
618     (values 'complex-single-float 2))
619     ((subtypep type '(complex double-float))
620     (values 'complex-double-float 4))
621 dtc 1.64 #+long-float
622 dtc 1.61 ((subtypep type '(complex long-float))
623     (values 'complex-long-float #+x86 6 #+sparc 8))
624 ram 1.38 (t (values nil nil)))
625    
626     (cond ((not raw-type)
627     (setf (dsd-index dsd) (dd-length defstruct))
628     (incf (dd-length defstruct)))
629     (t
630     (unless (dd-raw-index defstruct)
631     (setf (dd-raw-index defstruct) (dd-length defstruct))
632     (incf (dd-length defstruct)))
633 ram 1.51 (let ((off (rem (dd-raw-length defstruct) words)))
634 ram 1.38 (unless (zerop off)
635     (incf (dd-raw-length defstruct) (- words off))))
636     (setf (dsd-raw-type dsd) raw-type)
637     (setf (dsd-index dsd) (dd-raw-length defstruct))
638     (incf (dd-raw-length defstruct) words)))))
639    
640 ram 1.30 (undefined-value))
641 ram 1.1
642 ram 1.38
643     ;;; DO-INCLUSION-STUFF -- Internal
644     ;;;
645     ;;; Process any included slots pretty much like they were specified. Also
646     ;;; inherit various other attributes (print function, etc.)
647     ;;;
648     (defun do-inclusion-stuff (defstruct)
649     (destructuring-bind (included-name &rest modified-slots)
650     (dd-include defstruct)
651     (let* ((type (dd-type defstruct))
652     (included-structure
653 ram 1.40 (if (class-structure-p defstruct)
654 ram 1.38 (layout-info (compiler-layout-or-lose included-name))
655     (typed-structure-info-or-lose included-name))))
656     (unless (and (eq type (dd-type included-structure))
657     (type= (specifier-type (dd-element-type included-structure))
658     (specifier-type (dd-element-type defstruct))))
659     (error ":TYPE option mismatch between structures ~S and ~S."
660     (dd-name defstruct) included-name))
661    
662     (incf (dd-length defstruct) (dd-length included-structure))
663 ram 1.40 (when (class-structure-p defstruct)
664 ram 1.38 (unless (dd-print-function defstruct)
665     (setf (dd-print-function defstruct)
666     (dd-print-function included-structure)))
667     (unless (dd-make-load-form-fun defstruct)
668     (setf (dd-make-load-form-fun defstruct)
669     (dd-make-load-form-fun included-structure)))
670 ram 1.40 (let ((mc (rest (dd-alternate-metaclass included-structure))))
671     (when (and mc (not (dd-alternate-metaclass defstruct)))
672     (setf (dd-alternate-metaclass defstruct)
673     (cons included-name mc))))
674 ram 1.38 (when (eq (dd-pure defstruct) :unspecified)
675     (setf (dd-pure defstruct) (dd-pure included-structure)))
676     (setf (dd-raw-index defstruct) (dd-raw-index included-structure))
677     (setf (dd-raw-length defstruct) (dd-raw-length included-structure)))
678    
679     (dolist (islot (dd-slots included-structure))
680     (let* ((iname (dsd-name islot))
681     (modified (or (find iname modified-slots
682     :key #'(lambda (x) (if (atom x) x (car x)))
683     :test #'string=)
684     `(,iname))))
685     (parse-1-dsd defstruct modified
686     (copy-defstruct-slot-description islot)))))))
687    
688    
689 ram 1.1
690 ram 1.38 ;;;; Constructors:
691    
692     (defun typed-structure-info-or-lose (name)
693     (or (info typed-structure info name)
694     (error ":TYPE'd defstruct ~S not found for inclusion." name)))
695    
696     ;;; %GET-COMPILER-LAYOUT -- Internal
697 ram 1.1 ;;;
698 ram 1.38 ;;; Delay looking for compiler-layout until the constructor is being compiled,
699     ;;; since it doesn't exist until after the eval-when (compile) is compiled.
700 ram 1.1 ;;;
701 ram 1.38 (defmacro %get-compiler-layout (name)
702     `',(compiler-layout-or-lose name))
703 ram 1.1
704 ram 1.38 ;;; FIND-NAME-INDICES -- Internal
705 ram 1.1 ;;;
706 ram 1.38 ;;; Returns a list of pairs (name . index). Used for :TYPE'd constructors
707     ;;; to find all the names that we have to splice in & where. Note that these
708     ;;; types don't have a layout, so we can't look at LAYOUT-INHERITS.
709 ram 1.1 ;;;
710 ram 1.38 (defun find-name-indices (defstruct)
711     (collect ((res))
712     (let ((infos ()))
713     (do ((info defstruct
714     (typed-structure-info-or-lose (first (dd-include info)))))
715     ((not (dd-include info))
716     (push info infos))
717     (push info infos))
718    
719     (let ((i 0))
720     (dolist (info infos)
721     (incf i (or (dd-offset info) 0))
722     (when (dd-named info)
723     (res (cons (dd-name info) i)))
724     (setq i (dd-length info)))))
725 ram 1.1
726 ram 1.38 (res)))
727 ram 1.15
728 ram 1.38
729     ;;; CREATE-{STRUCTURE,VECTOR,LIST}-CONSTRUCTOR -- Internal
730 ram 1.15 ;;;
731 ram 1.38 ;;; These functions are called to actually make a constructor after we have
732     ;;; processed the arglist. The correct variant (according to the DD-TYPE)
733     ;;; should be called. The function is defined with the specified name and
734     ;;; arglist. Vars and Types are used for argument type declarations. Values
735     ;;; are the values for the slots (in order.)
736 ram 1.15 ;;;
737 ram 1.40 ;;; This is split four ways because:
738 ram 1.38 ;;; 1] list & vector structures need "name" symbols stuck in at various weird
739     ;;; places, whereas STRUCTURE structures have a LAYOUT slot.
740     ;;; 2] We really want to use LIST to make list structures, instead of
741     ;;; MAKE-LIST/(SETF ELT).
742     ;;; 3] STRUCTURE structures can have raw slots that must also be allocated and
743     ;;; indirectly referenced. We use SLOT-ACCESSOR-FORM to compute how to set
744     ;;; the slots, which deals with raw slots.
745 ram 1.40 ;;; 4] funcallable structures are weird.
746 ram 1.38 ;;;
747     (defun create-vector-constructor
748     (defstruct cons-name arglist vars types values)
749     (let ((temp (gensym))
750     (etype (dd-element-type defstruct)))
751     `(defun ,cons-name ,arglist
752     (declare ,@(mapcar #'(lambda (var type) `(type (and ,type ,etype) ,var))
753     vars types))
754     (let ((,temp (make-array ,(dd-length defstruct)
755     :element-type ',(dd-element-type defstruct))))
756     ,@(mapcar #'(lambda (x)
757     `(setf (aref ,temp ,(cdr x)) ',(car x)))
758     (find-name-indices defstruct))
759     ,@(mapcar #'(lambda (dsd value)
760     `(setf (aref ,temp ,(dsd-index dsd)) ,value))
761     (dd-slots defstruct) values)
762     ,temp))))
763     ;;;
764     (defun create-list-constructor
765     (defstruct cons-name arglist vars types values)
766     (let ((vals (make-list (dd-length defstruct) :initial-element nil)))
767     (dolist (x (find-name-indices defstruct))
768     (setf (elt vals (cdr x)) `',(car x)))
769     (loop for dsd in (dd-slots defstruct) and val in values do
770     (setf (elt vals (dsd-index dsd)) val))
771 ram 1.15
772 ram 1.38 `(defun ,cons-name ,arglist
773     (declare ,@(mapcar #'(lambda (var type) `(type ,type ,var))
774     vars types))
775     (list ,@vals))))
776     ;;;
777     (defun create-structure-constructor
778     (defstruct cons-name arglist vars types values)
779     (let* ((temp (gensym))
780     (raw-index (dd-raw-index defstruct))
781     (n-raw-data (when raw-index (gensym))))
782     `(defun ,cons-name ,arglist
783     (declare ,@(mapcar #'(lambda (var type) `(type ,type ,var))
784     vars types))
785     (let ((,temp (truly-the ,(dd-name defstruct)
786     (%make-instance ,(dd-length defstruct))))
787     ,@(when n-raw-data
788     `((,n-raw-data
789     (make-array ,(dd-raw-length defstruct)
790     :element-type '(unsigned-byte 32))))))
791     (setf (%instance-layout ,temp)
792     (%get-compiler-layout ,(dd-name defstruct)))
793     ,@(when n-raw-data
794     `((setf (%instance-ref ,temp ,raw-index) ,n-raw-data)))
795     ,@(mapcar #'(lambda (dsd value)
796     (multiple-value-bind
797     (accessor index data)
798     (slot-accessor-form defstruct dsd temp n-raw-data)
799     `(setf (,accessor ,data ,index) ,value)))
800     (dd-slots defstruct)
801     values)
802     ,temp))))
803 ram 1.40 ;;;
804     (defun create-fin-constructor
805     (defstruct cons-name arglist vars types values)
806     (let ((temp (gensym)))
807     `(defun ,cons-name ,arglist
808     (declare ,@(mapcar #'(lambda (var type) `(type ,type ,var))
809     vars types))
810     (let ((,temp (truly-the
811     ,(dd-name defstruct)
812     (%make-funcallable-instance
813     ,(dd-length defstruct)
814     (%get-compiler-layout ,(dd-name defstruct))))))
815     ,@(mapcar #'(lambda (dsd value)
816     `(setf (%funcallable-instance-info
817     ,temp ,(dsd-index dsd))
818     ,value))
819     (dd-slots defstruct) values)
820     ,temp))))
821 ram 1.15
822    
823 ram 1.38 ;;; CREATE-KEYWORD-CONSTRUCTOR -- Internal
824 ram 1.1 ;;;
825 ram 1.38 ;;; Create a default (non-BOA) keyword constructor.
826 ram 1.1 ;;;
827 ram 1.38 (defun create-keyword-constructor (defstruct creator)
828     (collect ((arglist (list '&key))
829     (types)
830     (vals))
831     (dolist (slot (dd-slots defstruct))
832     (let ((dum (gensym))
833     (name (dsd-name slot)))
834     (arglist `((,(intern (string name) "KEYWORD") ,dum)
835     ,(dsd-default slot)))
836     (types (dsd-type slot))
837     (vals dum)))
838     (funcall creator
839     defstruct (dd-default-constructor defstruct)
840     (arglist) (vals) (types) (vals))))
841    
842    
843     ;;; CREATE-BOA-CONSTRUCTOR -- Internal
844     ;;;
845     ;;; Given a structure and a BOA constructor spec, call Creator with the
846     ;;; appropriate args to make a constructor.
847     ;;;
848     (defun create-boa-constructor (defstruct boa creator)
849     (multiple-value-bind (req opt restp rest keyp keys allowp aux)
850     (kernel:parse-lambda-list (second boa))
851     (collect ((arglist)
852     (vars)
853     (types))
854     (labels ((get-slot (name)
855     (let ((res (find name (dd-slots defstruct) :test #'string=
856     :key #'dsd-name)))
857     (if res
858     (values (dsd-type res) (dsd-default res))
859     (values t nil))))
860     (do-default (arg)
861     (multiple-value-bind (type default) (get-slot arg)
862     (arglist `(,arg ,default))
863     (vars arg)
864     (types type))))
865     (dolist (arg req)
866     (arglist arg)
867     (vars arg)
868     (types (get-slot arg)))
869    
870     (when opt
871     (arglist '&optional)
872     (dolist (arg opt)
873     (cond ((consp arg)
874     (destructuring-bind
875     (name &optional (def (nth-value 1 (get-slot name))))
876     arg
877     (arglist `(,name ,def))
878     (vars name)
879     (types (get-slot name))))
880     (t
881     (do-default arg)))))
882    
883     (when restp
884     (arglist '&rest rest)
885     (vars rest)
886     (types 'list))
887    
888     (when keyp
889     (arglist '&key)
890     (dolist (key keys)
891     (if (consp key)
892     (destructuring-bind (wot &optional (def nil def-p))
893     key
894     (let ((name (if (consp wot)
895     (destructuring-bind (key var) wot
896     (declare (ignore key))
897     var)
898     wot)))
899     (multiple-value-bind (type slot-def) (get-slot name)
900     (arglist `(,wot ,(if def-p def slot-def)))
901     (vars name)
902     (types type))))
903     (do-default key))))
904 ram 1.1
905 ram 1.38 (when allowp (arglist '&allow-other-keys))
906 ram 1.1
907 ram 1.38 (when aux
908     (arglist '&aux)
909     (dolist (arg aux)
910     (let* ((arg (if (consp arg) arg (list arg)))
911     (var (first arg)))
912     (arglist arg)
913     (vars var)
914     (types (get-slot var))))))
915 ram 1.1
916 ram 1.38 (funcall creator defstruct (first boa)
917     (arglist) (vars) (types)
918     (mapcar #'(lambda (slot)
919 ram 1.41 (or (find (dsd-name slot) (vars) :test #'string=)
920 ram 1.38 (dsd-default slot)))
921     (dd-slots defstruct))))))
922 ram 1.35
923    
924 ram 1.38 ;;; DEFINE-CONSTRUCTORS -- Internal
925 ram 1.35 ;;;
926 ram 1.38 ;;; Grovel the constructor options, and decide what constructors (if any) to
927     ;;; create.
928 ram 1.35 ;;;
929 ram 1.38 (defun define-constructors (defstruct)
930     (let ((no-constructors nil)
931     (boas ())
932     (defaults ())
933     (creator (ecase (dd-type defstruct)
934     (structure #'create-structure-constructor)
935 ram 1.40 (funcallable-structure #'create-fin-constructor)
936 ram 1.38 (vector #'create-vector-constructor)
937     (list #'create-list-constructor))))
938     (dolist (constructor (dd-constructors defstruct))
939     (destructuring-bind (name &optional (boa-ll nil boa-p))
940     constructor
941     (declare (ignore boa-ll))
942     (cond ((not name) (setq no-constructors t))
943     (boa-p (push constructor boas))
944     (t (push name defaults)))))
945 ram 1.1
946 ram 1.38 (when no-constructors
947     (when (or defaults boas)
948     (error "(:CONSTRUCTOR NIL) combined with other :CONSTRUCTORs."))
949     (return-from define-constructors ()))
950 ram 1.1
951 ram 1.38 (unless (or defaults boas)
952     (push (concat-pnames 'make- (dd-name defstruct)) defaults))
953 ram 1.1
954 ram 1.38 (collect ((res))
955     (when defaults
956     (let ((cname (first defaults)))
957     (setf (dd-default-constructor defstruct) cname)
958     (res (create-keyword-constructor defstruct creator))
959     (dolist (other-name (rest defaults))
960     (res `(setf (fdefinition ',other-name) (fdefinition ',cname)))
961     (res `(declaim (ftype function ',other-name))))))
962    
963     (dolist (boa boas)
964     (res (create-boa-constructor defstruct boa creator)))
965 ram 1.5
966 ram 1.38 (res))))
967 ram 1.1
968 ram 1.38 ;;;; Slot accessors for raw slots:
969 ram 1.5
970 ram 1.38 ;;; SLOT-ACCESSOR-FORM -- Internal
971 ram 1.1 ;;;
972 ram 1.38 ;;; Return info about how to read/write a slot in the value stored in
973     ;;; Object. This is also used by constructors (we can't use the accessor
974     ;;; function, since some slots are read-only.) If supplied, Data is a variable
975     ;;; holding the raw-data vector.
976     ;;;
977     ;;; Values:
978     ;;; 1] Accessor function name (setfable)
979     ;;; 2] Index to pass to accessor.
980     ;;; 3] Object form to pass to accessor.
981 ram 1.1 ;;;
982 ram 1.38 (defun slot-accessor-form (defstruct slot &optional (object 'object) data)
983     (let ((rtype (dsd-raw-type slot)))
984     (values
985     (ecase rtype
986     (single-float '%raw-ref-single)
987     (double-float '%raw-ref-double)
988 dtc 1.61 #+long-float
989     (long-float '%raw-ref-long)
990 dtc 1.60 (complex-single-float '%raw-ref-complex-single)
991     (complex-double-float '%raw-ref-complex-double)
992 dtc 1.64 #+long-float
993 dtc 1.61 (complex-long-float '%raw-ref-complex-long)
994 ram 1.38 (unsigned-byte 'aref)
995 ram 1.40 ((t)
996     (if (eq (dd-type defstruct) 'funcallable-structure)
997     '%funcallable-instance-info
998     '%instance-ref)))
999 dtc 1.60 (case rtype
1000 dtc 1.64 #+long-float
1001 dtc 1.61 (complex-long-float
1002     (truncate (dsd-index slot) #+x86 6 #+sparc 8))
1003     #+long-float
1004     (long-float
1005     (truncate (dsd-index slot) #+x86 3 #+sparc 4))
1006 dtc 1.60 (double-float
1007     (ash (dsd-index slot) -1))
1008     (complex-double-float
1009     (ash (dsd-index slot) -2))
1010     (complex-single-float
1011     (ash (dsd-index slot) -1))
1012     (t
1013     (dsd-index slot)))
1014 ram 1.38 (cond
1015     ((eq rtype 't) object)
1016     (data)
1017     (t
1018     `(truly-the (simple-array (unsigned-byte 32) (*))
1019     (%instance-ref object ,(dd-raw-index defstruct))))))))
1020 ram 1.1
1021 ram 1.5
1022 ram 1.38 ;;; DEFINE-RAW-ACCESSORS -- Internal
1023 ram 1.1 ;;;
1024 ram 1.38 ;;; Define readers and writers for raw slots as inline functions. We use
1025 ram 1.40 ;;; the special RAW-REF operations to store floats in the raw data vector. We
1026     ;;; also define FIN accessors here.
1027 ram 1.38 ;;;
1028     (defun define-raw-accessors (defstruct)
1029     (let ((name (dd-name defstruct)))
1030     (collect ((res))
1031     (dolist (slot (dd-slots defstruct))
1032     (let ((stype (dsd-type slot))
1033     (aname (dsd-accessor slot)))
1034     (multiple-value-bind (accessor offset data)
1035     (slot-accessor-form defstruct slot)
1036     (when (and aname (not (eq accessor '%instance-ref)))
1037     (res `(declaim (inline ,aname)))
1038     (res `(declaim (ftype (function (,name) ,stype) ,aname)))
1039     (res
1040     `(defun ,aname (object)
1041     (truly-the ,stype (,accessor ,data ,offset))))
1042     (unless (dsd-read-only slot)
1043     (res `(declaim (inline (setf ,aname))))
1044     (res `(declaim (ftype (function (,stype ,name) ,stype)
1045     (setf ,aname))))
1046     (res
1047     `(defun (setf ,aname) (new-value object)
1048     (setf (,accessor ,data ,offset) new-value)
1049     new-value)))))))
1050 ram 1.40
1051     (when (eq (dd-type defstruct) 'funcallable-structure)
1052     (let ((pred (dd-predicate defstruct)))
1053     (when pred
1054     (res `(declaim (inline ,pred)))
1055     (res `(defun ,pred (x) (typep x ',name))))))
1056    
1057     (res))))
1058    
1059 ram 1.1
1060 ram 1.38 ;;;; Typed (non-class) structures:
1061    
1062     ;;; DD-LISP-TYPE -- Internal
1063     ;;;
1064     ;;; Return a type specifier we can use for testing :TYPE'd structures.
1065     ;;;
1066     (defun dd-lisp-type (defstruct)
1067     (ecase (dd-type defstruct)
1068     (list 'list)
1069     (vector `(simple-array ,(dd-element-type defstruct)
1070     (*)))))
1071    
1072     ;;; DEFINE-ACCESSORS -- Internal
1073     ;;;
1074     ;;; Returns a list of function definitions for accessing and setting the
1075     ;;; slots of the a typed Defstruct. The functions are proclaimed to be inline,
1076     ;;; and the types of their arguments and results are declared as well. We
1077     ;;; count on the compiler to do clever things with Elt.
1078     ;;;
1079     (defun define-accessors (defstruct)
1080     (collect ((stuff))
1081     (let ((ltype (dd-lisp-type defstruct)))
1082     (dolist (slot (dd-slots defstruct))
1083     (let ((name (dsd-accessor slot))
1084     (index (dsd-index slot))
1085     (slot-type `(and ,(dsd-type slot)
1086     ,(dd-element-type defstruct))))
1087     (stuff `(proclaim '(inline ,name (setf ,name))))
1088     (stuff `(defun ,name (structure)
1089     (declare (type ,ltype structure))
1090     (the ,slot-type (elt structure ,index))))
1091     (unless (dsd-read-only slot)
1092     (stuff
1093     `(defun (setf ,name) (new-value structure)
1094     (declare (type ,ltype structure) (type ,slot-type new-value))
1095     (setf (elt structure ,index) new-value)))))))
1096     (stuff)))
1097    
1098    
1099 ram 1.1 ;;; Define-Copier returns the definition for a copier function of a typed
1100     ;;; Defstruct if one is desired.
1101     (defun define-copier (defstruct)
1102     (when (dd-copier defstruct)
1103 ram 1.38 `((setf (fdefinition ',(dd-copier defstruct)) #'copy-seq)
1104     (declaim (ftype function ,(dd-copier defstruct))))))
1105 ram 1.1
1106 ram 1.38
1107 ram 1.1 ;;; Define-Predicate returns a definition for a predicate function if one is
1108 ram 1.38 ;;; desired. Rather vaguely specified w.r.t. inclusion.
1109     ;;;
1110 ram 1.7 (defun define-predicate (defstruct)
1111 ram 1.1 (let ((name (dd-name defstruct))
1112     (pred (dd-predicate defstruct)))
1113     (when (and pred (dd-named defstruct))
1114     (let ((ltype (dd-lisp-type defstruct)))
1115     `((defun ,pred (object)
1116     (and (typep object ',ltype)
1117 ram 1.38 (eq (elt (the ,ltype object)
1118     ,(cdr (car (last (find-name-indices defstruct)))))
1119 ram 1.1 ',name))))))))
1120    
1121    
1122 ram 1.38 ;;;; Load time support for default structures (%DEFSTRUCT)
1123     ;;;
1124     ;;; In the normal case of structures that have a real type (i.e. no :Type
1125     ;;; option was specified), we want to optimize things for space as well as
1126     ;;; speed, since there can be thousands of defined slot accesors.
1127     ;;;
1128     ;;; What we do is defined the accessors and copier as closures over
1129     ;;; general-case code. Since the compiler will normally open-code accesors,
1130     ;;; the (minor) efficiency penalty is not a concern.
1131 ram 1.1
1132 ram 1.38 ;;; Typep-To-Layout -- Internal
1133     ;;;
1134     ;;; Return true if Obj is an object of the structure type corresponding to
1135     ;;; Layout. This is called by the accessor closures, which have a handle on
1136     ;;; the type's layout.
1137     ;;;
1138     (proclaim '(inline typep-to-layout))
1139     (defun typep-to-layout (obj layout)
1140     (declare (type layout layout) (optimize (speed 3) (safety 0)))
1141     (when (layout-invalid layout)
1142     (error "Obsolete structure accessor function called."))
1143     (and (%instancep obj)
1144     (let ((depth (layout-inheritance-depth layout))
1145     (obj-layout (%instance-layout obj)))
1146     (cond ((eq obj-layout layout) t)
1147     ((layout-invalid obj-layout)
1148     (error 'layout-invalid :expected-type (layout-class obj-layout)
1149     :datum obj))
1150     (t
1151     (and (> (layout-inheritance-depth obj-layout) depth)
1152     (eq (svref (layout-inherits obj-layout) depth)
1153     layout)))))))
1154    
1155    
1156     ;;; STRUCTURE-SLOT-SETTER, STRUCTURE-SLOT-ACCESSOR -- Internal
1157     ;;;
1158     ;;; Return closures to do slot access (set), according to Layout and DSD.
1159     ;;; We check types, then do the access. This is only used for normal slots
1160     ;;; (not raw.)
1161     ;;;
1162     (defun structure-slot-accessor (layout dsd)
1163 ram 1.54 (let ((class (layout-class layout)))
1164     (if (typep class 'basic-structure-class)
1165     #'(lambda (structure)
1166     (declare (optimize (speed 3) (safety 0)))
1167     (unless (typep-to-layout structure layout)
1168 dtc 1.66 (error 'simple-type-error
1169     :datum structure
1170     :expected-type class
1171     :format-control "Structure for accessor ~S is not a ~S:~% ~S"
1172     :format-arguments (list (dsd-accessor dsd)
1173     (class-name class)
1174     structure)))
1175 ram 1.54 (%instance-ref structure (dsd-index dsd)))
1176     #'(lambda (structure)
1177     (declare (optimize (speed 3) (safety 0)))
1178     (unless (%typep structure class)
1179 dtc 1.66 (error 'simple-type-error
1180     :datum structure
1181     :expected-type class
1182     :format-control "Structure for accessor ~S is not a ~S:~% ~S"
1183     :format-arguments (list (dsd-accessor dsd) class
1184     structure)))
1185 ram 1.54 (%instance-ref structure (dsd-index dsd))))))
1186 ram 1.38 ;;;
1187     (defun structure-slot-setter (layout dsd)
1188 ram 1.54 (let ((class (layout-class layout)))
1189     (if (typep class 'basic-structure-class)
1190     #'(lambda (new-value structure)
1191     (declare (optimize (speed 3) (safety 0)))
1192     (unless (typep-to-layout structure layout)
1193 dtc 1.66 (error 'simple-type-error
1194     :datum structure
1195     :expected-type class
1196     :format-control "Structure for setter ~S is not a ~S:~% ~S"
1197     :format-arguments (list `(setf ,(dsd-accessor dsd))
1198     (class-name class)
1199     structure)))
1200 ram 1.54 (unless (%typep new-value (dsd-type dsd))
1201 dtc 1.66 (error 'simple-type-error
1202     :datum new-value
1203     :expected-type (dsd-type dsd)
1204     :format-control "New-Value for setter ~S is not a ~S:~% ~S."
1205     :format-arguments (list `(setf ,(dsd-accessor dsd))
1206     (dsd-type dsd)
1207     new-value)))
1208 ram 1.54 (setf (%instance-ref structure (dsd-index dsd)) new-value))
1209     #'(lambda (new-value structure)
1210     (declare (optimize (speed 3) (safety 0)))
1211     (unless (%typep structure class)
1212 dtc 1.66 (error 'simple-type-error
1213     :datum structure
1214     :expected-type class
1215     :format-control "Structure for setter ~S is not a ~S:~% ~S"
1216     :format-arguments (list `(setf ,(dsd-accessor dsd))
1217     (class-name class)
1218     structure)))
1219 ram 1.54 (unless (%typep new-value (dsd-type dsd))
1220 dtc 1.66 (error 'simple-type-error
1221     :datum new-value
1222     :expected-type (dsd-type dsd)
1223     :format-control "New-Value for setter ~S is not a ~S:~% ~S."
1224     :format-arguments (list `(setf ,(dsd-accessor dsd))
1225     (dsd-type dsd)
1226     new-value)))
1227 ram 1.54 (setf (%instance-ref structure (dsd-index dsd)) new-value)))))
1228 ram 1.38
1229    
1230     ;;; %Defstruct -- Internal
1231     ;;;
1232     ;;; Do miscellaneous (LOAD EVAL) time actions for the structure described by
1233     ;;; Info. Create the class & layout, checking for incompatible redefinition.
1234     ;;; Define setters, accessors, copier, predicate, documentation, instantiate
1235     ;;; definition in load-time env. This is only called for default structures.
1236     ;;;
1237     (defun %defstruct (info inherits)
1238     (declare (type defstruct-description info))
1239     (multiple-value-bind (class layout old-layout)
1240 dtc 1.66 (ensure-structure-class info inherits "current" "new")
1241 ram 1.38 (cond ((not old-layout)
1242     (unless (eq (class-layout class) layout)
1243 ram 1.40 (register-layout layout)))
1244 ram 1.38 (t
1245     (let ((old-info (layout-info old-layout)))
1246     (when (defstruct-description-p old-info)
1247     (dolist (slot (dd-slots old-info))
1248     (fmakunbound (dsd-accessor slot))
1249     (unless (dsd-read-only slot)
1250     (fmakunbound `(setf ,(dsd-accessor slot)))))))
1251 ram 1.42 (%redefine-defstruct class old-layout layout)
1252     (setq layout (class-layout class))))
1253 ram 1.38
1254     (setf (find-class (dd-name info)) class)
1255 ram 1.40
1256     (unless (eq (dd-type info) 'funcallable-structure)
1257     (dolist (slot (dd-slots info))
1258     (let ((dsd slot))
1259     (when (and (dsd-accessor slot)
1260     (eq (dsd-raw-type slot) 't))
1261     (setf (symbol-function (dsd-accessor slot))
1262     (structure-slot-accessor layout dsd))
1263    
1264     (unless (dsd-read-only slot)
1265     (setf (fdefinition `(setf ,(dsd-accessor slot)))
1266     (structure-slot-setter layout dsd))))))
1267 ram 1.38
1268 ram 1.40 (when (dd-predicate info)
1269     (setf (symbol-function (dd-predicate info))
1270     #'(lambda (object)
1271     (declare (optimize (speed 3) (safety 0)))
1272     (typep-to-layout object layout))))
1273    
1274     (when (dd-copier info)
1275     (setf (symbol-function (dd-copier info))
1276     #'(lambda (structure)
1277     (declare (optimize (speed 3) (safety 0)))
1278     (unless (typep-to-layout structure layout)
1279 dtc 1.66 (error 'simple-type-error
1280     :datum structure
1281     :expected-type class
1282     :format-control "Structure for copier is not a ~S:~% ~S"
1283     :format-arguments (list class structure)))
1284     (copy-structure structure))))))
1285    
1286 ram 1.38 (when (dd-doc info)
1287 dtc 1.66 (setf (documentation (dd-name info) 'type) (dd-doc info)))
1288 ram 1.38
1289     (undefined-value))
1290    
1291    
1292     ;;;; Redefinition stuff:
1293    
1294     ;;; ENSURE-STRUCTURE-CLASS -- Internal
1295     ;;;
1296     ;;; Called when we are about to define a structure class. Returns a
1297     ;;; (possibly new) class object and the layout which should be used for the new
1298     ;;; definition (may be the current layout, and also might be an uninstalled
1299     ;;; forward referenced layout.) The third value is true if this is an
1300     ;;; incompatible redefinition, in which case it is the old layout.
1301     ;;;
1302 ram 1.48 (defun ensure-structure-class (info inherits old-context new-context
1303     &optional compiler-layout)
1304 ram 1.38 (multiple-value-bind
1305     (class old-layout)
1306     (destructuring-bind (&optional name (class 'structure-class)
1307     (constructor 'make-structure-class))
1308     (dd-alternate-metaclass info)
1309     (declare (ignore name))
1310     (insured-find-class (dd-name info)
1311     (if (eq class 'structure-class)
1312     #'(lambda (x) (typep x 'structure-class))
1313     #'(lambda (x) (typep x (find-class class))))
1314     (fdefinition constructor)))
1315 wlott 1.53 (setf (class-direct-superclasses class)
1316 dtc 1.63 (if (eq (dd-name info) 'lisp-stream)
1317     ;; Hack to add stream as a superclass mixin to lisp-streams.
1318     (list (layout-class (svref inherits (1- (length inherits))))
1319     (layout-class (svref inherits (- (length inherits) 2))))
1320     (list (layout-class (svref inherits (1- (length inherits)))))))
1321 ram 1.38 (let ((new-layout (make-layout :class class
1322     :inherits inherits
1323     :inheritance-depth (length inherits)
1324     :length (dd-length info)
1325 ram 1.48 :info info))
1326     (old-layout (or compiler-layout old-layout)))
1327 ram 1.38 (cond
1328     ((not old-layout)
1329     (values class new-layout nil))
1330     ((not *type-system-initialized*)
1331     (setf (layout-info old-layout) info)
1332     (values class old-layout nil))
1333     ((redefine-layout-warning old-layout old-context
1334     new-layout new-context)
1335     (values class new-layout old-layout))
1336     (t
1337     (let ((old-info (layout-info old-layout)))
1338     (typecase old-info
1339     ((or defstruct-description)
1340     (cond ((redefine-structure-warning class old-info info)
1341     (values class new-layout old-layout))
1342     (t
1343     (setf (layout-info old-layout) info)
1344     (values class old-layout nil))))
1345     (null
1346     (setf (layout-info old-layout) info)
1347     (values class old-layout nil))
1348     (t
1349     (warn "Shouldn't happen! Some strange thing in LAYOUT-INFO:~
1350     ~% ~S"
1351     old-layout)
1352     (values class new-layout old-layout)))))))))
1353    
1354    
1355     ;;; COMPARE-SLOTS -- Internal
1356     ;;;
1357     ;;; Compares the slots of Old and New, returning 3 lists of slot names:
1358     ;;; 1] Slots which have moved,
1359     ;;; 2] Slots whose type has changed,
1360     ;;; 3] Deleted slots.
1361     ;;;
1362     (defun compare-slots (old new)
1363     (let* ((oslots (dd-slots old))
1364     (nslots (dd-slots new))
1365     (onames (mapcar #'dsd-name oslots))
1366     (nnames (mapcar #'dsd-name nslots)))
1367     (collect ((moved)
1368     (retyped))
1369     (dolist (name (intersection onames nnames))
1370     (let ((os (find name oslots :key #'dsd-name))
1371     (ns (find name nslots :key #'dsd-name)))
1372     (unless (subtypep (dsd-type ns) (dsd-type os))
1373     (retyped name))
1374     (unless (and (= (dsd-index os) (dsd-index ns))
1375     (eq (dsd-raw-type os) (dsd-raw-type ns)))
1376     (moved name))))
1377     (values (moved)
1378     (retyped)
1379     (set-difference onames nnames)))))
1380    
1381    
1382     ;;; REDEFINE-STRUCTURE-WARNING -- Internal
1383     ;;;
1384     ;;; Give a warning and return true if we are redefining a structure with
1385     ;;; different slots than in the currently loaded version.
1386     ;;;
1387     (defun redefine-structure-warning (class old new)
1388     (declare (type defstruct-description old new) (type class class)
1389     (ignore class))
1390     (let ((name (dd-name new)))
1391     (multiple-value-bind (moved retyped deleted)
1392     (compare-slots old new)
1393     (when (or moved retyped deleted)
1394     (warn
1395     "Incompatibly redefining slots of structure class ~S~@
1396     Make sure any uses of affected accessors are recompiled:~@
1397 ram 1.40 ~@[ These slots were moved to new positions:~% ~S~%~]~
1398     ~@[ These slots have new incompatible types:~% ~S~%~]~
1399 ram 1.38 ~@[ These slots were deleted:~% ~S~%~]"
1400     name moved retyped deleted)
1401     t))))
1402    
1403    
1404     ;;; %REDEFINE-DEFSTRUCT -- Internal
1405     ;;;
1406     ;;; This function is called when we are incompatibly redefining a structure
1407     ;;; Class to have the specified New-Layout. We signal an error with some
1408 ram 1.42 ;;; proceed options and return the layout that should be used.
1409 ram 1.38 ;;;
1410     (defun %redefine-defstruct (class old-layout new-layout)
1411 ram 1.40 (declare (type class class) (type layout old-layout new-layout))
1412 ram 1.38 (let ((name (class-proper-name class)))
1413     (restart-case
1414     (error "Redefining class ~S incompatibly with the current ~
1415     definition."
1416     name)
1417     (continue ()
1418     :report "Invalidate current definition."
1419     (warn "Previously loaded ~S accessors will no longer work." name)
1420 ram 1.40 (register-layout new-layout))
1421 ram 1.38 (clobber-it ()
1422     :report "Smash current layout, preserving old code."
1423     (warn "Any old ~S instances will be in a bad way.~@
1424     I hope you know what you're doing..."
1425     name)
1426 ram 1.40 (register-layout new-layout :invalidate nil
1427     :destruct-layout old-layout))))
1428 ram 1.38 (undefined-value))
1429    
1430    
1431     ;;; UNDEFINE-STRUCTURE -- Interface
1432     ;;;
1433 ram 1.54 ;;; Blow away all the compiler info for the structure CLASS.
1434 ram 1.38 ;;; Iterate over this type, clearing the compiler structure
1435     ;;; type info, and undefining all the associated functions.
1436     ;;;
1437 ram 1.54 (defun undefine-structure (class)
1438     (let ((info (layout-info (class-layout class))))
1439     (when (defstruct-description-p info)
1440     (let ((type (dd-name info)))
1441     (setf (info type compiler-layout type) nil)
1442     (undefine-function-name (dd-copier info))
1443     (undefine-function-name (dd-predicate info))
1444     (dolist (slot (dd-slots info))
1445     (let ((fun (dsd-accessor slot)))
1446     (undefine-function-name fun)
1447     (unless (dsd-read-only slot)
1448     (undefine-function-name `(setf ,fun))))))
1449     ;;
1450     ;; Clear out the SPECIFIER-TYPE cache so that subsequent references are
1451     ;; unknown types.
1452     (values-specifier-type-cache-clear)))
1453 ram 1.38 (undefined-value))
1454    
1455    
1456     ;;;; Compiler stuff:
1457    
1458     ;;; DEFINE-DEFSTRUCT-NAME -- Internal
1459     ;;;
1460     ;;; Like DEFINE-FUNCTION-NAME, but we also set the kind to :DECLARED and
1461     ;;; blow away any ASSUMED-TYPE. Also, if the thing is a slot accessor
1462     ;;; currently, quietly unaccessorize it. And if there are any undefined
1463     ;;; warnings, we nuke them.
1464     ;;;
1465     (defun define-defstruct-name (name)
1466     (when name
1467     (when (info function accessor-for name)
1468     (setf (info function accessor-for name) nil))
1469     (define-function-name name)
1470     (note-name-defined name :function)
1471     (setf (info function where-from name) :declared)
1472     (when (info function assumed-type name)
1473     (setf (info function assumed-type name) nil)))
1474     (undefined-value))
1475    
1476    
1477     ;;; INHERITS-FOR-STRUCTURE -- Internal
1478     ;;;
1479     ;;; This function is called at macroexpand time to compute the INHERITS
1480     ;;; vector for a structure type definition.
1481     ;;;
1482     (defun inherits-for-structure (info)
1483     (declare (type defstruct-description info))
1484     (let* ((include (dd-include info))
1485     (superclass-opt (dd-alternate-metaclass info))
1486     (super
1487     (if include
1488     (compiler-layout-or-lose (first include))
1489     (class-layout (find-class (or (first superclass-opt)
1490     'structure-object))))))
1491 dtc 1.63 (if (eq (dd-name info) 'lisp-stream)
1492     ;; Hack to added the stream class as a mixin for lisp-streams.
1493     (concatenate 'simple-vector (layout-inherits super)
1494     (vector super (class-layout (find-class 'stream))))
1495     (concatenate 'simple-vector (layout-inherits super) (vector super)))))
1496 ram 1.38
1497     ;;; %COMPILER-ONLY-DEFSTRUCT -- Internal
1498     ;;;
1499 ram 1.50 ;;; This function is called at compile-time to do the compile-time-only
1500 ram 1.38 ;;; actions for defining a structure type. It installs the class in the type
1501     ;;; system in a similar way to %DEFSTRUCT, but is quieter and safer in the case
1502 ram 1.50 ;;; of redefinition. Eval-when doesn't do the right thing when nested or
1503     ;;; non-top-level, so this is magically called by the compiler.
1504 ram 1.38 ;;;
1505     ;;; Basically, this function avoids trashing the compiler by only actually
1506     ;;; defining the class if there is no current definition. Instead, we just set
1507     ;;; the INFO TYPE COMPILER-LAYOUT.
1508     ;;;
1509     (defun %compiler-only-defstruct (info inherits)
1510 ram 1.48 (multiple-value-bind
1511     (class layout old-layout)
1512 ram 1.49 (multiple-value-bind
1513     (clayout clayout-p)
1514     (info type compiler-layout (dd-name info))
1515 ram 1.48 (ensure-structure-class info inherits
1516 ram 1.49 (if clayout-p "previously compiled" "current")
1517 ram 1.48 "compiled"
1518     clayout))
1519 ram 1.38 (cond
1520     (old-layout
1521 ram 1.55 (undefine-structure (layout-class old-layout))
1522 ram 1.38 (when (and (class-subclasses class)
1523     (not (eq layout old-layout)))
1524     (collect ((subs))
1525     (do-hash (class layout (class-subclasses class))
1526 ram 1.54 (declare (ignore layout))
1527     (undefine-structure class)
1528 ram 1.38 (subs (class-proper-name class)))
1529     (when (subs)
1530     (warn "Removing old subclasses of ~S:~% ~S"
1531     (class-name class) (subs))))))
1532     (t
1533     (unless (eq (class-layout class) layout)
1534 ram 1.40 (register-layout layout :invalidate nil))
1535 ram 1.38 (setf (find-class (dd-name info)) class)))
1536    
1537     (setf (info type compiler-layout (dd-name info)) layout))
1538    
1539     (undefined-value))
1540    
1541    
1542     ;;; %%Compiler-Defstruct -- External
1543     ;;;
1544     ;;; This function does the (compile load eval) time actions for updating the
1545 dtc 1.59 ;;; compiler's global meta-information to represent the definition of the
1546 ram 1.38 ;;; structure described by Info. This primarily amounts to setting up info
1547     ;;; about the accessor and other implicitly defined functions. The
1548     ;;; constructors are explicitly defined by top-level code.
1549     ;;;
1550     (defun %%compiler-defstruct (info)
1551     (declare (type defstruct-description info))
1552     (let* ((name (dd-name info))
1553     (class (find-class name)))
1554     (let ((copier (dd-copier info)))
1555     (when copier
1556     (proclaim `(ftype (function (,name) ,name) ,copier))))
1557    
1558     (let ((pred (dd-predicate info)))
1559     (when pred
1560     (define-defstruct-name pred)
1561     (setf (info function inlinep pred) :inline)
1562     (setf (info function inline-expansion pred)
1563     `(lambda (x) (typep x ',name)))))
1564 ram 1.40
1565 ram 1.38 (dolist (slot (dd-slots info))
1566     (let* ((fun (dsd-accessor slot))
1567     (setf-fun `(setf ,fun)))
1568     (when (and fun (eq (dsd-raw-type slot) 't))
1569     (define-defstruct-name fun)
1570     (setf (info function accessor-for fun) class)
1571     (unless (dsd-read-only slot)
1572     (define-defstruct-name setf-fun)
1573     (setf (info function accessor-for setf-fun) class))))))
1574    
1575     (undefined-value))
1576    
1577     (setf (symbol-function '%compiler-defstruct) #'%%compiler-defstruct)
1578    
1579    
1580     ;;; COPY-STRUCTURE -- Public
1581     ;;;
1582     ;;; Copy any old kind of structure.
1583     ;;;
1584     (defun copy-structure (structure)
1585     "Return a copy of Structure with the same (EQL) slot values."
1586     (declare (type structure-object structure) (optimize (speed 3) (safety 0)))
1587     (let* ((len (%instance-length structure))
1588     (res (%make-instance len))
1589     (layout (%instance-layout structure)))
1590     (declare (type index len))
1591     (when (layout-invalid layout)
1592     (error "Copying an obsolete structure:~% ~S" structure))
1593    
1594     (dotimes (i len)
1595     (declare (type index i))
1596     (setf (%instance-ref res i)
1597     (%instance-ref structure i)))
1598    
1599     (let ((raw-index (dd-raw-index (layout-info layout))))
1600     (when raw-index
1601     (let* ((data (%instance-ref structure raw-index))
1602     (raw-len (length data))
1603     (new (make-array raw-len :element-type '(unsigned-byte 32))))
1604     (declare (type (simple-array (unsigned-byte 32) (*)) data))
1605     (setf (%instance-ref res raw-index) new)
1606     (dotimes (i raw-len)
1607     (setf (aref new i) (aref data i))))))
1608    
1609     res))
1610    
1611    
1612     ;;; Default print and make-load-form methods.
1613    
1614 ram 1.1 (defun default-structure-print (structure stream depth)
1615     (declare (ignore depth))
1616 ram 1.44 (if (funcallable-instance-p structure)
1617 ram 1.46 (print-unreadable-object (structure stream :identity t :type t)
1618 ram 1.44 (write-string "Funcallable Structure" stream))
1619     (let* ((type (%instance-layout structure))
1620     (name (class-name (layout-class type)))
1621     (dd (layout-info type)))
1622 pw 1.67 (flet ((slot-accessor (slot)
1623     (let ((aname
1624     (intern (concatenate
1625     'simple-string
1626     (symbol-name (kernel::dd-conc-name dd))
1627     (dsd-%name slot)))))
1628     (fdefinition aname))))
1629     (if *print-pretty*
1630     (pprint-logical-block (stream nil :prefix "#S(" :suffix ")")
1631     (prin1 name stream)
1632     (let ((slots (dd-slots dd)))
1633     (when slots
1634     (write-char #\space stream)
1635     (pprint-indent :block 2 stream)
1636     (pprint-newline :linear stream)
1637     (loop
1638     (pprint-pop)
1639     (let ((slot (pop slots)))
1640     (write-char #\: stream)
1641     (output-symbol-name (dsd-%name slot) stream)
1642     (write-char #\space stream)
1643     (pprint-newline :miser stream)
1644     (output-object
1645     (funcall (slot-accessor slot) structure) stream)
1646     (when (null slots)
1647     (return))
1648     (write-char #\space stream)
1649     (pprint-newline :linear stream))))))
1650     (descend-into (stream)
1651     (write-string "#S(" stream)
1652     (prin1 name stream)
1653     (do ((index 0 (1+ index))
1654     (slots (dd-slots dd) (cdr slots)))
1655     ((or (null slots)
1656     (and (not *print-readably*)(eql *print-length* index)))
1657     (if (null slots)
1658     (write-string ")" stream)
1659     (write-string " ...)" stream)))
1660     (declare (type index index))
1661 wlott 1.34 (write-char #\space stream)
1662 pw 1.67 (write-char #\: stream)
1663     (let ((slot (first slots)))
1664     (output-symbol-name (dsd-%name slot) stream)
1665     (write-char #\space stream)
1666     (output-object
1667     (funcall (slot-accessor slot) structure) stream)))))))))
1668 wlott 1.29
1669     (defun make-structure-load-form (structure)
1670 ram 1.38 (declare (type structure-object structure))
1671     (let* ((class (layout-class (%instance-layout structure)))
1672     (fun (structure-class-make-load-form-fun class)))
1673 wlott 1.29 (etypecase fun
1674     ((member :just-dump-it-normally :ignore-it)
1675     fun)
1676     (null
1677 ram 1.38 (error "Structures of type ~S cannot be dumped as constants."
1678     (class-name class)))
1679 wlott 1.29 (function
1680     (funcall fun structure))
1681     (symbol
1682     (funcall (symbol-function fun) structure)))))

  ViewVC Help
Powered by ViewVC 1.1.5