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