0.7.9.24:
[sbcl.git] / src / compiler / ir1-translators.lisp
1 ;;;; the usual place for DEF-IR1-TRANSLATOR forms (and their
2 ;;;; close personal friends)
3
4 ;;;; This software is part of the SBCL system. See the README file for
5 ;;;; more information.
6 ;;;;
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
12
13 (in-package "SB!C")
14 \f
15 ;;;; special forms for control
16
17 (def-ir1-translator progn ((&rest forms) start cont)
18   #!+sb-doc
19   "Progn Form*
20   Evaluates each Form in order, returning the values of the last form. With no
21   forms, returns NIL."
22   (ir1-convert-progn-body start cont forms))
23
24 (def-ir1-translator if ((test then &optional else) start cont)
25   #!+sb-doc
26   "If Predicate Then [Else]
27   If Predicate evaluates to non-null, evaluate Then and returns its values,
28   otherwise evaluate Else and return its values. Else defaults to NIL."
29   (let* ((pred (make-continuation))
30          (then-cont (make-continuation))
31          (then-block (continuation-starts-block then-cont))
32          (else-cont (make-continuation))
33          (else-block (continuation-starts-block else-cont))
34          (dummy-cont (make-continuation))
35          (node (make-if :test pred
36                         :consequent then-block
37                         :alternative else-block)))
38     (setf (continuation-dest pred) node)
39     (ir1-convert start pred test)
40     (link-node-to-previous-continuation node pred)
41     (use-continuation node dummy-cont)
42
43     (let ((start-block (continuation-block pred)))
44       (setf (block-last start-block) node)
45       (continuation-starts-block cont)
46
47       (link-blocks start-block then-block)
48       (link-blocks start-block else-block))
49
50     (ir1-convert then-cont cont then)
51     (ir1-convert else-cont cont else)))
52 \f
53 ;;;; BLOCK and TAGBODY
54
55 ;;;; We make an ENTRY node to mark the start and a :ENTRY cleanup to
56 ;;;; mark its extent. When doing GO or RETURN-FROM, we emit an EXIT
57 ;;;; node.
58
59 ;;; Make a :ENTRY cleanup and emit an ENTRY node, then convert the
60 ;;; body in the modified environment. We make CONT start a block now,
61 ;;; since if it was done later, the block would be in the wrong
62 ;;; environment.
63 (def-ir1-translator block ((name &rest forms) start cont)
64   #!+sb-doc
65   "Block Name Form*
66   Evaluate the Forms as a PROGN. Within the lexical scope of the body,
67   (RETURN-FROM Name Value-Form) can be used to exit the form, returning the
68   result of Value-Form."
69   (unless (symbolp name)
70     (compiler-error "The block name ~S is not a symbol." name))
71   (continuation-starts-block cont)
72   (let* ((dummy (make-continuation))
73          (entry (make-entry))
74          (cleanup (make-cleanup :kind :block
75                                 :mess-up entry)))
76     (push entry (lambda-entries (lexenv-lambda *lexenv*)))
77     (setf (entry-cleanup entry) cleanup)
78     (link-node-to-previous-continuation entry start)
79     (use-continuation entry dummy)
80
81     (let* ((env-entry (list entry cont))
82            (*lexenv* (make-lexenv :blocks (list (cons name env-entry))
83                                   :cleanup cleanup)))
84       (push env-entry (continuation-lexenv-uses cont))
85       (ir1-convert-progn-body dummy cont forms))))
86
87 (def-ir1-translator return-from ((name &optional value) start cont)
88   #!+sb-doc
89   "Return-From Block-Name Value-Form
90   Evaluate the Value-Form, returning its values from the lexically enclosing
91   BLOCK Block-Name. This is constrained to be used only within the dynamic
92   extent of the BLOCK."
93   ;; CMU CL comment:
94   ;;   We make CONT start a block just so that it will have a block
95   ;;   assigned. People assume that when they pass a continuation into
96   ;;   IR1-CONVERT as CONT, it will have a block when it is done.
97   ;; KLUDGE: Note that this block is basically fictitious. In the code
98   ;;   (BLOCK B (RETURN-FROM B) (SETQ X 3))
99   ;; it's the block which answers the question "which block is
100   ;; the (SETQ X 3) in?" when the right answer is that (SETQ X 3) is
101   ;; dead code and so doesn't really have a block at all. The existence
102   ;; of this block, and that way that it doesn't explicitly say
103   ;; "I'm actually nowhere at all" makes some logic (e.g.
104   ;; BLOCK-HOME-LAMBDA-OR-NULL) more obscure, and it might be better
105   ;; to get rid of it, perhaps using a special placeholder value
106   ;; to indicate the orphanedness of the code.
107   (continuation-starts-block cont)
108   (let* ((found (or (lexenv-find name blocks)
109                     (compiler-error "return for unknown block: ~S" name)))
110          (value-cont (make-continuation))
111          (entry (first found))
112          (exit (make-exit :entry entry
113                           :value value-cont)))
114     (push exit (entry-exits entry))
115     (setf (continuation-dest value-cont) exit)
116     (ir1-convert start value-cont value)
117     (link-node-to-previous-continuation exit value-cont)
118     (let ((home-lambda (continuation-home-lambda-or-null start)))
119       (when home-lambda
120         (push entry (lambda-calls-or-closes home-lambda))))
121     (use-continuation exit (second found))))
122
123 ;;; Return a list of the segments of a TAGBODY. Each segment looks
124 ;;; like (<tag> <form>* (go <next tag>)). That is, we break up the
125 ;;; tagbody into segments of non-tag statements, and explicitly
126 ;;; represent the drop-through with a GO. The first segment has a
127 ;;; dummy NIL tag, since it represents code before the first tag. The
128 ;;; last segment (which may also be the first segment) ends in NIL
129 ;;; rather than a GO.
130 (defun parse-tagbody (body)
131   (declare (list body))
132   (collect ((segments))
133     (let ((current (cons nil body)))
134       (loop
135         (let ((tag-pos (position-if (complement #'listp) current :start 1)))
136           (unless tag-pos
137             (segments `(,@current nil))
138             (return))
139           (let ((tag (elt current tag-pos)))
140             (when (assoc tag (segments))
141               (compiler-error
142                "The tag ~S appears more than once in the tagbody."
143                tag))
144             (unless (or (symbolp tag) (integerp tag))
145               (compiler-error "~S is not a legal tagbody statement." tag))
146             (segments `(,@(subseq current 0 tag-pos) (go ,tag))))
147           (setq current (nthcdr tag-pos current)))))
148     (segments)))
149
150 ;;; Set up the cleanup, emitting the entry node. Then make a block for
151 ;;; each tag, building up the tag list for LEXENV-TAGS as we go.
152 ;;; Finally, convert each segment with the precomputed Start and Cont
153 ;;; values.
154 (def-ir1-translator tagbody ((&rest statements) start cont)
155   #!+sb-doc
156   "Tagbody {Tag | Statement}*
157   Define tags for used with GO. The Statements are evaluated in order
158   (skipping Tags) and NIL is returned. If a statement contains a GO to a
159   defined Tag within the lexical scope of the form, then control is transferred
160   to the next statement following that tag. A Tag must an integer or a
161   symbol. A statement must be a list. Other objects are illegal within the
162   body."
163   (continuation-starts-block cont)
164   (let* ((dummy (make-continuation))
165          (entry (make-entry))
166          (segments (parse-tagbody statements))
167          (cleanup (make-cleanup :kind :tagbody
168                                 :mess-up entry)))
169     (push entry (lambda-entries (lexenv-lambda *lexenv*)))
170     (setf (entry-cleanup entry) cleanup)
171     (link-node-to-previous-continuation entry start)
172     (use-continuation entry dummy)
173
174     (collect ((tags)
175               (starts)
176               (conts))
177       (starts dummy)
178       (dolist (segment (rest segments))
179         (let* ((tag-cont (make-continuation))
180                (tag (list (car segment) entry tag-cont)))
181           (conts tag-cont)
182           (starts tag-cont)
183           (continuation-starts-block tag-cont)
184           (tags tag)
185           (push (cdr tag) (continuation-lexenv-uses tag-cont))))
186       (conts cont)
187
188       (let ((*lexenv* (make-lexenv :cleanup cleanup :tags (tags))))
189         (mapc (lambda (segment start cont)
190                 (ir1-convert-progn-body start cont (rest segment)))
191               segments (starts) (conts))))))
192
193 ;;; Emit an EXIT node without any value.
194 (def-ir1-translator go ((tag) start cont)
195   #!+sb-doc
196   "Go Tag
197   Transfer control to the named Tag in the lexically enclosing TAGBODY. This
198   is constrained to be used only within the dynamic extent of the TAGBODY."
199   (continuation-starts-block cont)
200   (let* ((found (or (lexenv-find tag tags :test #'eql)
201                     (compiler-error "attempt to GO to nonexistent tag: ~S"
202                                     tag)))
203          (entry (first found))
204          (exit (make-exit :entry entry)))
205     (push exit (entry-exits entry))
206     (link-node-to-previous-continuation exit start)
207     (let ((home-lambda (continuation-home-lambda-or-null start)))
208       (when home-lambda
209         (push entry (lambda-calls-or-closes home-lambda))))
210     (use-continuation exit (second found))))
211 \f
212 ;;;; translators for compiler-magic special forms
213
214 ;;; This handles EVAL-WHEN in non-top-level forms. (EVAL-WHENs in top
215 ;;; level forms are picked off and handled by PROCESS-TOPLEVEL-FORM,
216 ;;; so that they're never seen at this level.)
217 ;;;
218 ;;; ANSI "3.2.3.1 Processing of Top Level Forms" says that processing
219 ;;; of non-top-level EVAL-WHENs is very simple:
220 ;;;   EVAL-WHEN forms cause compile-time evaluation only at top level.
221 ;;;   Both :COMPILE-TOPLEVEL and :LOAD-TOPLEVEL situation specifications
222 ;;;   are ignored for non-top-level forms. For non-top-level forms, an
223 ;;;   eval-when specifying the :EXECUTE situation is treated as an
224 ;;;   implicit PROGN including the forms in the body of the EVAL-WHEN
225 ;;;   form; otherwise, the forms in the body are ignored.
226 (def-ir1-translator eval-when ((situations &rest forms) start cont)
227   #!+sb-doc
228   "EVAL-WHEN (Situation*) Form*
229   Evaluate the Forms in the specified Situations (any of :COMPILE-TOPLEVEL,
230   :LOAD-TOPLEVEL, or :EXECUTE, or (deprecated) COMPILE, LOAD, or EVAL)."
231   (multiple-value-bind (ct lt e) (parse-eval-when-situations situations)
232     (declare (ignore ct lt))
233     (ir1-convert-progn-body start cont (and e forms)))
234   (values))
235
236 ;;; common logic for MACROLET and SYMBOL-MACROLET
237 ;;;
238 ;;; Call DEFINITIONIZE-FUN on each element of DEFINITIONS to find its
239 ;;; in-lexenv representation, stuff the results into *LEXENV*, and
240 ;;; call FUN (with no arguments).
241 (defun %funcall-in-foomacrolet-lexenv (definitionize-fun
242                                        definitionize-keyword
243                                        definitions
244                                        fun)
245   (declare (type function definitionize-fun fun))
246   (declare (type (member :vars :funs) definitionize-keyword))
247   (declare (type list definitions))
248   (unless (= (length definitions)
249              (length (remove-duplicates definitions :key #'first)))
250     (compiler-style-warn "duplicate definitions in ~S" definitions))
251   (let* ((processed-definitions (mapcar definitionize-fun definitions))
252          (*lexenv* (make-lexenv definitionize-keyword processed-definitions)))
253     (funcall fun definitionize-keyword processed-definitions)))
254
255 ;;; Tweak LEXENV to include the DEFINITIONS from a MACROLET, then
256 ;;; call FUN (with no arguments).
257 ;;;
258 ;;; This is split off from the IR1 convert method so that it can be
259 ;;; shared by the special-case top level MACROLET processing code, and
260 ;;; further split so that the special-case MACROLET processing code in
261 ;;; EVAL can likewise make use of it.
262 (defmacro macrolet-definitionize-fun (context lexenv)
263   (flet ((make-error-form (control &rest args)
264            (ecase context
265              (:compile `(compiler-error ,control ,@args))
266              (:eval `(error 'simple-program-error
267                       :format-control ,control
268                       :format-arguments (list ,@args))))))
269     `(lambda (definition)
270       (unless (list-of-length-at-least-p definition 2)
271         ,(make-error-form "The list ~S is too short to be a legal local macro definition." 'definition))
272       (destructuring-bind (name arglist &body body) definition
273         (unless (symbolp name)
274           ,(make-error-form "The local macro name ~S is not a symbol." 'name))
275         (unless (listp arglist)
276           ,(make-error-form "The local macro argument list ~S is not a list." 'arglist))
277         (let ((whole (gensym "WHOLE"))
278               (environment (gensym "ENVIRONMENT")))
279           (multiple-value-bind (body local-decls)
280               (parse-defmacro arglist whole body name 'macrolet
281                               :environment environment)
282             `(,name macro .
283               ,(compile-in-lexenv
284                 nil
285                 `(lambda (,whole ,environment)
286                   ,@local-decls
287                   (block ,name ,body))
288                 ,lexenv))))))))
289
290 (defun funcall-in-macrolet-lexenv (definitions fun)
291   (%funcall-in-foomacrolet-lexenv
292    (macrolet-definitionize-fun :compile (make-restricted-lexenv *lexenv*))
293    :funs
294    definitions
295    fun))
296
297 (def-ir1-translator macrolet ((definitions &rest body) start cont)
298   #!+sb-doc
299   "MACROLET ({(Name Lambda-List Form*)}*) Body-Form*
300   Evaluate the Body-Forms in an environment with the specified local macros
301   defined. Name is the local macro name, Lambda-List is the DEFMACRO style
302   destructuring lambda list, and the Forms evaluate to the expansion.."
303   (funcall-in-macrolet-lexenv
304    definitions
305    (lambda (&key funs)
306      (declare (ignore funs))
307      (ir1-translate-locally body start cont))))
308
309 (defmacro symbol-macrolet-definitionize-fun (context)
310   (flet ((make-error-form (control &rest args)
311            (ecase context
312              (:compile `(compiler-error ,control ,@args))
313              (:eval `(error 'simple-program-error
314                       :format-control ,control
315                       :format-arguments (list ,@args))))))
316     `(lambda (definition)
317       (unless (proper-list-of-length-p definition 2)
318        ,(make-error-form "malformed symbol/expansion pair: ~S" 'definition))
319      (destructuring-bind (name expansion) definition
320        (unless (symbolp name)
321          ,(make-error-form
322            "The local symbol macro name ~S is not a symbol."
323            'name))
324        (let ((kind (info :variable :kind name)))
325          (when (member kind '(:special :constant))
326            ,(make-error-form
327              "Attempt to bind a ~(~A~) variable with SYMBOL-MACROLET: ~S"
328              'kind 'name)))
329        `(,name . (MACRO . ,expansion))))))1
330
331 (defun funcall-in-symbol-macrolet-lexenv (definitions fun)
332   (%funcall-in-foomacrolet-lexenv
333    (symbol-macrolet-definitionize-fun :compile)
334    :vars
335    definitions
336    fun))
337
338 (def-ir1-translator symbol-macrolet ((macrobindings &body body) start cont)
339   #!+sb-doc
340   "SYMBOL-MACROLET ({(Name Expansion)}*) Decl* Form*
341   Define the Names as symbol macros with the given Expansions. Within the
342   body, references to a Name will effectively be replaced with the Expansion."
343   (funcall-in-symbol-macrolet-lexenv
344    macrobindings
345    (lambda (&key vars)
346      (ir1-translate-locally body start cont :vars vars))))
347
348 ;;; not really a special form, but..
349 (def-ir1-translator declare ((&rest stuff) start cont)
350   (declare (ignore stuff))
351   ;; We ignore START and CONT too, but we can't use DECLARE IGNORE to
352   ;; tell the compiler about it here, because the DEF-IR1-TRANSLATOR
353   ;; macro would put the DECLARE in the wrong place, so..
354   start cont
355   (compiler-error "misplaced declaration"))
356 \f
357 ;;;; %PRIMITIVE
358 ;;;;
359 ;;;; Uses of %PRIMITIVE are either expanded into Lisp code or turned
360 ;;;; into a funny function.
361
362 ;;; Carefully evaluate a list of forms, returning a list of the results.
363 (defun eval-info-args (args)
364   (declare (list args))
365   (handler-case (mapcar #'eval args)
366     (error (condition)
367       (compiler-error "Lisp error during evaluation of info args:~%~A"
368                       condition))))
369
370 ;;; Convert to the %%PRIMITIVE funny function. The first argument is
371 ;;; the template, the second is a list of the results of any
372 ;;; codegen-info args, and the remaining arguments are the runtime
373 ;;; arguments.
374 ;;;
375 ;;; We do various error checking now so that we don't bomb out with
376 ;;; a fatal error during IR2 conversion.
377 ;;;
378 ;;; KLUDGE: It's confusing having multiple names floating around for
379 ;;; nearly the same concept: PRIMITIVE, TEMPLATE, VOP. Now that CMU
380 ;;; CL's *PRIMITIVE-TRANSLATORS* stuff is gone, we could call
381 ;;; primitives VOPs, rename TEMPLATE to VOP-TEMPLATE, rename
382 ;;; BACKEND-TEMPLATE-NAMES to BACKEND-VOPS, and rename %PRIMITIVE to
383 ;;; VOP or %VOP.. -- WHN 2001-06-11
384 ;;; FIXME: Look at doing this ^, it doesn't look too hard actually.
385 (def-ir1-translator %primitive ((name &rest args) start cont)
386   (declare (type symbol name))
387   (let* ((template (or (gethash name *backend-template-names*)
388                        (bug "undefined primitive ~A" name)))
389          (required (length (template-arg-types template)))
390          (info (template-info-arg-count template))
391          (min (+ required info))
392          (nargs (length args)))
393     (if (template-more-args-type template)
394         (when (< nargs min)
395           (bug "Primitive ~A was called with ~R argument~:P, ~
396                 but wants at least ~R."
397                name
398                nargs
399                min))
400         (unless (= nargs min)
401           (bug "Primitive ~A was called with ~R argument~:P, ~
402                 but wants exactly ~R."
403                name
404                nargs
405                min)))
406
407     (when (eq (template-result-types template) :conditional)
408       (bug "%PRIMITIVE was used with a conditional template."))
409
410     (when (template-more-results-type template)
411       (bug "%PRIMITIVE was used with an unknown values template."))
412
413     (ir1-convert start
414                  cont
415                  `(%%primitive ',template
416                                ',(eval-info-args
417                                   (subseq args required min))
418                                ,@(subseq args 0 required)
419                                ,@(subseq args min)))))
420 \f
421 ;;;; QUOTE
422
423 (def-ir1-translator quote ((thing) start cont)
424   #!+sb-doc
425   "QUOTE Value
426   Return Value without evaluating it."
427   (reference-constant start cont thing))
428 \f
429 ;;;; FUNCTION and NAMED-LAMBDA
430
431 (def-ir1-translator function ((thing) start cont)
432   #!+sb-doc
433   "FUNCTION Name
434   Return the lexically apparent definition of the function Name. Name may also
435   be a lambda expression."
436   (if (consp thing)
437       (case (car thing)
438         ((lambda)
439          (reference-leaf start
440                          cont
441                          (ir1-convert-lambda thing
442                                              :debug-name (debug-namify
443                                                           "#'~S" thing))))
444         ((setf)
445          (let ((var (find-lexically-apparent-fun
446                      thing "as the argument to FUNCTION")))
447            (reference-leaf start cont var)))
448         ((instance-lambda)
449          (let ((res (ir1-convert-lambda `(lambda ,@(cdr thing))
450                                         :debug-name (debug-namify "#'~S"
451                                                                   thing))))
452            (setf (getf (functional-plist res) :fin-function) t)
453            (reference-leaf start cont res)))
454         (t
455          (compiler-error "~S is not a legal function name." thing)))
456       (let ((var (find-lexically-apparent-fun
457                   thing "as the argument to FUNCTION")))
458         (reference-leaf start cont var))))
459
460 ;;; `(NAMED-LAMBDA ,NAME ,@REST) is like `(FUNCTION (LAMBDA ,@REST)),
461 ;;; except that the value of NAME is passed to the compiler for use in
462 ;;; creation of debug information for the resulting function.
463 ;;;
464 ;;; NAME can be a legal function name or some arbitrary other thing.
465 ;;;
466 ;;; If NAME is a legal function name, then the caller should be
467 ;;; planning to set (FDEFINITION NAME) to the created function.
468 ;;; (Otherwise the debug names will be inconsistent and thus
469 ;;; unnecessarily confusing.)
470 ;;;
471 ;;; Arbitrary other things are appropriate for naming things which are
472 ;;; not the FDEFINITION of NAME. E.g.
473 ;;;   NAME = (:FLET FOO BAR)
474 ;;; for the FLET function in
475 ;;;   (DEFUN BAR (X)
476 ;;;     (FLET ((FOO (Y) (+ X Y)))
477 ;;;       FOO))
478 ;;; or
479 ;;;   NAME = (:METHOD PRINT-OBJECT :AROUND (STARSHIP T))
480 ;;; for the function used to implement
481 ;;;   (DEFMETHOD PRINT-OBJECT :AROUND ((SS STARSHIP) STREAM) ...).
482 (def-ir1-translator named-lambda ((name &rest rest) start cont)
483   (let* ((fun (if (legal-fun-name-p name)
484                   (ir1-convert-lambda `(lambda ,@rest)
485                                       :source-name name)
486                   (ir1-convert-lambda `(lambda ,@rest)
487                                       :debug-name name)))
488          (leaf (reference-leaf start cont fun)))
489     (when (legal-fun-name-p name)
490       (assert-global-function-definition-type name fun))
491     leaf))
492 \f
493 ;;;; FUNCALL
494
495 ;;; FUNCALL is implemented on %FUNCALL, which can only call functions
496 ;;; (not symbols). %FUNCALL is used directly in some places where the
497 ;;; call should always be open-coded even if FUNCALL is :NOTINLINE.
498 (deftransform funcall ((function &rest args) * *)
499   (let ((arg-names (make-gensym-list (length args))))
500     `(lambda (function ,@arg-names)
501        (%funcall ,(if (csubtypep (continuation-type function)
502                                  (specifier-type 'function))
503                       'function
504                       '(%coerce-callable-to-fun function))
505                  ,@arg-names))))
506
507 (def-ir1-translator %funcall ((function &rest args) start cont)
508   (let ((fun-cont (make-continuation)))
509     (ir1-convert start fun-cont function)
510     (assert-continuation-type fun-cont (specifier-type 'function))
511     (ir1-convert-combination-args fun-cont cont args)))
512
513 ;;; This source transform exists to reduce the amount of work for the
514 ;;; compiler. If the called function is a FUNCTION form, then convert
515 ;;; directly to %FUNCALL, instead of waiting around for type
516 ;;; inference.
517 (define-source-transform funcall (function &rest args)
518   (if (and (consp function) (eq (car function) 'function))
519       `(%funcall ,function ,@args)
520       (values nil t)))
521
522 (deftransform %coerce-callable-to-fun ((thing) (function) *
523                                        :important t)
524   "optimize away possible call to FDEFINITION at runtime"
525   'thing)
526 \f
527 ;;;; LET and LET*
528 ;;;;
529 ;;;; (LET and LET* can't be implemented as macros due to the fact that
530 ;;;; any pervasive declarations also affect the evaluation of the
531 ;;;; arguments.)
532
533 ;;; Given a list of binding specifiers in the style of LET, return:
534 ;;;  1. The list of var structures for the variables bound.
535 ;;;  2. The initial value form for each variable.
536 ;;;
537 ;;; The variable names are checked for legality and globally special
538 ;;; variables are marked as such. Context is the name of the form, for
539 ;;; error reporting purposes.
540 (declaim (ftype (function (list symbol) (values list list))
541                 extract-let-vars))
542 (defun extract-let-vars (bindings context)
543   (collect ((vars)
544             (vals)
545             (names))
546     (flet ((get-var (name)
547              (varify-lambda-arg name
548                                 (if (eq context 'let*)
549                                     nil
550                                     (names)))))
551       (dolist (spec bindings)
552         (cond ((atom spec)
553                (let ((var (get-var spec)))
554                  (vars var)
555                  (names spec)
556                  (vals nil)))
557               (t
558                (unless (proper-list-of-length-p spec 1 2)
559                  (compiler-error "The ~S binding spec ~S is malformed."
560                                  context
561                                  spec))
562                (let* ((name (first spec))
563                       (var (get-var name)))
564                  (vars var)
565                  (names name)
566                  (vals (second spec)))))))
567
568     (values (vars) (vals))))
569
570 (def-ir1-translator let ((bindings &body body)
571                          start cont)
572   #!+sb-doc
573   "LET ({(Var [Value]) | Var}*) Declaration* Form*
574   During evaluation of the Forms, bind the Vars to the result of evaluating the
575   Value forms. The variables are bound in parallel after all of the Values are
576   evaluated."
577   (multiple-value-bind (forms decls) (parse-body body nil)
578     (multiple-value-bind (vars values) (extract-let-vars bindings 'let)
579       (let ((fun-cont (make-continuation)))
580         (let* ((*lexenv* (process-decls decls vars nil cont))
581                (fun (ir1-convert-lambda-body
582                      forms vars
583                      :debug-name (debug-namify "LET ~S" bindings))))
584           (reference-leaf start fun-cont fun))
585         (ir1-convert-combination-args fun-cont cont values)))))
586
587 (def-ir1-translator let* ((bindings &body body)
588                           start cont)
589   #!+sb-doc
590   "LET* ({(Var [Value]) | Var}*) Declaration* Form*
591   Similar to LET, but the variables are bound sequentially, allowing each Value
592   form to reference any of the previous Vars."
593   (multiple-value-bind (forms decls) (parse-body body nil)
594     (multiple-value-bind (vars values) (extract-let-vars bindings 'let*)
595       (let ((*lexenv* (process-decls decls vars nil cont)))
596         (ir1-convert-aux-bindings start cont forms vars values)))))
597
598 ;;; logic shared between IR1 translators for LOCALLY, MACROLET,
599 ;;; and SYMBOL-MACROLET
600 ;;;
601 ;;; Note that all these things need to preserve toplevel-formness,
602 ;;; but we don't need to worry about that within an IR1 translator,
603 ;;; since toplevel-formness is picked off by PROCESS-TOPLEVEL-FOO
604 ;;; forms before we hit the IR1 transform level.
605 (defun ir1-translate-locally (body start cont &key vars funs)
606   (declare (type list body) (type continuation start cont))
607   (multiple-value-bind (forms decls) (parse-body body nil)
608     (let ((*lexenv* (process-decls decls vars funs cont)))
609       (ir1-convert-aux-bindings start cont forms nil nil))))
610
611 (def-ir1-translator locally ((&body body) start cont)
612   #!+sb-doc
613   "LOCALLY Declaration* Form*
614   Sequentially evaluate the Forms in a lexical environment where the
615   the Declarations have effect. If LOCALLY is a top level form, then
616   the Forms are also processed as top level forms."
617   (ir1-translate-locally body start cont))
618 \f
619 ;;;; FLET and LABELS
620
621 ;;; Given a list of local function specifications in the style of
622 ;;; FLET, return lists of the function names and of the lambdas which
623 ;;; are their definitions.
624 ;;;
625 ;;; The function names are checked for legality. CONTEXT is the name
626 ;;; of the form, for error reporting.
627 (declaim (ftype (function (list symbol) (values list list)) extract-flet-vars))
628 (defun extract-flet-vars (definitions context)
629   (collect ((names)
630             (defs))
631     (dolist (def definitions)
632       (when (or (atom def) (< (length def) 2))
633         (compiler-error "The ~S definition spec ~S is malformed." context def))
634
635       (let ((name (first def)))
636         (check-fun-name name)
637         (names name)
638         (multiple-value-bind (forms decls) (parse-body (cddr def))
639           (defs `(lambda ,(second def)
640                    ,@decls
641                    (block ,(fun-name-block-name name)
642                      . ,forms))))))
643     (values (names) (defs))))
644
645 (def-ir1-translator flet ((definitions &body body)
646                           start cont)
647   #!+sb-doc
648   "FLET ({(Name Lambda-List Declaration* Form*)}*) Declaration* Body-Form*
649   Evaluate the Body-Forms with some local function definitions. The bindings
650   do not enclose the definitions; any use of Name in the Forms will refer to
651   the lexically apparent function definition in the enclosing environment."
652   (multiple-value-bind (forms decls) (parse-body body nil)
653     (multiple-value-bind (names defs)
654         (extract-flet-vars definitions 'flet)
655       (let* ((fvars (mapcar (lambda (n d)
656                               (ir1-convert-lambda d
657                                                   :source-name n
658                                                   :debug-name (debug-namify
659                                                                "FLET ~S" n)))
660                             names defs))
661              (*lexenv* (make-lexenv
662                         :default (process-decls decls nil fvars cont)
663                         :funs (pairlis names fvars))))
664         (ir1-convert-progn-body start cont forms)))))
665
666 (def-ir1-translator labels ((definitions &body body) start cont)
667   #!+sb-doc
668   "LABELS ({(Name Lambda-List Declaration* Form*)}*) Declaration* Body-Form*
669   Evaluate the Body-Forms with some local function definitions. The bindings
670   enclose the new definitions, so the defined functions can call themselves or
671   each other."
672   (multiple-value-bind (forms decls) (parse-body body nil)
673     (multiple-value-bind (names defs)
674         (extract-flet-vars definitions 'labels)
675       (let* (;; dummy LABELS functions, to be used as placeholders
676              ;; during construction of real LABELS functions
677              (placeholder-funs (mapcar (lambda (name)
678                                          (make-functional
679                                           :%source-name name
680                                           :%debug-name (debug-namify
681                                                         "LABELS placeholder ~S"
682                                                         name)))
683                                        names))
684              ;; (like PAIRLIS but guaranteed to preserve ordering:)
685              (placeholder-fenv (mapcar #'cons names placeholder-funs))
686              ;; the real LABELS functions, compiled in a LEXENV which
687              ;; includes the dummy LABELS functions
688              (real-funs
689               (let ((*lexenv* (make-lexenv :funs placeholder-fenv)))
690                 (mapcar (lambda (name def)
691                           (ir1-convert-lambda def
692                                               :source-name name
693                                               :debug-name (debug-namify
694                                                            "LABELS ~S" name)))
695                         names defs))))
696
697         ;; Modify all the references to the dummy function leaves so
698         ;; that they point to the real function leaves.
699         (loop for real-fun in real-funs and
700               placeholder-cons in placeholder-fenv do
701               (substitute-leaf real-fun (cdr placeholder-cons))
702               (setf (cdr placeholder-cons) real-fun))
703
704         ;; Voila.
705         (let ((*lexenv* (make-lexenv
706                          :default (process-decls decls nil real-funs cont)
707                          ;; Use a proper FENV here (not the
708                          ;; placeholder used earlier) so that if the
709                          ;; lexical environment is used for inline
710                          ;; expansion we'll get the right functions.
711                          :funs (pairlis names real-funs))))
712           (ir1-convert-progn-body start cont forms))))))
713 \f
714 ;;;; the THE special operator, and friends
715
716 ;;; Do stuff to recognize a THE or VALUES declaration. CONT is the
717 ;;; continuation that the assertion applies to, TYPE is the type
718 ;;; specifier and LEXENV is the current lexical environment. NAME is
719 ;;; the name of the declaration we are doing, for use in error
720 ;;; messages.
721 ;;;
722 ;;; This is somewhat involved, since a type assertion may only be made
723 ;;; on a continuation, not on a node. We can't just set the
724 ;;; continuation asserted type and let it go at that, since there may
725 ;;; be parallel THE's for the same continuation, i.e.
726 ;;;     (if ...
727 ;;;      (the foo ...)
728 ;;;      (the bar ...))
729 ;;;
730 ;;; In this case, our representation can do no better than the union
731 ;;; of these assertions. And if there is a branch with no assertion,
732 ;;; we have nothing at all. We really need to recognize scoping, since
733 ;;; we need to be able to discern between parallel assertions (which
734 ;;; we union) and nested ones (which we intersect).
735 ;;;
736 ;;; We represent the scoping by throwing our innermost (intersected)
737 ;;; assertion on CONT into the TYPE-RESTRICTIONS. As we go down, we
738 ;;; intersect our assertions together. If CONT has no uses yet, we
739 ;;; have not yet bottomed out on the first COND branch; in this case
740 ;;; we optimistically assume that this type will be the one we end up
741 ;;; with, and set the ASSERTED-TYPE to it. We can never get better
742 ;;; than the type that we have the first time we bottom out. Later
743 ;;; THE's (or the absence thereof) can only weaken this result.
744 ;;;
745 ;;; We make this work by getting USE-CONTINUATION to do the unioning
746 ;;; across COND branches. We can't do it here, since we don't know how
747 ;;; many branches there are going to be.
748 (defun ir1ize-the-or-values (type cont lexenv place)
749   (declare (type continuation cont) (type lexenv lexenv))
750   (let* ((ctype (if (typep type 'ctype) type (compiler-values-specifier-type type)))
751          (old-type (or (lexenv-find cont type-restrictions)
752                        *wild-type*))
753          (intersects (values-types-equal-or-intersect old-type ctype))
754          (new (values-type-intersection old-type ctype)))
755     (when (null (find-uses cont))
756       (setf (continuation-asserted-type cont) new))
757     (when (and (not intersects)
758                ;; FIXME: Is it really right to look at *LEXENV* here,
759                ;; instead of looking at the LEXENV argument? Why?
760                (not (policy *lexenv*
761                             (= inhibit-warnings 3)))) ;FIXME: really OK to suppress?
762       (compiler-warn
763        "The type ~S ~A conflicts with an enclosing assertion:~%   ~S"
764        (type-specifier ctype)
765        place
766        (type-specifier old-type)))
767     (make-lexenv :type-restrictions `((,cont . ,new))
768                  :default lexenv)))
769
770 ;;; Assert that FORM evaluates to the specified type (which may be a
771 ;;; VALUES type).
772 ;;;
773 ;;; FIXME: In a version of CMU CL that I used at Cadabra ca. 20000101,
774 ;;; this didn't seem to expand into an assertion, at least for ALIEN
775 ;;; values. Check that SBCL doesn't have this problem.
776 (def-ir1-translator the ((type value) start cont)
777   (with-continuation-type-assertion (cont (compiler-values-specifier-type type)
778                                           "in THE declaration")
779     (ir1-convert start cont value)))
780
781 ;;; This is like the THE special form, except that it believes
782 ;;; whatever you tell it. It will never generate a type check, but
783 ;;; will cause a warning if the compiler can prove the assertion is
784 ;;; wrong.
785 ;;;
786 ;;; Since the CONTINUATION-DERIVED-TYPE is computed as the union of
787 ;;; its uses's types, setting it won't work. Instead we must intersect
788 ;;; the type with the uses's DERIVED-TYPE.
789 (def-ir1-translator truly-the ((type value) start cont)
790   #!+sb-doc
791   (declare (inline member))
792   (let ((type (compiler-values-specifier-type type))
793         (old (find-uses cont)))
794     (ir1-convert start cont value)
795     (do-uses (use cont)
796       (unless (member use old :test #'eq)
797         (derive-node-type use type)))))
798 \f
799 ;;;; SETQ
800
801 ;;; If there is a definition in LEXENV-VARS, just set that, otherwise
802 ;;; look at the global information. If the name is for a constant,
803 ;;; then error out.
804 (def-ir1-translator setq ((&whole source &rest things) start cont)
805   (let ((len (length things)))
806     (when (oddp len)
807       (compiler-error "odd number of args to SETQ: ~S" source))
808     (if (= len 2)
809         (let* ((name (first things))
810                (leaf (or (lexenv-find name vars)
811                          (find-free-var name))))
812           (etypecase leaf
813             (leaf
814              (when (constant-p leaf)
815                (compiler-error "~S is a constant and thus can't be set." name))
816              (when (lambda-var-p leaf)
817                (let ((home-lambda (continuation-home-lambda-or-null start)))
818                  (when home-lambda
819                    (pushnew leaf (lambda-calls-or-closes home-lambda))))
820                (when (lambda-var-ignorep leaf)
821                  ;; ANSI's definition of "Declaration IGNORE, IGNORABLE"
822                  ;; requires that this be a STYLE-WARNING, not a full warning.
823                  (compiler-style-warn
824                   "~S is being set even though it was declared to be ignored."
825                   name)))
826              (setq-var start cont leaf (second things)))
827             (cons
828              (aver (eq (car leaf) 'MACRO))
829              (ir1-convert start cont `(setf ,(cdr leaf) ,(second things))))
830             (heap-alien-info
831              (ir1-convert start cont
832                           `(%set-heap-alien ',leaf ,(second things))))))
833         (collect ((sets))
834           (do ((thing things (cddr thing)))
835               ((endp thing)
836                (ir1-convert-progn-body start cont (sets)))
837             (sets `(setq ,(first thing) ,(second thing))))))))
838
839 ;;; This is kind of like REFERENCE-LEAF, but we generate a SET node.
840 ;;; This should only need to be called in SETQ.
841 (defun setq-var (start cont var value)
842   (declare (type continuation start cont) (type basic-var var))
843   (let ((dest (make-continuation)))
844     (setf (continuation-asserted-type dest) (leaf-type var))
845     (ir1-convert start dest value)
846     (let ((res (make-set :var var :value dest)))
847       (setf (continuation-dest dest) res)
848       (setf (leaf-ever-used var) t)
849       (push res (basic-var-sets var))
850       (link-node-to-previous-continuation res dest)
851       (use-continuation res cont))))
852 \f
853 ;;;; CATCH, THROW and UNWIND-PROTECT
854
855 ;;; We turn THROW into a multiple-value-call of a magical function,
856 ;;; since as as far as IR1 is concerned, it has no interesting
857 ;;; properties other than receiving multiple-values.
858 (def-ir1-translator throw ((tag result) start cont)
859   #!+sb-doc
860   "Throw Tag Form
861   Do a non-local exit, return the values of Form from the CATCH whose tag
862   evaluates to the same thing as Tag."
863   (ir1-convert start cont
864                `(multiple-value-call #'%throw ,tag ,result)))
865
866 ;;; This is a special special form used to instantiate a cleanup as
867 ;;; the current cleanup within the body. KIND is the kind of cleanup
868 ;;; to make, and MESS-UP is a form that does the mess-up action. We
869 ;;; make the MESS-UP be the USE of the MESS-UP form's continuation,
870 ;;; and introduce the cleanup into the lexical environment. We
871 ;;; back-patch the ENTRY-CLEANUP for the current cleanup to be the new
872 ;;; cleanup, since this inner cleanup is the interesting one.
873 (def-ir1-translator %within-cleanup ((kind mess-up &body body) start cont)
874   (let ((dummy (make-continuation))
875         (dummy2 (make-continuation)))
876     (ir1-convert start dummy mess-up)
877     (let* ((mess-node (continuation-use dummy))
878            (cleanup (make-cleanup :kind kind
879                                   :mess-up mess-node))
880            (old-cup (lexenv-cleanup *lexenv*))
881            (*lexenv* (make-lexenv :cleanup cleanup)))
882       (setf (entry-cleanup (cleanup-mess-up old-cup)) cleanup)
883       (ir1-convert dummy dummy2 '(%cleanup-point))
884       (ir1-convert-progn-body dummy2 cont body))))
885
886 ;;; This is a special special form that makes an "escape function"
887 ;;; which returns unknown values from named block. We convert the
888 ;;; function, set its kind to :ESCAPE, and then reference it. The
889 ;;; :ESCAPE kind indicates that this function's purpose is to
890 ;;; represent a non-local control transfer, and that it might not
891 ;;; actually have to be compiled.
892 ;;;
893 ;;; Note that environment analysis replaces references to escape
894 ;;; functions with references to the corresponding NLX-INFO structure.
895 (def-ir1-translator %escape-fun ((tag) start cont)
896   (let ((fun (ir1-convert-lambda
897               `(lambda ()
898                  (return-from ,tag (%unknown-values)))
899               :debug-name (debug-namify "escape function for ~S" tag))))
900     (setf (functional-kind fun) :escape)
901     (reference-leaf start cont fun)))
902
903 ;;; Yet another special special form. This one looks up a local
904 ;;; function and smashes it to a :CLEANUP function, as well as
905 ;;; referencing it.
906 (def-ir1-translator %cleanup-fun ((name) start cont)
907   (let ((fun (lexenv-find name funs)))
908     (aver (lambda-p fun))
909     (setf (functional-kind fun) :cleanup)
910     (reference-leaf start cont fun)))
911
912 ;;; We represent the possibility of the control transfer by making an
913 ;;; "escape function" that does a lexical exit, and instantiate the
914 ;;; cleanup using %WITHIN-CLEANUP.
915 (def-ir1-translator catch ((tag &body body) start cont)
916   #!+sb-doc
917   "Catch Tag Form*
918   Evaluates Tag and instantiates it as a catcher while the body forms are
919   evaluated in an implicit PROGN. If a THROW is done to Tag within the dynamic
920   scope of the body, then control will be transferred to the end of the body
921   and the thrown values will be returned."
922   (ir1-convert
923    start cont
924    (let ((exit-block (gensym "EXIT-BLOCK-")))
925      `(block ,exit-block
926         (%within-cleanup
927             :catch
928             (%catch (%escape-fun ,exit-block) ,tag)
929           ,@body)))))
930
931 ;;; UNWIND-PROTECT is similar to CATCH, but hairier. We make the
932 ;;; cleanup forms into a local function so that they can be referenced
933 ;;; both in the case where we are unwound and in any local exits. We
934 ;;; use %CLEANUP-FUN on this to indicate that reference by
935 ;;; %UNWIND-PROTECT isn't "real", and thus doesn't cause creation of
936 ;;; an XEP.
937 (def-ir1-translator unwind-protect ((protected &body cleanup) start cont)
938   #!+sb-doc
939   "Unwind-Protect Protected Cleanup*
940   Evaluate the form Protected, returning its values. The cleanup forms are
941   evaluated whenever the dynamic scope of the Protected form is exited (either
942   due to normal completion or a non-local exit such as THROW)."
943   (ir1-convert
944    start cont
945    (let ((cleanup-fun (gensym "CLEANUP-FUN-"))
946          (drop-thru-tag (gensym "DROP-THRU-TAG-"))
947          (exit-tag (gensym "EXIT-TAG-"))
948          (next (gensym "NEXT"))
949          (start (gensym "START"))
950          (count (gensym "COUNT")))
951      `(flet ((,cleanup-fun () ,@cleanup nil))
952         ;; FIXME: If we ever get DYNAMIC-EXTENT working, then
953         ;; ,CLEANUP-FUN should probably be declared DYNAMIC-EXTENT,
954         ;; and something can be done to make %ESCAPE-FUN have
955         ;; dynamic extent too.
956         (block ,drop-thru-tag
957           (multiple-value-bind (,next ,start ,count)
958               (block ,exit-tag
959                 (%within-cleanup
960                     :unwind-protect
961                     (%unwind-protect (%escape-fun ,exit-tag)
962                                      (%cleanup-fun ,cleanup-fun))
963                   (return-from ,drop-thru-tag ,protected)))
964             (,cleanup-fun)
965             (%continue-unwind ,next ,start ,count)))))))
966 \f
967 ;;;; multiple-value stuff
968
969 ;;; If there are arguments, MULTIPLE-VALUE-CALL turns into an
970 ;;; MV-COMBINATION.
971 ;;;
972 ;;; If there are no arguments, then we convert to a normal
973 ;;; combination, ensuring that a MV-COMBINATION always has at least
974 ;;; one argument. This can be regarded as an optimization, but it is
975 ;;; more important for simplifying compilation of MV-COMBINATIONS.
976 (def-ir1-translator multiple-value-call ((fun &rest args) start cont)
977   #!+sb-doc
978   "MULTIPLE-VALUE-CALL Function Values-Form*
979   Call Function, passing all the values of each Values-Form as arguments,
980   values from the first Values-Form making up the first argument, etc."
981   (let* ((fun-cont (make-continuation))
982          (node (if args
983                    (make-mv-combination fun-cont)
984                    (make-combination fun-cont))))
985     (ir1-convert start fun-cont
986                  (if (and (consp fun) (eq (car fun) 'function))
987                      fun
988                      `(%coerce-callable-to-fun ,fun)))
989     (setf (continuation-dest fun-cont) node)
990     (assert-continuation-type fun-cont
991                               (specifier-type '(or function symbol)))
992     (collect ((arg-conts))
993       (let ((this-start fun-cont))
994         (dolist (arg args)
995           (let ((this-cont (make-continuation node)))
996             (ir1-convert this-start this-cont arg)
997             (setq this-start this-cont)
998             (arg-conts this-cont)))
999         (link-node-to-previous-continuation node this-start)
1000         (use-continuation node cont)
1001         (setf (basic-combination-args node) (arg-conts))))))
1002
1003 ;;; MULTIPLE-VALUE-PROG1 is represented implicitly in IR1 by having a
1004 ;;; the result code use result continuation (CONT), but transfer
1005 ;;; control to the evaluation of the body. In other words, the result
1006 ;;; continuation isn't IMMEDIATELY-USED-P by the nodes that compute
1007 ;;; the result.
1008 ;;;
1009 ;;; In order to get the control flow right, we convert the result with
1010 ;;; a dummy result continuation, then convert all the uses of the
1011 ;;; dummy to be uses of CONT. If a use is an EXIT, then we also
1012 ;;; substitute CONT for the dummy in the corresponding ENTRY node so
1013 ;;; that they are consistent. Note that this doesn't amount to
1014 ;;; changing the exit target, since the control destination of an exit
1015 ;;; is determined by the block successor; we are just indicating the
1016 ;;; continuation that the result is delivered to.
1017 ;;;
1018 ;;; We then convert the body, using another dummy continuation in its
1019 ;;; own block as the result. After we are done converting the body, we
1020 ;;; move all predecessors of the dummy end block to CONT's block.
1021 ;;;
1022 ;;; Note that we both exploit and maintain the invariant that the CONT
1023 ;;; to an IR1 convert method either has no block or starts the block
1024 ;;; that control should transfer to after completion for the form.
1025 ;;; Nested MV-PROG1's work because during conversion of the result
1026 ;;; form, we use dummy continuation whose block is the true control
1027 ;;; destination.
1028 (def-ir1-translator multiple-value-prog1 ((result &rest forms) start cont)
1029   #!+sb-doc
1030   "MULTIPLE-VALUE-PROG1 Values-Form Form*
1031   Evaluate Values-Form and then the Forms, but return all the values of
1032   Values-Form."
1033   (continuation-starts-block cont)
1034   (let* ((dummy-result (make-continuation))
1035          (dummy-start (make-continuation))
1036          (cont-block (continuation-block cont)))
1037     (continuation-starts-block dummy-start)
1038     (ir1-convert start dummy-start result)
1039
1040     (with-continuation-type-assertion
1041         (cont (continuation-asserted-type dummy-start)
1042               "of the first form")
1043       (substitute-continuation-uses cont dummy-start))
1044
1045     (continuation-starts-block dummy-result)
1046     (ir1-convert-progn-body dummy-start dummy-result forms)
1047     (let ((end-block (continuation-block dummy-result)))
1048       (dolist (pred (block-pred end-block))
1049         (unlink-blocks pred end-block)
1050         (link-blocks pred cont-block))
1051       (aver (not (continuation-dest dummy-result)))
1052       (delete-continuation dummy-result)
1053       (remove-from-dfo end-block))))
1054 \f
1055 ;;;; interface to defining macros
1056
1057 ;;;; FIXME:
1058 ;;;;   classic CMU CL comment:
1059 ;;;;     DEFMACRO and DEFUN expand into calls to %DEFxxx functions
1060 ;;;;     so that we get a chance to see what is going on. We define
1061 ;;;;     IR1 translators for these functions which look at the
1062 ;;;;     definition and then generate a call to the %%DEFxxx function.
1063 ;;;; Alas, this implementation doesn't do the right thing for
1064 ;;;; non-toplevel uses of these forms, so this should probably
1065 ;;;; be changed to use EVAL-WHEN instead.
1066
1067 ;;; Return a new source path with any stuff intervening between the
1068 ;;; current path and the first form beginning with NAME stripped off.
1069 ;;; This is used to hide the guts of DEFmumble macros to prevent
1070 ;;; annoying error messages.
1071 (defun revert-source-path (name)
1072   (do ((path *current-path* (cdr path)))
1073       ((null path) *current-path*)
1074     (let ((first (first path)))
1075       (when (or (eq first name)
1076                 (eq first 'original-source-start))
1077         (return path)))))
1078
1079 (def-ir1-translator %define-compiler-macro ((name def lambda-list doc)
1080                                             start cont
1081                                             :kind :function)
1082   (let ((name (eval name))
1083         (def (second def))) ; We don't want to make a function just yet...
1084
1085     (when (eq (info :function :kind name) :special-form)
1086       (compiler-error "attempt to define a compiler-macro for special form ~S"
1087                       name))
1088
1089     (setf (info :function :compiler-macro-function name)
1090           (coerce def 'function))
1091
1092     (let* ((*current-path* (revert-source-path 'define-compiler-macro))
1093            (fun (ir1-convert-lambda def
1094                                     :debug-name (debug-namify
1095                                                  "DEFINE-COMPILER-MACRO ~S"
1096                                                  name))))
1097       (setf (functional-arg-documentation fun) (eval lambda-list))
1098
1099       (ir1-convert start cont `(%%define-compiler-macro ',name ,fun ,doc)))
1100
1101     (when sb!xc:*compile-print*
1102       (compiler-mumble "~&; converted ~S~%" name))))