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