0.6.9.11:
[sbcl.git] / src / compiler / macros.lisp
1 ;;;; miscellaneous types and macros used in writing the compiler
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
11
12 (in-package "SB!C")
13
14 (declaim (special *wild-type* *universal-type* *compiler-error-context*))
15
16 ;;; An INLINEP value describes how a function is called. The values
17 ;;; have these meanings:
18 ;;;     NIL     No declaration seen: do whatever you feel like, but don't 
19 ;;;             dump an inline expansion.
20 ;;; :NOTINLINE  NOTINLINE declaration seen: always do full function call.
21 ;;;    :INLINE  INLINE declaration seen: save expansion, expanding to it 
22 ;;;             if policy favors.
23 ;;; :MAYBE-INLINE
24 ;;;             Retain expansion, but only use it opportunistically.
25 (deftype inlinep () '(member :inline :maybe-inline :notinline nil))
26 \f
27 ;;;; the POLICY macro
28
29 (eval-when (:compile-toplevel :load-toplevel :execute)
30
31 ;;; a helper function for the POLICY macro: Look up a named optimization
32 ;;; quality in POLICY.
33 (declaim (ftype (function (policy symbol) policy-quality)))
34 (defun policy-quality (policy quality-name)
35   (the policy-quality
36        (cdr (assoc quality-name policy))))
37
38 ;;; A helper function for the POLICY macro: Return a list of symbols
39 ;;; naming the qualities which appear in EXPR.
40 (defun policy-qualities-used-by (expr)
41   (let ((result nil))
42     (labels ((recurse (x)
43                (if (listp x)
44                    (map nil #'recurse x)
45                    (when (policy-quality-p x)
46                      (pushnew x result)))))
47       (recurse expr)
48       result)))
49
50 ) ; EVAL-WHEN
51
52 ;;; syntactic sugar for querying optimization policy qualities
53 ;;;
54 ;;; Evaluate EXPR in terms of the current optimization policy for
55 ;;; NODE, or if NODE is NIL, in terms of the current policy as defined
56 ;;; by *DEFAULT-POLICY* and *CURRENT-POLICY*. (Using NODE=NIL is only
57 ;;; well-defined during IR1 conversion.)
58 ;;;
59 ;;; EXPR is a form which accesses the policy values by referring to
60 ;;; them by name, e.g. (> SPEED SPACE).
61 (defmacro policy (node expr)
62   (let* ((n-policy (gensym))
63          (binds (mapcar (lambda (name)
64                           `(,name (policy-quality ,n-policy ',name)))
65                         (policy-qualities-used-by expr))))
66     (/show "in POLICY" expr binds)
67     `(let* ((,n-policy (lexenv-policy ,(if node
68                                            `(node-lexenv ,node)
69                                            '*lexenv*)))
70             ,@binds)
71        ,expr)))
72 \f
73 ;;;; source-hacking defining forms
74
75 ;;; to be passed to PARSE-DEFMACRO when we want compiler errors
76 ;;; instead of real errors
77 #!-sb-fluid (declaim (inline convert-condition-into-compiler-error))
78 (defun convert-condition-into-compiler-error (datum &rest stuff)
79   (if (stringp datum)
80       (apply #'compiler-error datum stuff)
81       (compiler-error "~A"
82                       (if (symbolp datum)
83                           (apply #'make-condition datum stuff)
84                           datum))))
85
86 ;;; Parse a DEFMACRO-style lambda-list, setting things up so that a
87 ;;; compiler error happens if the syntax is invalid.
88 ;;;
89 ;;; Define a function that converts a special form or other magical
90 ;;; thing into IR1. LAMBDA-LIST is a defmacro style lambda list.
91 ;;; START-VAR and CONT-VAR are bound to the start and result
92 ;;; continuations for the resulting IR1. KIND is the function kind to
93 ;;; associate with NAME.
94 (defmacro def-ir1-translator (name (lambda-list start-var cont-var
95                                                 &key (kind :special-form))
96                                    &body body)
97   (let ((fn-name (symbolicate "IR1-CONVERT-" name))
98         (n-form (gensym))
99         (n-env (gensym)))
100     (multiple-value-bind (body decls doc)
101         (parse-defmacro lambda-list n-form body name "special form"
102                         :environment n-env
103                         :error-fun 'convert-condition-into-compiler-error)
104       `(progn
105          (declaim (ftype (function (continuation continuation t) (values))
106                          ,fn-name))
107          (defun ,fn-name (,start-var ,cont-var ,n-form)
108            (let ((,n-env *lexenv*))
109              ,@decls
110              ,body
111              (values)))
112          ,@(when doc
113              `((setf (fdocumentation ',name 'function) ,doc)))
114          ;; FIXME: Evidently "there can only be one!" -- we overwrite any
115          ;; other :IR1-CONVERT value. This deserves a warning, I think.
116          (setf (info :function :ir1-convert ',name) #',fn-name)
117          (setf (info :function :kind ',name) ,kind)
118          ;; It's nice to do this for error checking in the target
119          ;; SBCL, but it's not nice to do this when we're running in
120          ;; the cross-compilation host Lisp, which owns the
121          ;; SYMBOL-FUNCTION of its COMMON-LISP symbols.
122          #-sb-xc-host
123          ,@(when (eq kind :special-form)
124              `((setf (symbol-function ',name)
125                      (lambda (&rest rest)
126                        (declare (ignore rest))
127                        (error "can't FUNCALL the SYMBOL-FUNCTION of ~
128                                special forms")))))))))
129
130 ;;; (This is similar to DEF-IR1-TRANSLATOR, except that we pass if the
131 ;;; syntax is invalid.)
132 ;;;
133 ;;; Define a macro-like source-to-source transformation for the
134 ;;; function NAME. A source transform may "pass" by returning a
135 ;;; non-nil second value. If the transform passes, then the form is
136 ;;; converted as a normal function call. If the supplied arguments are
137 ;;; not compatible with the specified LAMBDA-LIST, then the transform
138 ;;; automatically passes.
139 ;;;
140 ;;; Source transforms may only be defined for functions. Source
141 ;;; transformation is not attempted if the function is declared
142 ;;; NOTINLINE. Source transforms should not examine their arguments.
143 ;;; If it matters how the function is used, then DEFTRANSFORM should
144 ;;; be used to define an IR1 transformation.
145 ;;;
146 ;;; If the desirability of the transformation depends on the current
147 ;;; OPTIMIZE parameters, then the POLICY macro should be used to
148 ;;; determine when to pass.
149 (defmacro def-source-transform (name lambda-list &body body)
150   (let ((fn-name
151          (if (listp name)
152              (collect ((pieces))
153                (dolist (piece name)
154                  (pieces "-")
155                  (pieces piece))
156                (apply #'symbolicate "SOURCE-TRANSFORM" (pieces)))
157              (symbolicate "SOURCE-TRANSFORM-" name)))
158         (n-form (gensym))
159         (n-env (gensym)))
160     (multiple-value-bind (body decls)
161         (parse-defmacro lambda-list n-form body name "form"
162                         :environment n-env
163                         :error-fun `(lambda (&rest stuff)
164                                       (declare (ignore stuff))
165                                       (return-from ,fn-name
166                                         (values nil t))))
167       `(progn
168          (defun ,fn-name (,n-form)
169            (let ((,n-env *lexenv*))
170              ,@decls
171              ,body))
172          (setf (info :function :source-transform ',name) #',fn-name)))))
173
174 ;;; Define a function that converts a use of (%PRIMITIVE NAME ..)
175 ;;; into Lisp code. LAMBDA-LIST is a DEFMACRO-style lambda list.
176 (defmacro def-primitive-translator (name lambda-list &body body)
177   (let ((fn-name (symbolicate "PRIMITIVE-TRANSLATE-" name))
178         (n-form (gensym))
179         (n-env (gensym)))
180     (multiple-value-bind (body decls)
181         (parse-defmacro lambda-list n-form body name "%primitive"
182                         :environment n-env
183                         :error-fun 'convert-condition-into-compiler-error)
184       `(progn
185          (defun ,fn-name (,n-form)
186            (let ((,n-env *lexenv*))
187              ,@decls
188              ,body))
189          (setf (gethash ',name *primitive-translators*) ',fn-name)))))
190 \f
191 ;;;; boolean attribute utilities
192 ;;;;
193 ;;;; We need to maintain various sets of boolean attributes for known
194 ;;;; functions and VOPs. To save space and allow for quick set
195 ;;;; operations, we represent the attributes as bits in a fixnum.
196
197 (deftype attributes () 'fixnum)
198
199 (eval-when (:compile-toplevel :load-toplevel :execute)
200
201 ;;; Given a list of attribute names and an alist that translates them
202 ;;; to masks, return the OR of the masks.
203 (defun compute-attribute-mask (names alist)
204   (collect ((res 0 logior))
205     (dolist (name names)
206       (let ((mask (cdr (assoc name alist))))
207         (unless mask
208           (error "unknown attribute name: ~S" name))
209         (res mask)))
210     (res)))
211
212 ) ; EVAL-WHEN
213
214 ;;; Parse the specification and generate some accessor macros.
215 ;;;
216 ;;; KLUDGE: This is expanded out twice, by cut-and-paste, in a
217 ;;;   (DEF!MACRO FOO (..) .. CL:GET-SETF-EXPANSION ..)
218 ;;;   #+SB-XC-HOST
219 ;;;   (SB!XC:DEFMACRO FOO (..) .. SB!XC:GET-SETF-EXPANSION ..)
220 ;;; arrangement, in order to get it to work in cross-compilation. This
221 ;;; duplication should be removed, perhaps by rewriting the macro in a
222 ;;; more cross-compiler-friendly way, or perhaps just by using some
223 ;;; (MACROLET ((FROB ..)) .. FROB .. FROB) form, but I don't want to
224 ;;; do it now, because the system isn't running yet, so it'd be too
225 ;;; hard to check that my changes were correct -- WHN 19990806
226 (def!macro def-boolean-attribute (name &rest attribute-names)
227   #!+sb-doc
228   "Def-Boolean-Attribute Name Attribute-Name*
229   Define a new class of boolean attributes, with the attributes having the
230   specified Attribute-Names. Name is the name of the class, which is used to
231   generate some macros to manipulate sets of the attributes:
232
233     NAME-attributep attributes attribute-name*
234       Return true if one of the named attributes is present, false otherwise.
235       When set with SETF, updates the place Attributes setting or clearing the
236       specified attributes.
237
238     NAME-attributes attribute-name*
239       Return a set of the named attributes."
240
241   (let ((translations-name (symbolicate "*" name "-ATTRIBUTE-TRANSLATIONS*"))
242         (test-name (symbolicate name "-ATTRIBUTEP")))
243     (collect ((alist))
244       (do ((mask 1 (ash mask 1))
245            (names attribute-names (cdr names)))
246           ((null names))
247         (alist (cons (car names) mask)))
248
249       `(progn
250
251          (eval-when (:compile-toplevel :load-toplevel :execute)
252            (defparameter ,translations-name ',(alist)))
253
254          (defmacro ,test-name (attributes &rest attribute-names)
255            "Automagically generated boolean attribute test function. See
256             Def-Boolean-Attribute."
257            `(logtest ,(compute-attribute-mask attribute-names
258                                               ,translations-name)
259                      (the attributes ,attributes)))
260
261          (define-setf-expander ,test-name (place &rest attributes
262                                                  &environment env)
263            "Automagically generated boolean attribute setter. See
264             Def-Boolean-Attribute."
265            #-sb-xc-host (declare (type sb!c::lexenv env))
266            ;; FIXME: It would be better if &ENVIRONMENT arguments
267            ;; were automatically declared to have type LEXENV by the
268            ;; hairy-argument-handling code.
269            (multiple-value-bind (temps values stores set get)
270                (get-setf-expansion place env)
271              (when (cdr stores)
272                (error "multiple store variables for ~S" place))
273              (let ((newval (gensym))
274                    (n-place (gensym))
275                    (mask (compute-attribute-mask attributes
276                                                  ,translations-name)))
277                (values `(,@temps ,n-place)
278                        `(,@values ,get)
279                        `(,newval)
280                        `(let ((,(first stores)
281                                (if ,newval
282                                    (logior ,n-place ,mask)
283                                    (logand ,n-place ,(lognot mask)))))
284                           ,set
285                           ,newval)
286                        `(,',test-name ,n-place ,@attributes)))))
287
288          (defmacro ,(symbolicate name "-ATTRIBUTES") (&rest attribute-names)
289            "Automagically generated boolean attribute creation function. See
290             Def-Boolean-Attribute."
291            (compute-attribute-mask attribute-names ,translations-name))))))
292 ;;; #+SB-XC-HOST SB!XC:DEFMACRO version is in late-macros.lisp. -- WHN 19990806
293
294 ;;; And now for some gratuitous pseudo-abstraction...
295 (defmacro attributes-union (&rest attributes)
296   #!+sb-doc
297   "Returns the union of all the sets of boolean attributes which are its
298   arguments."
299   `(the attributes
300         (logior ,@(mapcar #'(lambda (x) `(the attributes ,x)) attributes))))
301 (defmacro attributes-intersection (&rest attributes)
302   #!+sb-doc
303   "Returns the intersection of all the sets of boolean attributes which are its
304   arguments."
305   `(the attributes
306         (logand ,@(mapcar #'(lambda (x) `(the attributes ,x)) attributes))))
307 (declaim (ftype (function (attributes attributes) boolean) attributes=))
308 #!-sb-fluid (declaim (inline attributes=))
309 (defun attributes= (attr1 attr2)
310   #!+sb-doc
311   "Returns true if the attributes present in Attr1 are identical to those in
312   Attr2."
313   (eql attr1 attr2))
314 \f
315 ;;;; lambda-list parsing utilities
316 ;;;;
317 ;;;; IR1 transforms, optimizers and type inferencers need to be able
318 ;;;; to parse the IR1 representation of a function call using a
319 ;;;; standard function lambda-list.
320
321 (eval-when (:compile-toplevel :load-toplevel :execute)
322
323 ;;; Given a DEFTRANSFORM-style lambda-list, generate code that parses
324 ;;; the arguments of a combination with respect to that lambda-list.
325 ;;; BODY is the the list of forms which are to be evaluated within the
326 ;;; bindings. ARGS is the variable that holds list of argument
327 ;;; continuations. ERROR-FORM is a form which is evaluated when the
328 ;;; syntax of the supplied arguments is incorrect or a non-constant
329 ;;; argument keyword is supplied. Defaults and other gunk are ignored.
330 ;;; The second value is a list of all the arguments bound. We make the
331 ;;; variables IGNORABLE so that we don't have to manually declare them
332 ;;; Ignore if their only purpose is to make the syntax work.
333 (declaim (ftype (function (list list symbol t) list) parse-deftransform))
334 (defun parse-deftransform (lambda-list body args error-form)
335   (multiple-value-bind (req opt restp rest keyp keys allowp)
336       (parse-lambda-list lambda-list)
337     (let* ((min-args (length req))
338            (max-args (+ min-args (length opt)))
339            (n-keys (gensym)))
340       (collect ((binds)
341                 (vars)
342                 (pos 0 +)
343                 (keywords))
344         (dolist (arg req)
345           (vars arg)
346           (binds `(,arg (nth ,(pos) ,args)))
347           (pos 1))
348
349         (dolist (arg opt)
350           (let ((var (if (atom arg) arg (first  arg))))
351             (vars var)
352             (binds `(,var (nth ,(pos) ,args)))
353             (pos 1)))
354
355         (when restp
356           (vars rest)
357           (binds `(,rest (nthcdr ,(pos) ,args))))
358
359         (dolist (spec keys)
360           (if (or (atom spec) (atom (first spec)))
361               (let* ((var (if (atom spec) spec (first spec)))
362                      (key (intern (symbol-name var) "KEYWORD")))
363                 (vars var)
364                 (binds `(,var (find-keyword-continuation ,n-keys ,key)))
365                 (keywords key))
366               (let* ((head (first spec))
367                      (var (second head))
368                      (key (first head)))
369                 (vars var)
370                 (binds `(,var (find-keyword-continuation ,n-keys ,key)))
371                 (keywords key))))
372
373         (let ((n-length (gensym))
374               (limited-legal (not (or restp keyp))))
375           (values
376            `(let ((,n-length (length ,args))
377                   ,@(when keyp `((,n-keys (nthcdr ,(pos) ,args)))))
378               (unless (and
379                        ;; FIXME: should be PROPER-LIST-OF-LENGTH-P
380                        ,(if limited-legal
381                             `(<= ,min-args ,n-length ,max-args)
382                             `(<= ,min-args ,n-length))
383                        ,@(when keyp
384                            (if allowp
385                                `((check-keywords-constant ,n-keys))
386                                `((check-transform-keys ,n-keys ',(keywords))))))
387                 ,error-form)
388               (let ,(binds)
389                 (declare (ignorable ,@(vars)))
390                 ,@body))
391            (vars)))))))
392
393 ) ; EVAL-WHEN
394 \f
395 ;;;; DEFTRANSFORM
396
397 ;;; Define an IR1 transformation for NAME. An IR1 transformation
398 ;;; computes a lambda that replaces the function variable reference
399 ;;; for the call. A transform may pass (decide not to transform the
400 ;;; call) by calling the GIVE-UP-IR1-TRANSFORM function. LAMBDA-LIST
401 ;;; both determines how the current call is parsed and specifies the
402 ;;; LAMBDA-LIST for the resulting lambda.
403 ;;;
404 ;;; We parse the call and bind each of the lambda-list variables to
405 ;;; the continuation which represents the value of the argument. When
406 ;;; parsing the call, we ignore the defaults, and always bind the
407 ;;; variables for unsupplied arguments to NIL. If a required argument
408 ;;; is missing, an unknown keyword is supplied, or an argument keyword
409 ;;; is not a constant, then the transform automatically passes. The
410 ;;; DECLARATIONS apply to the bindings made by DEFTRANSFORM at
411 ;;; transformation time, rather than to the variables of the resulting
412 ;;; lambda. Bound-but-not-referenced warnings are suppressed for the
413 ;;; lambda-list variables. The DOC-STRING is used when printing
414 ;;; efficiency notes about the defined transform.
415 ;;;
416 ;;; Normally, the body evaluates to a form which becomes the body of
417 ;;; an automatically constructed lambda. We make LAMBDA-LIST the
418 ;;; lambda-list for the lambda, and automatically insert declarations
419 ;;; of the argument and result types. If the second value of the body
420 ;;; is non-null, then it is a list of declarations which are to be
421 ;;; inserted at the head of the lambda. Automatic lambda generation
422 ;;; may be inhibited by explicitly returning a lambda from the body.
423 ;;;
424 ;;; The ARG-TYPES and RESULT-TYPE are used to create a function type
425 ;;; which the call must satisfy before transformation is attempted.
426 ;;; The function type specifier is constructed by wrapping (FUNCTION
427 ;;; ...) around these values, so the lack of a restriction may be
428 ;;; specified by omitting the argument or supplying *. The argument
429 ;;; syntax specified in the ARG-TYPES need not be the same as that in
430 ;;; the LAMBDA-LIST, but the transform will never happen if the
431 ;;; syntaxes can't be satisfied simultaneously. If there is an
432 ;;; existing transform for the same function that has the same type,
433 ;;; then it is replaced with the new definition.
434 ;;;
435 ;;; These are the legal keyword options:
436 ;;;   :RESULT - A variable which is bound to the result continuation.
437 ;;;   :NODE   - A variable which is bound to the combination node for the call.
438 ;;;   :POLICY - A form which is supplied to the POLICY macro to determine
439 ;;;             whether this transformation is appropriate. If the result
440 ;;;             is false, then the transform automatically gives up.
441 ;;;   :EVAL-NAME
442 ;;;           - The name and argument/result types are actually forms to be
443 ;;;             evaluated. Useful for getting closures that transform similar
444 ;;;             functions.
445 ;;;   :DEFUN-ONLY
446 ;;;           - Don't actually instantiate a transform, instead just DEFUN
447 ;;;             Name with the specified transform definition function. This
448 ;;;             may be later instantiated with %DEFTRANSFORM.
449 ;;;   :IMPORTANT
450 ;;;           - If supplied and non-NIL, note this transform as ``important,''
451 ;;;             which means efficiency notes will be generated when this
452 ;;;             transform fails even if INHIBIT-WARNINGS=SPEED (but not if
453 ;;;             INHIBIT-WARNINGS>SPEED).
454 ;;;   :WHEN {:NATIVE | :BYTE | :BOTH}
455 ;;;           - Indicates whether this transform applies to native code,
456 ;;;             byte-code or both (default :native.)
457 (defmacro deftransform (name (lambda-list &optional (arg-types '*)
458                                           (result-type '*)
459                                           &key result policy node defun-only
460                                           eval-name important (when :native))
461                              &body body-decls-doc)
462   (when (and eval-name defun-only)
463     (error "can't specify both DEFUN-ONLY and EVAL-NAME"))
464   (multiple-value-bind (body decls doc) (parse-body body-decls-doc)
465     (let ((n-args (gensym))
466           (n-node (or node (gensym)))
467           (n-decls (gensym))
468           (n-lambda (gensym))
469           (decls-body `(,@decls ,@body)))
470       (multiple-value-bind (parsed-form vars)
471           (parse-deftransform lambda-list
472                               (if policy
473                                   `((unless (policy ,n-node ,policy)
474                                       (give-up-ir1-transform))
475                                     ,@decls-body)
476                                   body)
477                               n-args
478                               '(give-up-ir1-transform))
479         (let ((stuff
480                `((,n-node)
481                  (let* ((,n-args (basic-combination-args ,n-node))
482                         ,@(when result
483                             `((,result (node-cont ,n-node)))))
484                    (multiple-value-bind (,n-lambda ,n-decls)
485                        ,parsed-form
486                      (if (and (consp ,n-lambda) (eq (car ,n-lambda) 'lambda))
487                          ,n-lambda
488                        `(lambda ,',lambda-list
489                           (declare (ignorable ,@',vars))
490                           ,@,n-decls
491                           ,,n-lambda)))))))
492           (if defun-only
493               `(defun ,name ,@(when doc `(,doc)) ,@stuff)
494               `(%deftransform
495                 ,(if eval-name name `',name)
496                 ,(if eval-name
497                      ``(function ,,arg-types ,,result-type)
498                      `'(function ,arg-types ,result-type))
499                 #'(lambda ,@stuff)
500                 ,doc
501                 ,(if important t nil)
502                 ,when)))))))
503 \f
504 ;;;; DEFKNOWN and DEFOPTIMIZER
505
506 ;;; This macro should be the way that all implementation independent
507 ;;; information about functions is made known to the compiler.
508 ;;;
509 ;;; FIXME: The comment above suggests that perhaps some of my added
510 ;;; FTYPE declarations are in poor taste. Should I change my
511 ;;; declarations, or change the comment, or what?
512 ;;;
513 ;;; FIXME: DEFKNOWN is needed only at build-the-system time. Figure
514 ;;; out some way to keep it from appearing in the target system.
515 ;;;
516 ;;; Declare the function NAME to be a known function. We construct a
517 ;;; type specifier for the function by wrapping (FUNCTION ...) around
518 ;;; the ARG-TYPES and RESULT-TYPE. ATTRIBUTES is an unevaluated list
519 ;;; of boolean attributes of the function. These attributes are
520 ;;; meaningful here:
521 ;;;
522 ;;;     CALL
523 ;;;        May call functions that are passed as arguments. In order
524 ;;;        to determine what other effects are present, we must find
525 ;;;        the effects of all arguments that may be functions.
526 ;;;
527 ;;;     UNSAFE
528 ;;;        May incorporate arguments in the result or somehow pass
529 ;;;        them upward.
530 ;;;
531 ;;;     UNWIND
532 ;;;        May fail to return during correct execution. Errors
533 ;;;        are O.K.
534 ;;;
535 ;;;     ANY
536 ;;;        The (default) worst case. Includes all the other bad
537 ;;;        things, plus any other possible bad thing.
538 ;;;
539 ;;;     FOLDABLE
540 ;;;        May be constant-folded. The function has no side effects,
541 ;;;        but may be affected by side effects on the arguments. E.g.
542 ;;;        SVREF, MAPC.
543 ;;;
544 ;;;     FLUSHABLE
545 ;;;        May be eliminated if value is unused. The function has
546 ;;;        no side effects except possibly CONS. If a function is
547 ;;;        defined to signal errors, then it is not flushable even
548 ;;;        if it is movable or foldable.
549 ;;;
550 ;;;     MOVABLE
551 ;;;        May be moved with impunity. Has no side effects except
552 ;;;        possibly CONS, and is affected only by its arguments.
553 ;;;
554 ;;;     PREDICATE
555 ;;;         A true predicate likely to be open-coded. This is a
556 ;;;         hint to IR1 conversion that it should ensure calls always
557 ;;;         appear as an IF test. Not usually specified to DEFKNOWN,
558 ;;;         since this is implementation dependent, and is usually
559 ;;;         automatically set by the DEFINE-VOP :CONDITIONAL option.
560 ;;;
561 ;;; NAME may also be a list of names, in which case the same
562 ;;; information is given to all the names. The keywords specify the
563 ;;; initial values for various optimizers that the function might
564 ;;; have.
565 (defmacro defknown (name arg-types result-type &optional (attributes '(any))
566                          &rest keys)
567   (when (and (intersection attributes '(any call unwind))
568              (intersection attributes '(movable)))
569     (error "function cannot have both good and bad attributes: ~S" attributes))
570
571   `(%defknown ',(if (and (consp name)
572                          (not (eq (car name) 'setf)))
573                     name
574                     (list name))
575               '(function ,arg-types ,result-type)
576               (ir1-attributes ,@(if (member 'any attributes)
577                                     (union '(call unsafe unwind) attributes)
578                                     attributes))
579               ,@keys))
580
581 ;;; Create a function which parses combination args according to WHAT
582 ;;; and LAMBDA-LIST, where WHAT is either a function name or a list
583 ;;; (FUNCTION-NAME KIND) and does some KIND of optimization.
584 ;;;
585 ;;; The FUNCTION-NAME must name a known function. LAMBDA-LIST is used
586 ;;; to parse the arguments to the combination as in DEFTRANSFORM. If
587 ;;; the argument syntax is invalid or there are non-constant keys,
588 ;;; then we simply return NIL.
589 ;;;
590 ;;; The function is DEFUN'ed as FUNCTION-KIND-OPTIMIZER. Possible
591 ;;; kinds are DERIVE-TYPE, OPTIMIZER, LTN-ANNOTATE and IR2-CONVERT. If
592 ;;; a symbol is specified instead of a (FUNCTION KIND) list, then we
593 ;;; just do a DEFUN with the symbol as its name, and don't do anything
594 ;;; with the definition. This is useful for creating optimizers to be
595 ;;; passed by name to DEFKNOWN.
596 ;;;
597 ;;; If supplied, NODE-VAR is bound to the combination node being
598 ;;; optimized. If additional VARS are supplied, then they are used as
599 ;;; the rest of the optimizer function's lambda-list. LTN-ANNOTATE
600 ;;; methods are passed an additional POLICY argument, and IR2-CONVERT
601 ;;; methods are passed an additional IR2-BLOCK argument.
602 (defmacro defoptimizer (what (lambda-list &optional (n-node (gensym))
603                                           &rest vars)
604                              &body body)
605   (let ((name (if (symbolp what) what
606                   (symbolicate (first what) "-" (second what) "-OPTIMIZER"))))
607
608     (let ((n-args (gensym)))
609       `(progn
610         (defun ,name (,n-node ,@vars)
611           (let ((,n-args (basic-combination-args ,n-node)))
612             ,(parse-deftransform lambda-list body n-args
613                                  `(return-from ,name nil))))
614         ,@(when (consp what)
615             `((setf (,(symbolicate "FUNCTION-INFO-" (second what))
616                      (function-info-or-lose ',(first what)))
617                     #',name)))))))
618 \f
619 ;;;; IR groveling macros
620
621 ;;; Iterate over the blocks in a component, binding BLOCK-VAR to each
622 ;;; block in turn. The value of ENDS determines whether to iterate
623 ;;; over dummy head and tail blocks:
624 ;;;    NIL  -- Skip Head and Tail (the default)
625 ;;;   :HEAD -- Do head but skip tail
626 ;;;   :TAIL -- Do tail but skip head
627 ;;;   :BOTH -- Do both head and tail
628 ;;;
629 ;;; If supplied, RESULT-FORM is the value to return.
630 (defmacro do-blocks ((block-var component &optional ends result) &body body)
631   #!+sb-doc
632   (unless (member ends '(nil :head :tail :both))
633     (error "losing ENDS value: ~S" ends))
634   (let ((n-component (gensym))
635         (n-tail (gensym)))
636     `(let* ((,n-component ,component)
637             (,n-tail ,(if (member ends '(:both :tail))
638                           nil
639                           `(component-tail ,n-component))))
640        (do ((,block-var ,(if (member ends '(:both :head))
641                              `(component-head ,n-component)
642                              `(block-next (component-head ,n-component)))
643                         (block-next ,block-var)))
644            ((eq ,block-var ,n-tail) ,result)
645          ,@body))))
646 (defmacro do-blocks-backwards ((block-var component &optional ends result) &body body)
647   #!+sb-doc
648   "Do-Blocks-Backwards (Block-Var Component [Ends] [Result-Form]) {Declaration}* {Form}*
649   Like Do-Blocks, only iterate over the blocks in reverse order."
650   (unless (member ends '(nil :head :tail :both))
651     (error "losing ENDS value: ~S" ends))
652   (let ((n-component (gensym))
653         (n-head (gensym)))
654     `(let* ((,n-component ,component)
655             (,n-head ,(if (member ends '(:both :head))
656                           nil
657                           `(component-head ,n-component))))
658        (do ((,block-var ,(if (member ends '(:both :tail))
659                              `(component-tail ,n-component)
660                              `(block-prev (component-tail ,n-component)))
661                         (block-prev ,block-var)))
662            ((eq ,block-var ,n-head) ,result)
663          ,@body))))
664
665 ;;; Could change it not to replicate the code someday perhaps...
666 (defmacro do-uses ((node-var continuation &optional result) &body body)
667   #!+sb-doc
668   "Do-Uses (Node-Var Continuation [Result]) {Declaration}* {Form}*
669   Iterate over the uses of Continuation, binding Node to each one
670   successively."
671   (once-only ((n-cont continuation))
672     `(ecase (continuation-kind ,n-cont)
673        (:unused)
674        (:inside-block
675         (block nil
676           (let ((,node-var (continuation-use ,n-cont)))
677             ,@body
678             ,result)))
679        ((:block-start :deleted-block-start)
680         (dolist (,node-var (block-start-uses (continuation-block ,n-cont))
681                            ,result)
682           ,@body)))))
683
684 ;;; In the forward case, we terminate on Last-Cont so that we don't
685 ;;; have to worry about our termination condition being changed when
686 ;;; new code is added during the iteration. In the backward case, we
687 ;;; do NODE-PREV before evaluating the body so that we can keep going
688 ;;; when the current node is deleted.
689 ;;;
690 ;;; When RESTART-P is supplied to DO-NODES, we start iterating over
691 ;;; again at the beginning of the block when we run into a
692 ;;; continuation whose block differs from the one we are trying to
693 ;;; iterate over, either beacuse the block was split, or because a
694 ;;; node was deleted out from under us (hence its block is NIL.) If
695 ;;; the block start is deleted, we just punt. With RESTART-P, we are
696 ;;; also more careful about termination, re-indirecting the BLOCK-LAST
697 ;;; each time.
698 (defmacro do-nodes ((node-var cont-var block &key restart-p) &body body)
699   #!+sb-doc
700   "Do-Nodes (Node-Var Cont-Var Block {Key Value}*) {Declaration}* {Form}*
701   Iterate over the nodes in Block, binding Node-Var to the each node and
702   Cont-Var to the node's Cont. The only keyword option is Restart-P, which
703   causes iteration to be restarted when a node is deleted out from under us (if
704   not supplied, this is an error.)"
705   (let ((n-block (gensym))
706         (n-last-cont (gensym)))
707     `(let* ((,n-block ,block)
708             ,@(unless restart-p
709                 `((,n-last-cont (node-cont (block-last ,n-block))))))
710        (do* ((,node-var (continuation-next (block-start ,n-block))
711                         ,(if restart-p
712                              `(cond
713                                ((eq (continuation-block ,cont-var) ,n-block)
714                                 (assert (continuation-next ,cont-var))
715                                 (continuation-next ,cont-var))
716                                (t
717                                 (let ((start (block-start ,n-block)))
718                                   (unless (eq (continuation-kind start)
719                                               :block-start)
720                                     (return nil))
721                                   (continuation-next start))))
722                              `(continuation-next ,cont-var)))
723              (,cont-var (node-cont ,node-var) (node-cont ,node-var)))
724             (())
725          ,@body
726          (when ,(if restart-p
727                     `(eq ,node-var (block-last ,n-block))
728                     `(eq ,cont-var ,n-last-cont))
729            (return nil))))))
730 (defmacro do-nodes-backwards ((node-var cont-var block) &body body)
731   #!+sb-doc
732   "Do-Nodes-Backwards (Node-Var Cont-Var Block) {Declaration}* {Form}*
733   Like Do-Nodes, only iterates in reverse order."
734   (let ((n-block (gensym))
735         (n-start (gensym))
736         (n-last (gensym))
737         (n-next (gensym)))
738     `(let* ((,n-block ,block)
739             (,n-start (block-start ,n-block))
740             (,n-last (block-last ,n-block)))
741        (do* ((,cont-var (node-cont ,n-last) ,n-next)
742              (,node-var ,n-last (continuation-use ,cont-var))
743              (,n-next (node-prev ,node-var) (node-prev ,node-var)))
744             (())
745          ,@body
746          (when (eq ,n-next ,n-start)
747            (return nil))))))
748
749 ;;; The lexical environment is presumably already null...
750 (defmacro with-ir1-environment (node &rest forms)
751   #!+sb-doc
752   "With-IR1-Environment Node Form*
753   Bind the IR1 context variables so that IR1 conversion can be done after the
754   main conversion pass has finished."
755   (let ((n-node (gensym)))
756     `(let* ((,n-node ,node)
757             (*current-component* (block-component (node-block ,n-node)))
758             (*lexenv* (node-lexenv ,n-node))
759             (*current-path* (node-source-path ,n-node)))
760        ,@forms)))
761
762 ;;; Bind the hashtables used for keeping track of global variables,
763 ;;; functions, &c. Also establish condition handlers.
764 (defmacro with-ir1-namespace (&body forms)
765   `(let ((*free-variables* (make-hash-table :test 'eq))
766          (*free-functions* (make-hash-table :test 'equal))
767          (*constants* (make-hash-table :test 'equal))
768          (*source-paths* (make-hash-table :test 'eq)))
769      (handler-bind ((compiler-error #'compiler-error-handler)
770                     (style-warning #'compiler-style-warning-handler)
771                     (warning #'compiler-warning-handler))
772        ,@forms)))
773
774 (defmacro lexenv-find (name slot &key test)
775   #!+sb-doc
776   "LEXENV-FIND Name Slot {Key Value}*
777   Look up Name in the lexical environment namespace designated by Slot,
778   returning the <value, T>, or <NIL, NIL> if no entry. The :TEST keyword
779   may be used to determine the name equality predicate."
780   (once-only ((n-res `(assoc ,name (,(symbolicate "LEXENV-" slot) *lexenv*)
781                              :test ,(or test '#'eq))))
782     `(if ,n-res
783          (values (cdr ,n-res) t)
784          (values nil nil))))
785 \f
786 ;;; These functions are called by the expansion of the DEFPRINTER
787 ;;; macro to do the actual printing.
788 (declaim (ftype (function (symbol t stream &optional t) (values))
789                 defprinter-prin1 defprinter-princ))
790 (defun defprinter-prin1 (name value stream &optional indent)
791   (declare (ignore indent))
792   (defprinter-prinx #'prin1 name value stream))
793 (defun defprinter-princ (name value stream &optional indent)
794   (declare (ignore indent))
795   (defprinter-prinx #'princ name value stream))
796 (defun defprinter-prinx (prinx name value stream)
797   (declare (type function prinx))
798   (write-char #\space stream)
799   (when *print-pretty*
800     (pprint-newline :linear stream))
801   (format stream ":~A " name)
802   (funcall prinx value stream)
803   (values))
804
805 ;; Define some kind of reasonable PRINT-OBJECT method for a STRUCTURE-OBJECT.
806 ;;
807 ;; NAME is the name of the structure class, and CONC-NAME is the same as in
808 ;; DEFSTRUCT.
809 ;;
810 ;; The SLOT-DESCS describe how each slot should be printed. Each SLOT-DESC can
811 ;; be a slot name, indicating that the slot should simply be printed. A
812 ;; SLOT-DESC may also be a list of a slot name and other stuff. The other stuff
813 ;; is composed of keywords followed by expressions. The expressions are
814 ;; evaluated with the variable which is the slot name bound to the value of the
815 ;; slot. These keywords are defined:
816 ;;
817 ;; :PRIN1    Print the value of the expression instead of the slot value.
818 ;; :PRINC    Like :PRIN1, only princ the value
819 ;; :TEST     Only print something if the test is true.
820 ;;
821 ;; If no printing thing is specified then the slot value is printed as PRIN1.
822 ;;
823 ;; The structure being printed is bound to STRUCTURE and the stream is bound to
824 ;; STREAM.
825 (defmacro defprinter ((name &key (conc-name (concatenate 'simple-string
826                                                          (symbol-name name)
827                                                          "-")))
828                       &rest slot-descs)
829   (flet ((sref (slot-name)
830            `(,(symbolicate conc-name slot-name) structure)))
831     (collect ((prints))
832       (dolist (slot-desc slot-descs)
833         (if (atom slot-desc)
834           (prints `(defprinter-prin1 ',slot-desc ,(sref slot-desc) stream))
835           (let ((sname (first slot-desc))
836                 (test t))
837             (collect ((stuff))
838               (do ((option (rest slot-desc) (cddr option)))
839                   ((null option)
840                    (prints
841                     `(let ((,sname ,(sref sname)))
842                        (when ,test
843                          ,@(or (stuff)
844                                `((defprinter-prin1 ',sname ,sname
845                                    stream)))))))
846                 (case (first option)
847                   (:prin1
848                    (stuff `(defprinter-prin1 ',sname ,(second option)
849                              stream)))
850                   (:princ
851                    (stuff `(defprinter-princ ',sname ,(second option)
852                              stream)))
853                   (:test (setq test (second option)))
854                   (t
855                    (error "bad DEFPRINTER option: ~S" (first option)))))))))
856
857       `(def!method print-object ((structure ,name) stream)
858          (print-unreadable-object (structure stream :type t)
859            (pprint-logical-block (stream nil)
860              ;;(pprint-indent :current 2 stream)
861              ,@(prints)))))))
862 \f
863 ;;;; the Event statistics/trace utility
864
865 ;;; FIXME: This seems to be useful for troubleshooting and
866 ;;; experimentation, not for ordinary use, so it should probably
867 ;;; become conditional on SB-SHOW.
868
869 (eval-when (:compile-toplevel :load-toplevel :execute)
870
871 (defstruct event-info
872   ;; The name of this event.
873   (name (required-argument) :type symbol)
874   ;; The string rescribing this event.
875   (description (required-argument) :type string)
876   ;; The name of the variable we stash this in.
877   (var (required-argument) :type symbol)
878   ;; The number of times this event has happened.
879   (count 0 :type fixnum)
880   ;; The level of significance of this event.
881   (level (required-argument) :type unsigned-byte)
882   ;; If true, a function that gets called with the node that the event
883   ;; happened to.
884   (action nil :type (or function null)))
885
886 ;;; A hashtable from event names to event-info structures.
887 (defvar *event-info* (make-hash-table :test 'eq))
888
889 ;;; Return the event info for Name or die trying.
890 (declaim (ftype (function (t) event-info) event-info-or-lose))
891 (defun event-info-or-lose (name)
892   (let ((res (gethash name *event-info*)))
893     (unless res
894       (error "~S is not the name of an event." name))
895     res))
896
897 ) ; EVAL-WHEN
898
899 (declaim (ftype (function (symbol) fixnum) event-count))
900 (defun event-count (name)
901   #!+sb-doc
902   "Return the number of times that Event has happened."
903   (event-info-count (event-info-or-lose name)))
904
905 (declaim (ftype (function (symbol) (or function null)) event-action))
906 (defun event-action (name)
907   #!+sb-doc
908   "Return the function that is called when Event happens. If this is null,
909   there is no action. The function is passed the node to which the event
910   happened, or NIL if there is no relevant node. This may be set with SETF."
911   (event-info-action (event-info-or-lose name)))
912 (declaim (ftype (function (symbol (or function null)) (or function null))
913                 %set-event-action))
914 (defun %set-event-action (name new-value)
915   (setf (event-info-action (event-info-or-lose name))
916         new-value))
917 (defsetf event-action %set-event-action)
918
919 (declaim (ftype (function (symbol) unsigned-byte) event-level))
920 (defun event-level (name)
921   #!+sb-doc
922   "Return the non-negative integer which represents the level of significance
923   of the event Name. This is used to determine whether to print a message when
924   the event happens. This may be set with SETF."
925   (event-info-level (event-info-or-lose name)))
926 (declaim (ftype (function (symbol unsigned-byte) unsigned-byte) %set-event-level))
927 (defun %set-event-level (name new-value)
928   (setf (event-info-level (event-info-or-lose name))
929         new-value))
930 (defsetf event-level %set-event-level)
931
932 ;;; Make an EVENT-INFO structure and stash it in a variable so we can
933 ;;; get at it quickly.
934 (defmacro defevent (name description &optional (level 0))
935   #!+sb-doc
936   "Defevent Name Description
937   Define a new kind of event. Name is a symbol which names the event and
938   Description is a string which describes the event. Level (default 0) is the
939   level of significance associated with this event; it is used to determine
940   whether to print a Note when the event happens."
941   (let ((var-name (symbolicate "*" name "-EVENT-INFO*")))
942     `(eval-when (:compile-toplevel :load-toplevel :execute)
943        (defvar ,var-name
944          (make-event-info :name ',name
945                           :description ',description
946                           :var ',var-name
947                           :level ,level))
948        (setf (gethash ',name *event-info*) ,var-name)
949        ',name)))
950
951 (declaim (type unsigned-byte *event-note-threshold*))
952 (defvar *event-note-threshold* 1
953   #!+sb-doc
954   "This variable is a non-negative integer specifying the lowest level of
955   event that will print a note when it occurs.")
956
957 ;;; Increment the counter and do any action. Mumble about the event if
958 ;;; policy indicates.
959 (defmacro event (name &optional node)
960   #!+sb-doc
961   "Event Name Node
962   Note that the event with the specified Name has happened. Node is evaluated
963   to determine the node to which the event happened."
964   `(%event ,(event-info-var (event-info-or-lose name)) ,node))
965
966 (declaim (ftype (function (&optional unsigned-byte stream) (values)) event-statistics))
967 (defun event-statistics (&optional (min-count 1) (stream *standard-output*))
968   #!+sb-doc
969   "Print a listing of events and their counts, sorted by the count. Events
970   that happened fewer than Min-Count times will not be printed. Stream is the
971   stream to write to."
972   (collect ((info))
973     (maphash #'(lambda (k v)
974                  (declare (ignore k))
975                  (when (>= (event-info-count v) min-count)
976                    (info v)))
977              *event-info*)
978     (dolist (event (sort (info) #'> :key #'event-info-count))
979       (format stream "~6D: ~A~%" (event-info-count event)
980               (event-info-description event)))
981     (values))
982   (values))
983
984 (declaim (ftype (function nil (values)) clear-event-statistics))
985 (defun clear-event-statistics ()
986   (maphash #'(lambda (k v)
987                (declare (ignore k))
988                (setf (event-info-count v) 0))
989            *event-info*)
990   (values))
991 \f
992 ;;;; functions on directly-linked lists (linked through specialized
993 ;;;; NEXT operations)
994
995 #!-sb-fluid (declaim (inline find-in position-in map-in))
996
997 (defun find-in (next
998                 element
999                 list
1000                 &key
1001                 (key #'identity)
1002                 (test #'eql test-p)
1003                 (test-not nil not-p))
1004   #!+sb-doc
1005   "Find Element in a null-terminated List linked by the accessor function
1006   Next. Key, Test and Test-Not are the same as for generic sequence
1007   functions."
1008   (when (and test-p not-p)
1009     (error "It's silly to supply both :TEST and :TEST-NOT arguments."))
1010   (if not-p
1011       (do ((current list (funcall next current)))
1012           ((null current) nil)
1013         (unless (funcall test-not (funcall key current) element)
1014           (return current)))
1015       (do ((current list (funcall next current)))
1016           ((null current) nil)
1017         (when (funcall test (funcall key current) element)
1018           (return current)))))
1019
1020 (defun position-in (next
1021                     element
1022                     list
1023                     &key
1024                     (key #'identity)
1025                     (test #'eql test-p)
1026                     (test-not nil not-p))
1027   #!+sb-doc
1028   "Return the position of Element (or NIL if absent) in a null-terminated List
1029   linked by the accessor function Next. Key, Test and Test-Not are the same as
1030   for generic sequence functions."
1031   (when (and test-p not-p)
1032     (error "It's silly to supply both :TEST and :TEST-NOT arguments."))
1033   (if not-p
1034       (do ((current list (funcall next current))
1035            (i 0 (1+ i)))
1036           ((null current) nil)
1037         (unless (funcall test-not (funcall key current) element)
1038           (return i)))
1039       (do ((current list (funcall next current))
1040            (i 0 (1+ i)))
1041           ((null current) nil)
1042         (when (funcall test (funcall key current) element)
1043           (return i)))))
1044
1045 (defun map-in (next function list)
1046   #!+sb-doc
1047   "Map Function over the elements in a null-terminated List linked by the
1048   accessor function Next, returning a list of the results."
1049   (collect ((res))
1050     (do ((current list (funcall next current)))
1051         ((null current))
1052       (res (funcall function current)))
1053     (res)))
1054
1055 ;;; KLUDGE: This is expanded out twice, by cut-and-paste, in a
1056 ;;;   (DEF!MACRO FOO (..) .. CL:GET-SETF-EXPANSION ..)
1057 ;;;   #+SB-XC-HOST
1058 ;;;   (SB!XC:DEFMACRO FOO (..) .. SB!XC:GET-SETF-EXPANSION ..)
1059 ;;; arrangement, in order to get it to work in cross-compilation. This
1060 ;;; duplication should be removed, perhaps by rewriting the macro in a more
1061 ;;; cross-compiler-friendly way, or perhaps just by using some (MACROLET ((FROB
1062 ;;; ..)) .. FROB .. FROB) form, or perhaps by completely eliminating this macro
1063 ;;; and its partner PUSH-IN, but I don't want to do it now, because the system
1064 ;;; isn't running yet, so it'd be too hard to check that my changes were
1065 ;;; correct -- WHN 19990806
1066 (def!macro deletef-in (next place item &environment env)
1067   (multiple-value-bind (temps vals stores store access)
1068       (get-setf-expansion place env)
1069     (when (cdr stores)
1070       (error "multiple store variables for ~S" place))
1071     (let ((n-item (gensym))
1072           (n-place (gensym))
1073           (n-current (gensym))
1074           (n-prev (gensym)))
1075       `(let* (,@(mapcar #'list temps vals)
1076               (,n-place ,access)
1077               (,n-item ,item))
1078          (if (eq ,n-place ,n-item)
1079              (let ((,(first stores) (,next ,n-place)))
1080                ,store)
1081              (do ((,n-prev ,n-place ,n-current)
1082                   (,n-current (,next ,n-place)
1083                               (,next ,n-current)))
1084                  ((eq ,n-current ,n-item)
1085                   (setf (,next ,n-prev)
1086                         (,next ,n-current)))))
1087          (values)))))
1088 ;;; #+SB-XC-HOST SB!XC:DEFMACRO version is in late-macros.lisp. -- WHN 19990806
1089
1090 ;;; KLUDGE: This is expanded out twice, by cut-and-paste, in a
1091 ;;;   (DEF!MACRO FOO (..) .. CL:GET-SETF-EXPANSION ..)
1092 ;;;   #+SB-XC-HOST
1093 ;;;   (SB!XC:DEFMACRO FOO (..) .. SB!XC:GET-SETF-EXPANSION ..)
1094 ;;; arrangement, in order to get it to work in cross-compilation. This
1095 ;;; duplication should be removed, perhaps by rewriting the macro in a more
1096 ;;; cross-compiler-friendly way, or perhaps just by using some (MACROLET ((FROB
1097 ;;; ..)) .. FROB .. FROB) form, or perhaps by completely eliminating this macro
1098 ;;; and its partner DELETEF-IN, but I don't want to do it now, because the
1099 ;;; system isn't running yet, so it'd be too hard to check that my changes were
1100 ;;; correct -- WHN 19990806
1101 (def!macro push-in (next item place &environment env)
1102   #!+sb-doc
1103   "Push Item onto a list linked by the accessor function Next that is stored in
1104   Place."
1105   (multiple-value-bind (temps vals stores store access)
1106       (get-setf-expansion place env)
1107     (when (cdr stores)
1108       (error "multiple store variables for ~S" place))
1109     `(let (,@(mapcar #'list temps vals)
1110            (,(first stores) ,item))
1111        (setf (,next ,(first stores)) ,access)
1112        ,store
1113        (values))))
1114 ;;; #+SB-XC-HOST SB!XC:DEFMACRO version is in late-macros.lisp. -- WHN 19990806
1115
1116 (defmacro position-or-lose (&rest args)
1117   `(or (position ,@args)
1118        (error "shouldn't happen?")))