0.8.3.3:
[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)))
308       `(do* ((,n-list ,list (cdr ,n-list)))
309         ((endp ,n-list)
310          ,@(if result
311                `((let ((,var nil))
312                    ,var
313                    ,result))
314                '(nil)))
315         (let ((,var (car ,n-list)))
316           ,@decls
317           (tagbody
318              ,@forms))))))
319 \f
320 ;;;; conditions, handlers, restarts
321
322 ;;; KLUDGE: we PROCLAIM these special here so that we can use restart
323 ;;; macros in the compiler before the DEFVARs are compiled.
324 (sb!xc:proclaim
325  '(special *handler-clusters* *restart-clusters* *condition-restarts*))
326
327 (defmacro-mundanely with-condition-restarts
328     (condition-form restarts-form &body body)
329   #!+sb-doc
330   "WITH-CONDITION-RESTARTS Condition-Form Restarts-Form Form*
331    Evaluates the Forms in a dynamic environment where the restarts in the list
332    Restarts-Form are associated with the condition returned by Condition-Form.
333    This allows FIND-RESTART, etc., to recognize restarts that are not related
334    to the error currently being debugged. See also RESTART-CASE."
335   (let ((n-cond (gensym)))
336     `(let ((*condition-restarts*
337             (cons (let ((,n-cond ,condition-form))
338                     (cons ,n-cond
339                           (append ,restarts-form
340                                   (cdr (assoc ,n-cond *condition-restarts*)))))
341                   *condition-restarts*)))
342        ,@body)))
343
344 (defmacro-mundanely restart-bind (bindings &body forms)
345   #!+sb-doc
346   "Executes forms in a dynamic context where the given restart bindings are
347    in effect. Users probably want to use RESTART-CASE. When clauses contain
348    the same restart name, FIND-RESTART will find the first such clause."
349   `(let ((*restart-clusters*
350           (cons (list
351                  ,@(mapcar (lambda (binding)
352                              (unless (or (car binding)
353                                          (member :report-function
354                                                  binding
355                                                  :test #'eq))
356                                (warn "Unnamed restart does not have a ~
357                                         report function: ~S"
358                                      binding))
359                              `(make-restart :name ',(car binding)
360                                             :function ,(cadr binding)
361                                             ,@(cddr binding)))
362                            bindings))
363                 *restart-clusters*)))
364      ,@forms))
365
366 ;;; Wrap the RESTART-CASE expression in a WITH-CONDITION-RESTARTS if
367 ;;; appropriate. Gross, but it's what the book seems to say...
368 (defun munge-restart-case-expression (expression env)
369   (let ((exp (sb!xc:macroexpand expression env)))
370     (if (consp exp)
371         (let* ((name (car exp))
372                (args (if (eq name 'cerror) (cddr exp) (cdr exp))))
373           (if (member name '(signal error cerror warn))
374               (once-only ((n-cond `(coerce-to-condition
375                                     ,(first args)
376                                     (list ,@(rest args))
377                                     ',(case name
378                                         (warn 'simple-warning)
379                                         (signal 'simple-condition)
380                                         (t 'simple-error))
381                                     ',name)))
382                 `(with-condition-restarts
383                      ,n-cond
384                      (car *restart-clusters*)
385                    ,(if (eq name 'cerror)
386                         `(cerror ,(second expression) ,n-cond)
387                         `(,name ,n-cond))))
388               expression))
389         expression)))
390
391 ;;; FIXME: I did a fair amount of rearrangement of this code in order to
392 ;;; get WITH-KEYWORD-PAIRS to work cleanly. This code should be tested..
393 (defmacro-mundanely restart-case (expression &body clauses &environment env)
394   #!+sb-doc
395   "(RESTART-CASE form
396    {(case-name arg-list {keyword value}* body)}*)
397    The form is evaluated in a dynamic context where the clauses have special
398    meanings as points to which control may be transferred (see INVOKE-RESTART).
399    When clauses contain the same case-name, FIND-RESTART will find the first
400    such clause. If Expression is a call to SIGNAL, ERROR, CERROR or WARN (or
401    macroexpands into such) then the signalled condition will be associated with
402    the new restarts."
403   (flet ((transform-keywords (&key report interactive test)
404            (let ((result '()))
405              (when report
406                (setq result (list* (if (stringp report)
407                                        `#'(lambda (stream)
408                                             (write-string ,report stream))
409                                        `#',report)
410                                    :report-function
411                                    result)))
412              (when interactive
413                (setq result (list* `#',interactive
414                                    :interactive-function
415                                    result)))
416              (when test
417                (setq result (list* `#',test :test-function result)))
418              (nreverse result)))
419          (parse-keyword-pairs (list keys)
420            (do ((l list (cddr l))
421                 (k '() (list* (cadr l) (car l) k)))
422                ((or (null l) (not (member (car l) keys)))
423                 (values (nreverse k) l)))))
424     (let ((block-tag (gensym))
425           (temp-var (gensym))
426           (data
427            (macrolet (;; KLUDGE: This started as an old DEFMACRO
428                       ;; WITH-KEYWORD-PAIRS general utility, which was used
429                       ;; only in this one place in the code. It was translated
430                       ;; literally into this MACROLET in order to avoid some
431                       ;; cross-compilation bootstrap problems. It would almost
432                       ;; certainly be clearer, and it would certainly be more
433                       ;; concise, to do a more idiomatic translation, merging
434                       ;; this with the TRANSFORM-KEYWORDS logic above.
435                       ;;   -- WHN 19990925
436                       (with-keyword-pairs ((names expression) &body forms)
437                         (let ((temp (member '&rest names)))
438                           (unless (= (length temp) 2)
439                             (error "&REST keyword is ~:[missing~;misplaced~]."
440                                    temp))
441                           (let* ((key-vars (ldiff names temp))
442                                  (keywords (mapcar #'keywordicate key-vars))
443                                  (key-var (gensym))
444                                  (rest-var (cadr temp)))
445                             `(multiple-value-bind (,key-var ,rest-var)
446                                  (parse-keyword-pairs ,expression ',keywords)
447                                (let ,(mapcar (lambda (var keyword)
448                                                `(,var (getf ,key-var
449                                                             ,keyword)))
450                                              key-vars keywords)
451                                  ,@forms))))))
452              (mapcar (lambda (clause)
453                        (with-keyword-pairs ((report interactive test
454                                                     &rest forms)
455                                             (cddr clause))
456                          (list (car clause) ;name=0
457                                (gensym) ;tag=1
458                                (transform-keywords :report report ;keywords=2
459                                                    :interactive interactive
460                                                    :test test)
461                                (cadr clause) ;bvl=3
462                                forms))) ;body=4
463                    clauses))))
464       `(block ,block-tag
465          (let ((,temp-var nil))
466            (tagbody
467             (restart-bind
468                 ,(mapcar (lambda (datum)
469                            (let ((name (nth 0 datum))
470                                  (tag  (nth 1 datum))
471                                  (keys (nth 2 datum)))
472                              `(,name #'(lambda (&rest temp)
473                                          (setq ,temp-var temp)
474                                          (go ,tag))
475                                      ,@keys)))
476                          data)
477               (return-from ,block-tag
478                            ,(munge-restart-case-expression expression env)))
479             ,@(mapcan (lambda (datum)
480                         (let ((tag  (nth 1 datum))
481                               (bvl  (nth 3 datum))
482                               (body (nth 4 datum)))
483                           (list tag
484                                 `(return-from ,block-tag
485                                    (apply (lambda ,bvl ,@body)
486                                           ,temp-var)))))
487                       data)))))))
488
489 (defmacro-mundanely with-simple-restart ((restart-name format-string
490                                                        &rest format-arguments)
491                                          &body forms)
492   #!+sb-doc
493   "(WITH-SIMPLE-RESTART (restart-name format-string format-arguments)
494    body)
495    If restart-name is not invoked, then all values returned by forms are
496    returned. If control is transferred to this restart, it immediately
497    returns the values NIL and T."
498   `(restart-case
499        ;; If there's just one body form, then don't use PROGN. This allows
500        ;; RESTART-CASE to "see" calls to ERROR, etc.
501        ,(if (= (length forms) 1) (car forms) `(progn ,@forms))
502      (,restart-name ()
503         :report (lambda (stream)
504                   (format stream ,format-string ,@format-arguments))
505       (values nil t))))
506
507 (defmacro-mundanely handler-bind (bindings &body forms)
508   #!+sb-doc
509   "(HANDLER-BIND ( {(type handler)}* )  body)
510    Executes body in a dynamic context where the given handler bindings are
511    in effect. Each handler must take the condition being signalled as an
512    argument. The bindings are searched first to last in the event of a
513    signalled condition."
514   (let ((member-if (member-if (lambda (x)
515                                 (not (proper-list-of-length-p x 2)))
516                               bindings)))
517     (when member-if
518       (error "ill-formed handler binding: ~S" (first member-if))))
519   `(let ((*handler-clusters*
520           (cons (list ,@(mapcar (lambda (x) `(cons ',(car x) ,(cadr x)))
521                                 bindings))
522                 *handler-clusters*)))
523      (multiple-value-prog1
524          (progn
525            ,@forms)
526        ;; Wait for any float exceptions.
527        #!+x86 (float-wait))))
528
529 (defmacro-mundanely handler-case (form &rest cases)
530   "(HANDLER-CASE form
531    { (type ([var]) body) }* )
532    Execute FORM in a context with handlers established for the condition
533    types. A peculiar property allows type to be :NO-ERROR. If such a clause
534    occurs, and form returns normally, all its values are passed to this clause
535    as if by MULTIPLE-VALUE-CALL.  The :NO-ERROR clause accepts more than one
536    var specification."
537   ;; FIXME: Replacing CADR, CDDDR and friends with DESTRUCTURING-BIND
538   ;; and names for the subexpressions would make it easier to
539   ;; understand the code below.
540   (let ((no-error-clause (assoc ':no-error cases)))
541     (if no-error-clause
542         (let ((normal-return (make-symbol "normal-return"))
543               (error-return  (make-symbol "error-return")))
544           `(block ,error-return
545              (multiple-value-call (lambda ,@(cdr no-error-clause))
546                (block ,normal-return
547                  (return-from ,error-return
548                    (handler-case (return-from ,normal-return ,form)
549                      ,@(remove no-error-clause cases)))))))
550         (let ((tag (gensym))
551               (var (gensym))
552               (annotated-cases (mapcar (lambda (case) (cons (gensym) case))
553                                        cases)))
554           `(block ,tag
555              (let ((,var nil))
556                (declare (ignorable ,var))
557                (tagbody
558                 (handler-bind
559                     ,(mapcar (lambda (annotated-case)
560                                (list (cadr annotated-case)
561                                      `(lambda (temp)
562                                         ,(if (caddr annotated-case)
563                                              `(setq ,var temp)
564                                              '(declare (ignore temp)))
565                                         (go ,(car annotated-case)))))
566                              annotated-cases)
567                   (return-from ,tag
568                     #!-x86 ,form
569                     #!+x86 (multiple-value-prog1 ,form
570                              ;; Need to catch FP errors here!
571                              (float-wait))))
572                 ,@(mapcan
573                    (lambda (annotated-case)
574                      (list (car annotated-case)
575                            (let ((body (cdddr annotated-case)))
576                              `(return-from
577                                   ,tag
578                                 ,(cond ((caddr annotated-case)
579                                         `(let ((,(caaddr annotated-case)
580                                                 ,var))
581                                            ,@body))
582                                        ((not (cdr body))
583                                         (car body))
584                                        (t
585                                         `(progn ,@body)))))))
586                    annotated-cases))))))))
587 \f
588 ;;;; miscellaneous
589
590 (defmacro-mundanely return (&optional (value nil))
591   `(return-from nil ,value))
592
593 (defmacro-mundanely psetq (&rest pairs)
594   #!+sb-doc
595   "PSETQ {var value}*
596    Set the variables to the values, like SETQ, except that assignments
597    happen in parallel, i.e. no assignments take place until all the
598    forms have been evaluated."
599   ;; Given the possibility of symbol-macros, we delegate to PSETF
600   ;; which knows how to deal with them, after checking that syntax is
601   ;; compatible with PSETQ.
602   (do ((pair pairs (cddr pair)))
603       ((endp pair) `(psetf ,@pairs))
604     (unless (symbolp (car pair))
605       (error 'simple-program-error
606              :format-control "variable ~S in PSETQ is not a SYMBOL"
607              :format-arguments (list (car pair))))))
608
609 (defmacro-mundanely lambda (&whole whole args &body body)
610   (declare (ignore args body))
611   `#',whole)
612
613 (defmacro-mundanely named-lambda (&whole whole name args &body body)
614   (declare (ignore name args body))
615   `#',whole)
616
617 (defmacro-mundanely lambda-with-lexenv (&whole whole
618                                         declarations macros symbol-macros
619                                         &body body)
620   (declare (ignore declarations macros symbol-macros body))
621   `#',whole)
622
623 ;;; this eliminates a whole bundle of unknown function STYLE-WARNINGs
624 ;;; when cross-compiling.  It's not critical for behaviour, but is
625 ;;; aesthetically pleasing, except inasmuch as there's this list of
626 ;;; magic functions here.  -- CSR, 2003-04-01
627 #+sb-xc-host
628 (sb!xc:proclaim '(ftype (function * *)
629                         ;; functions appearing in fundamental defining
630                         ;; macro expansions:
631                         %compiler-deftype
632                         %defun
633                         %defsetf
634                         sb!c:%compiler-defun
635                         sb!c::%define-symbol-macro
636                         sb!c::%defconstant
637                         sb!c::%define-compiler-macro
638                         sb!c::%defmacro
639                         sb!kernel::%compiler-defstruct
640                         sb!kernel::%compiler-define-condition
641                         sb!kernel::%defstruct
642                         sb!kernel::%define-condition
643                         ;; miscellaneous functions commonly appearing
644                         ;; as a result of macro expansions or compiler
645                         ;; transformations:
646                         sb!int:find-undeleted-package-or-lose ; IN-PACKAGE
647                         sb!kernel::arg-count-error ; PARSE-DEFMACRO
648                         ))