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