0.8.3.81:
[sbcl.git] / src / code / defboot.lisp
1 ;;;; bootstrapping fundamental machinery (e.g. DEFUN, DEFCONSTANT,
2 ;;;; DEFVAR) from special forms and primitive functions
3 ;;;;
4 ;;;; KLUDGE: The bootstrapping aspect of this is now obsolete. It was
5 ;;;; originally intended that this file file would be loaded into a
6 ;;;; Lisp image which had Common Lisp primitives defined, and DEFMACRO
7 ;;;; defined, and little else. Since then that approach has been
8 ;;;; dropped and this file has been modified somewhat to make it work
9 ;;;; more cleanly when used to predefine macros at
10 ;;;; build-the-cross-compiler time.
11
12 ;;;; This software is part of the SBCL system. See the README file for
13 ;;;; more information.
14 ;;;;
15 ;;;; This software is derived from the CMU CL system, which was
16 ;;;; written at Carnegie Mellon University and released into the
17 ;;;; public domain. The software is in the public domain and is
18 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
19 ;;;; files for more information.
20
21 (in-package "SB!IMPL")
22 \f
23 ;;;; IN-PACKAGE
24
25 (defmacro-mundanely in-package (package-designator)
26   `(eval-when (:compile-toplevel :load-toplevel :execute)
27      (setq *package* (find-undeleted-package-or-lose ',package-designator))))
28 \f
29 ;;;; MULTIPLE-VALUE-FOO
30
31 (defun list-of-symbols-p (x)
32   (and (listp x)
33        (every #'symbolp x)))
34
35 (defmacro-mundanely multiple-value-bind (vars value-form &body body)
36   (if (list-of-symbols-p vars)
37     ;; It's unclear why it would be important to special-case the LENGTH=1 case
38     ;; at this level, but the CMU CL code did it, so.. -- WHN 19990411
39     (if (= (length vars) 1)
40       `(let ((,(car vars) ,value-form))
41          ,@body)
42       (let ((ignore (gensym)))
43         `(multiple-value-call #'(lambda (&optional ,@vars &rest ,ignore)
44                                   (declare (ignore ,ignore))
45                                   ,@body)
46                               ,value-form)))
47     (error "Vars is not a list of symbols: ~S" vars)))
48
49 (defmacro-mundanely multiple-value-setq (vars value-form)
50   (unless (list-of-symbols-p vars)
51     (error "Vars is not a list of symbols: ~S" vars))
52   `(values (setf (values ,@vars) ,value-form)))
53
54 (defmacro-mundanely multiple-value-list (value-form)
55   `(multiple-value-call #'list ,value-form))
56 \f
57 ;;;; various conditional constructs
58
59 ;;; COND defined in terms of IF
60 (defmacro-mundanely cond (&rest clauses)
61   (if (endp clauses)
62       nil
63       (let ((clause (first clauses)))
64         (if (atom clause)
65             (error "COND clause is not a list: ~S" clause)
66             (let ((test (first clause))
67                   (forms (rest clause)))
68               (if (endp forms)
69                   (let ((n-result (gensym)))
70                     `(let ((,n-result ,test))
71                        (if ,n-result
72                            ,n-result
73                            (cond ,@(rest clauses)))))
74                   `(if ,test
75                        (progn ,@forms)
76                        (cond ,@(rest clauses)))))))))
77
78 ;;; other things defined in terms of COND
79 (defmacro-mundanely when (test &body forms)
80   #!+sb-doc
81   "If the first argument is true, the rest of the forms are
82   evaluated as a PROGN."
83   `(cond (,test nil ,@forms)))
84 (defmacro-mundanely unless (test &body forms)
85   #!+sb-doc
86   "If the first argument is not true, the rest of the forms are
87   evaluated as a PROGN."
88   `(cond ((not ,test) nil ,@forms)))
89 (defmacro-mundanely and (&rest forms)
90   (cond ((endp forms) t)
91         ((endp (rest forms)) (first forms))
92         (t
93          `(if ,(first forms)
94               (and ,@(rest forms))
95               nil))))
96 (defmacro-mundanely or (&rest forms)
97   (cond ((endp forms) nil)
98         ((endp (rest forms)) (first forms))
99         (t
100          (let ((n-result (gensym)))
101            `(let ((,n-result ,(first forms)))
102               (if ,n-result
103                   ,n-result
104                   (or ,@(rest forms))))))))
105 \f
106 ;;;; various sequencing constructs
107
108 (flet ((prog-expansion-from-let (varlist body-decls let)
109          (multiple-value-bind (body decls)
110              (parse-body body-decls :doc-string-allowed nil)
111            `(block nil
112               (,let ,varlist
113                 ,@decls
114                 (tagbody ,@body))))))
115   (defmacro-mundanely prog (varlist &body body-decls)
116     (prog-expansion-from-let varlist body-decls 'let))
117   (defmacro-mundanely prog* (varlist &body body-decls)
118     (prog-expansion-from-let varlist body-decls 'let*)))
119
120 (defmacro-mundanely prog1 (result &body body)
121   (let ((n-result (gensym)))
122     `(let ((,n-result ,result))
123        ,@body
124        ,n-result)))
125
126 (defmacro-mundanely prog2 (form1 result &body body)
127   `(prog1 (progn ,form1 ,result) ,@body))
128 \f
129 ;;;; DEFUN
130
131 ;;; Should we save the inline expansion of the function named NAME?
132 (defun inline-fun-name-p (name)
133   (or
134    ;; the normal reason for saving the inline expansion
135    (info :function :inlinep name)
136    ;; another reason for saving the inline expansion: If the
137    ;; ANSI-recommended idiom
138    ;;   (DECLAIM (INLINE FOO))
139    ;;   (DEFUN FOO ..)
140    ;;   (DECLAIM (NOTINLINE FOO))
141    ;; has been used, and then we later do another
142    ;;   (DEFUN FOO ..)
143    ;; without a preceding
144    ;;   (DECLAIM (INLINE FOO))
145    ;; what should we do with the old inline expansion when we see the
146    ;; new DEFUN? Overwriting it with the new definition seems like
147    ;; the only unsurprising choice.
148    (info :function :inline-expansion-designator name)))
149
150 (defmacro-mundanely defun (&environment env name args &body body)
151   "Define a function at top level."
152   #+sb-xc-host
153   (unless (symbol-package (fun-name-block-name name))
154     (warn "DEFUN of uninterned symbol ~S (tricky for GENESIS)" name))
155   (multiple-value-bind (forms decls doc) (parse-body body)
156     (let* (;; stuff shared between LAMBDA and INLINE-LAMBDA and NAMED-LAMBDA
157            (lambda-guts `(,args
158                           ,@decls
159                           (block ,(fun-name-block-name name)
160                             ,@forms)))
161            (lambda `(lambda ,@lambda-guts))
162            #-sb-xc-host
163            (named-lambda `(named-lambda ,name ,@lambda-guts))
164            (inline-lambda
165             (when (inline-fun-name-p name)
166               ;; we want to attempt to inline, so complain if we can't
167               (or (sb!c:maybe-inline-syntactic-closure lambda env)
168                   (progn
169                     (#+sb-xc-host warn
170                      #-sb-xc-host sb!c:maybe-compiler-notify
171                      "lexical environment too hairy, can't inline DEFUN ~S"
172                      name)
173                     nil)))))
174       `(progn
175
176          ;; In cross-compilation of toplevel DEFUNs, we arrange
177          ;; for the LAMBDA to be statically linked by GENESIS.
178          ;;
179          ;; It may seem strangely inconsistent not to use NAMED-LAMBDA
180          ;; here instead of LAMBDA. The reason is historical:
181          ;; COLD-FSET was written before NAMED-LAMBDA, and has special
182          ;; logic of its own to notify the compiler about NAME.
183          #+sb-xc-host
184          (cold-fset ,name ,lambda)
185
186          (eval-when (:compile-toplevel :load-toplevel :execute)
187            (sb!c:%compiler-defun ',name ',inline-lambda))
188
189          (%defun ',name
190                  ;; In normal compilation (not for cold load) this is
191                  ;; where the compiled LAMBDA first appears. In
192                  ;; cross-compilation, we manipulate the
193                  ;; previously-statically-linked LAMBDA here.
194                  #-sb-xc-host ,named-lambda
195                  #+sb-xc-host (fdefinition ',name)
196                  ,doc)))))
197 #-sb-xc-host
198 (defun %defun (name def doc)
199   (declare (type function def))
200   (declare (type (or null simple-string) doc))
201   (aver (legal-fun-name-p name)) ; should've been checked by DEFMACRO DEFUN
202   (when (fboundp name)
203     (/show0 "redefining NAME in %DEFUN")
204     (style-warn "redefining ~S in DEFUN" name))
205   (setf (sb!xc:fdefinition name) def)
206   
207   ;; FIXME: I want to do this here (and fix bug 137), but until the
208   ;; breathtaking CMU CL function name architecture is converted into
209   ;; something sane, (1) doing so doesn't really fix the bug, and 
210   ;; (2) doing probably isn't even really safe.
211   #+nil (setf (%fun-name def) name)
212
213   (when doc
214     (setf (fdocumentation name 'function) doc))
215   name)
216 \f
217 ;;;; DEFVAR and DEFPARAMETER
218
219 (defmacro-mundanely defvar (var &optional (val nil valp) (doc nil docp))
220   #!+sb-doc
221   "Define a global variable at top level. Declare the variable
222   SPECIAL and, optionally, initialize it. If the variable already has a
223   value, the old value is not clobbered. The third argument is an optional
224   documentation string for the variable."
225   `(progn
226      (declaim (special ,var))
227      ,@(when valp
228          `((unless (boundp ',var)
229              (set ',var ,val))))
230      ,@(when docp
231          `((setf (fdocumentation ',var 'variable) ',doc )))
232      ',var))
233
234 (defmacro-mundanely defparameter (var val &optional (doc nil docp))
235   #!+sb-doc
236   "Define a parameter that is not normally changed by the program,
237   but that may be changed without causing an error. Declare the
238   variable special and sets its value to VAL, overwriting any
239   previous value. The third argument is an optional documentation
240   string for the parameter."
241   `(progn
242      (declaim (special ,var))
243      (set ',var ,val)
244      ,@(when docp
245          `((setf (fdocumentation ',var 'variable) ',doc)))
246      ',var))
247 \f
248 ;;;; iteration constructs
249
250 ;;; (These macros are defined in terms of a function FROB-DO-BODY which
251 ;;; is also used by SB!INT:DO-ANONYMOUS. Since these macros should not
252 ;;; be loaded on the cross-compilation host, but SB!INT:DO-ANONYMOUS
253 ;;; and FROB-DO-BODY should be, these macros can't conveniently be in
254 ;;; the same file as FROB-DO-BODY.)
255 (defmacro-mundanely do (varlist endlist &body body)
256   #!+sb-doc
257   "DO ({(Var [Init] [Step])}*) (Test Exit-Form*) Declaration* Form*
258   Iteration construct. Each Var is initialized in parallel to the value of the
259   specified Init form. On subsequent iterations, the Vars are assigned the
260   value of the Step form (if any) in parallel. The Test is evaluated before
261   each evaluation of the body Forms. When the Test is true, the Exit-Forms
262   are evaluated as a PROGN, with the result being the value of the DO. A block
263   named NIL is established around the entire expansion, allowing RETURN to be
264   used as an alternate exit mechanism."
265   (frob-do-body varlist endlist body 'let 'psetq 'do nil))
266 (defmacro-mundanely do* (varlist endlist &body body)
267   #!+sb-doc
268   "DO* ({(Var [Init] [Step])}*) (Test Exit-Form*) Declaration* Form*
269   Iteration construct. Each Var is initialized sequentially (like LET*) to the
270   value of the specified Init form. On subsequent iterations, the Vars are
271   sequentially assigned the value of the Step form (if any). The Test is
272   evaluated before each evaluation of the body Forms. When the Test is true,
273   the Exit-Forms are evaluated as a PROGN, with the result being the value
274   of the DO. A block named NIL is established around the entire expansion,
275   allowing RETURN to be used as an laternate exit mechanism."
276   (frob-do-body varlist endlist body 'let* 'setq 'do* nil))
277
278 ;;; DOTIMES and DOLIST could be defined more concisely using
279 ;;; destructuring macro lambda lists or DESTRUCTURING-BIND, but then
280 ;;; it'd be tricky to use them before those things were defined.
281 ;;; They're used enough times before destructuring mechanisms are
282 ;;; defined that it looks as though it's worth just implementing them
283 ;;; ASAP, at the cost of being unable to use the standard
284 ;;; destructuring mechanisms.
285 (defmacro-mundanely dotimes ((var count &optional (result nil)) &body body)
286   (cond ((numberp count)
287          `(do ((,var 0 (1+ ,var)))
288               ((>= ,var ,count) ,result)
289             (declare (type unsigned-byte ,var))
290             ,@body))
291         (t (let ((v1 (gensym)))
292              `(do ((,var 0 (1+ ,var)) (,v1 ,count))
293                   ((>= ,var ,v1) ,result)
294                 (declare (type unsigned-byte ,var))
295                 ,@body)))))
296
297 (defmacro-mundanely dolist ((var list &optional (result nil)) &body body)
298   ;; We repeatedly bind the var instead of setting it so that we never
299   ;; have to give the var an arbitrary value such as NIL (which might
300   ;; conflict with a declaration). If there is a result form, we
301   ;; introduce a gratuitous binding of the variable to NIL without the
302   ;; declarations, then evaluate the result form in that
303   ;; environment. We spuriously reference the gratuitous variable,
304   ;; since we don't want to use IGNORABLE on what might be a special
305   ;; var.
306   (multiple-value-bind (forms decls) (parse-body body :doc-string-allowed nil)
307     (let ((n-list (gensym "N-LIST"))
308           (start (gensym "START")))
309       `(block nil
310          (let ((,n-list ,list))
311            (tagbody
312               ,start
313               (unless (endp ,n-list)
314                 (let ((,var (car ,n-list)))
315                   ,@decls
316                   (setq ,n-list (cdr ,n-list))
317                   (tagbody ,@forms))
318                 (go ,start))))
319          ,(if result
320               `(let ((,var nil))
321                  ,var
322                  ,result)
323                nil)))))
324 \f
325 ;;;; conditions, handlers, restarts
326
327 ;;; KLUDGE: we PROCLAIM these special here so that we can use restart
328 ;;; macros in the compiler before the DEFVARs are compiled.
329 (sb!xc:proclaim
330  '(special *handler-clusters* *restart-clusters* *condition-restarts*))
331
332 (defmacro-mundanely with-condition-restarts
333     (condition-form restarts-form &body body)
334   #!+sb-doc
335   "WITH-CONDITION-RESTARTS Condition-Form Restarts-Form Form*
336    Evaluates the Forms in a dynamic environment where the restarts in the list
337    Restarts-Form are associated with the condition returned by Condition-Form.
338    This allows FIND-RESTART, etc., to recognize restarts that are not related
339    to the error currently being debugged. See also RESTART-CASE."
340   (let ((n-cond (gensym)))
341     `(let ((*condition-restarts*
342             (cons (let ((,n-cond ,condition-form))
343                     (cons ,n-cond
344                           (append ,restarts-form
345                                   (cdr (assoc ,n-cond *condition-restarts*)))))
346                   *condition-restarts*)))
347        ,@body)))
348
349 (defmacro-mundanely restart-bind (bindings &body forms)
350   #!+sb-doc
351   "Executes forms in a dynamic context where the given restart bindings are
352    in effect. Users probably want to use RESTART-CASE. When clauses contain
353    the same restart name, FIND-RESTART will find the first such clause."
354   `(let ((*restart-clusters*
355           (cons (list
356                  ,@(mapcar (lambda (binding)
357                              (unless (or (car binding)
358                                          (member :report-function
359                                                  binding
360                                                  :test #'eq))
361                                (warn "Unnamed restart does not have a ~
362                                         report function: ~S"
363                                      binding))
364                              `(make-restart :name ',(car binding)
365                                             :function ,(cadr binding)
366                                             ,@(cddr binding)))
367                            bindings))
368                 *restart-clusters*)))
369      ,@forms))
370
371 ;;; Wrap the RESTART-CASE expression in a WITH-CONDITION-RESTARTS if
372 ;;; appropriate. Gross, but it's what the book seems to say...
373 (defun munge-restart-case-expression (expression env)
374   (let ((exp (sb!xc:macroexpand expression env)))
375     (if (consp exp)
376         (let* ((name (car exp))
377                (args (if (eq name 'cerror) (cddr exp) (cdr exp))))
378           (if (member name '(signal error cerror warn))
379               (once-only ((n-cond `(coerce-to-condition
380                                     ,(first args)
381                                     (list ,@(rest args))
382                                     ',(case name
383                                         (warn 'simple-warning)
384                                         (signal 'simple-condition)
385                                         (t 'simple-error))
386                                     ',name)))
387                 `(with-condition-restarts
388                      ,n-cond
389                      (car *restart-clusters*)
390                    ,(if (eq name 'cerror)
391                         `(cerror ,(second exp) ,n-cond)
392                         `(,name ,n-cond))))
393               expression))
394         expression)))
395
396 ;;; FIXME: I did a fair amount of rearrangement of this code in order to
397 ;;; get WITH-KEYWORD-PAIRS to work cleanly. This code should be tested..
398 (defmacro-mundanely restart-case (expression &body clauses &environment env)
399   #!+sb-doc
400   "(RESTART-CASE form
401    {(case-name arg-list {keyword value}* body)}*)
402    The form is evaluated in a dynamic context where the clauses have special
403    meanings as points to which control may be transferred (see INVOKE-RESTART).
404    When clauses contain the same case-name, FIND-RESTART will find the first
405    such clause. If Expression is a call to SIGNAL, ERROR, CERROR or WARN (or
406    macroexpands into such) then the signalled condition will be associated with
407    the new restarts."
408   (flet ((transform-keywords (&key report interactive test)
409            (let ((result '()))
410              (when report
411                (setq result (list* (if (stringp report)
412                                        `#'(lambda (stream)
413                                             (write-string ,report stream))
414                                        `#',report)
415                                    :report-function
416                                    result)))
417              (when interactive
418                (setq result (list* `#',interactive
419                                    :interactive-function
420                                    result)))
421              (when test
422                (setq result (list* `#',test :test-function result)))
423              (nreverse result)))
424          (parse-keyword-pairs (list keys)
425            (do ((l list (cddr l))
426                 (k '() (list* (cadr l) (car l) k)))
427                ((or (null l) (not (member (car l) keys)))
428                 (values (nreverse k) l)))))
429     (let ((block-tag (gensym))
430           (temp-var (gensym))
431           (data
432            (macrolet (;; KLUDGE: This started as an old DEFMACRO
433                       ;; WITH-KEYWORD-PAIRS general utility, which was used
434                       ;; only in this one place in the code. It was translated
435                       ;; literally into this MACROLET in order to avoid some
436                       ;; cross-compilation bootstrap problems. It would almost
437                       ;; certainly be clearer, and it would certainly be more
438                       ;; concise, to do a more idiomatic translation, merging
439                       ;; this with the TRANSFORM-KEYWORDS logic above.
440                       ;;   -- WHN 19990925
441                       (with-keyword-pairs ((names expression) &body forms)
442                         (let ((temp (member '&rest names)))
443                           (unless (= (length temp) 2)
444                             (error "&REST keyword is ~:[missing~;misplaced~]."
445                                    temp))
446                           (let* ((key-vars (ldiff names temp))
447                                  (keywords (mapcar #'keywordicate key-vars))
448                                  (key-var (gensym))
449                                  (rest-var (cadr temp)))
450                             `(multiple-value-bind (,key-var ,rest-var)
451                                  (parse-keyword-pairs ,expression ',keywords)
452                                (let ,(mapcar (lambda (var keyword)
453                                                `(,var (getf ,key-var
454                                                             ,keyword)))
455                                              key-vars keywords)
456                                  ,@forms))))))
457              (mapcar (lambda (clause)
458                        (with-keyword-pairs ((report interactive test
459                                                     &rest forms)
460                                             (cddr clause))
461                          (list (car clause) ;name=0
462                                (gensym) ;tag=1
463                                (transform-keywords :report report ;keywords=2
464                                                    :interactive interactive
465                                                    :test test)
466                                (cadr clause) ;bvl=3
467                                forms))) ;body=4
468                    clauses))))
469       `(block ,block-tag
470          (let ((,temp-var nil))
471            (tagbody
472             (restart-bind
473                 ,(mapcar (lambda (datum)
474                            (let ((name (nth 0 datum))
475                                  (tag  (nth 1 datum))
476                                  (keys (nth 2 datum)))
477                              `(,name #'(lambda (&rest temp)
478                                          (setq ,temp-var temp)
479                                          (go ,tag))
480                                      ,@keys)))
481                          data)
482               (return-from ,block-tag
483                            ,(munge-restart-case-expression expression env)))
484             ,@(mapcan (lambda (datum)
485                         (let ((tag  (nth 1 datum))
486                               (bvl  (nth 3 datum))
487                               (body (nth 4 datum)))
488                           (list tag
489                                 `(return-from ,block-tag
490                                    (apply (lambda ,bvl ,@body)
491                                           ,temp-var)))))
492                       data)))))))
493
494 (defmacro-mundanely with-simple-restart ((restart-name format-string
495                                                        &rest format-arguments)
496                                          &body forms)
497   #!+sb-doc
498   "(WITH-SIMPLE-RESTART (restart-name format-string format-arguments)
499    body)
500    If restart-name is not invoked, then all values returned by forms are
501    returned. If control is transferred to this restart, it immediately
502    returns the values NIL and T."
503   `(restart-case
504        ;; If there's just one body form, then don't use PROGN. This allows
505        ;; RESTART-CASE to "see" calls to ERROR, etc.
506        ,(if (= (length forms) 1) (car forms) `(progn ,@forms))
507      (,restart-name ()
508         :report (lambda (stream)
509                   (format stream ,format-string ,@format-arguments))
510       (values nil t))))
511
512 (defmacro-mundanely handler-bind (bindings &body forms)
513   #!+sb-doc
514   "(HANDLER-BIND ( {(type handler)}* )  body)
515    Executes body in a dynamic context where the given handler bindings are
516    in effect. Each handler must take the condition being signalled as an
517    argument. The bindings are searched first to last in the event of a
518    signalled condition."
519   (let ((member-if (member-if (lambda (x)
520                                 (not (proper-list-of-length-p x 2)))
521                               bindings)))
522     (when member-if
523       (error "ill-formed handler binding: ~S" (first member-if))))
524   `(let ((*handler-clusters*
525           (cons (list ,@(mapcar (lambda (x) `(cons ',(car x) ,(cadr x)))
526                                 bindings))
527                 *handler-clusters*)))
528      (multiple-value-prog1
529          (progn
530            ,@forms)
531        ;; Wait for any float exceptions.
532        #!+x86 (float-wait))))
533
534 (defmacro-mundanely handler-case (form &rest cases)
535   "(HANDLER-CASE form
536    { (type ([var]) body) }* )
537    Execute FORM in a context with handlers established for the condition
538    types. A peculiar property allows type to be :NO-ERROR. If such a clause
539    occurs, and form returns normally, all its values are passed to this clause
540    as if by MULTIPLE-VALUE-CALL.  The :NO-ERROR clause accepts more than one
541    var specification."
542   ;; FIXME: Replacing CADR, CDDDR and friends with DESTRUCTURING-BIND
543   ;; and names for the subexpressions would make it easier to
544   ;; understand the code below.
545   (let ((no-error-clause (assoc ':no-error cases)))
546     (if no-error-clause
547         (let ((normal-return (make-symbol "normal-return"))
548               (error-return  (make-symbol "error-return")))
549           `(block ,error-return
550              (multiple-value-call (lambda ,@(cdr no-error-clause))
551                (block ,normal-return
552                  (return-from ,error-return
553                    (handler-case (return-from ,normal-return ,form)
554                      ,@(remove no-error-clause cases)))))))
555         (let ((tag (gensym))
556               (var (gensym))
557               (annotated-cases (mapcar (lambda (case) (cons (gensym) case))
558                                        cases)))
559           `(block ,tag
560              (let ((,var nil))
561                (declare (ignorable ,var))
562                (tagbody
563                 (handler-bind
564                     ,(mapcar (lambda (annotated-case)
565                                (list (cadr annotated-case)
566                                      `(lambda (temp)
567                                         ,(if (caddr annotated-case)
568                                              `(setq ,var temp)
569                                              '(declare (ignore temp)))
570                                         (go ,(car annotated-case)))))
571                              annotated-cases)
572                   (return-from ,tag
573                     #!-x86 ,form
574                     #!+x86 (multiple-value-prog1 ,form
575                              ;; Need to catch FP errors here!
576                              (float-wait))))
577                 ,@(mapcan
578                    (lambda (annotated-case)
579                      (list (car annotated-case)
580                            (let ((body (cdddr annotated-case)))
581                              `(return-from
582                                   ,tag
583                                 ,(cond ((caddr annotated-case)
584                                         `(let ((,(caaddr annotated-case)
585                                                 ,var))
586                                            ,@body))
587                                        ((not (cdr body))
588                                         (car body))
589                                        (t
590                                         `(progn ,@body)))))))
591                    annotated-cases))))))))
592 \f
593 ;;;; miscellaneous
594
595 (defmacro-mundanely return (&optional (value nil))
596   `(return-from nil ,value))
597
598 (defmacro-mundanely psetq (&rest pairs)
599   #!+sb-doc
600   "PSETQ {var value}*
601    Set the variables to the values, like SETQ, except that assignments
602    happen in parallel, i.e. no assignments take place until all the
603    forms have been evaluated."
604   ;; Given the possibility of symbol-macros, we delegate to PSETF
605   ;; which knows how to deal with them, after checking that syntax is
606   ;; compatible with PSETQ.
607   (do ((pair pairs (cddr pair)))
608       ((endp pair) `(psetf ,@pairs))
609     (unless (symbolp (car pair))
610       (error 'simple-program-error
611              :format-control "variable ~S in PSETQ is not a SYMBOL"
612              :format-arguments (list (car pair))))))
613
614 (defmacro-mundanely lambda (&whole whole args &body body)
615   (declare (ignore args body))
616   `#',whole)
617
618 (defmacro-mundanely named-lambda (&whole whole name args &body body)
619   (declare (ignore name args body))
620   `#',whole)
621
622 (defmacro-mundanely lambda-with-lexenv (&whole whole
623                                         declarations macros symbol-macros
624                                         &body body)
625   (declare (ignore declarations macros symbol-macros body))
626   `#',whole)
627
628 ;;; this eliminates a whole bundle of unknown function STYLE-WARNINGs
629 ;;; when cross-compiling.  It's not critical for behaviour, but is
630 ;;; aesthetically pleasing, except inasmuch as there's this list of
631 ;;; magic functions here.  -- CSR, 2003-04-01
632 #+sb-xc-host
633 (sb!xc:proclaim '(ftype (function * *)
634                         ;; functions appearing in fundamental defining
635                         ;; macro expansions:
636                         %compiler-deftype
637                         %defun
638                         %defsetf
639                         sb!c:%compiler-defun
640                         sb!c::%define-symbol-macro
641                         sb!c::%defconstant
642                         sb!c::%define-compiler-macro
643                         sb!c::%defmacro
644                         sb!kernel::%compiler-defstruct
645                         sb!kernel::%compiler-define-condition
646                         sb!kernel::%defstruct
647                         sb!kernel::%define-condition
648                         ;; miscellaneous functions commonly appearing
649                         ;; as a result of macro expansions or compiler
650                         ;; transformations:
651                         sb!int:find-undeleted-package-or-lose ; IN-PACKAGE
652                         sb!kernel::arg-count-error ; PARSE-DEFMACRO
653                         ))