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