1.0.42.24: print symbols with fully qualified names in critical places
[sbcl.git] / src / code / defmacro.lisp
index b93621b..c43a723 100644 (file)
 ;;; bootstrap idiom
 ;;;   CL:DEFMACRO SB!XC:DEFMACRO
 ;;;   SB!XC:DEFMACRO CL:DEFMACRO
-(eval-when (:compile-toplevel :load-toplevel :execute)
+(eval-when (#-sb-xc :compile-toplevel :load-toplevel :execute)
   (defun %expander-for-defmacro (name lambda-list body)
     (unless (symbolp name)
       (error "The macro name ~S is not a symbol." name))
+    ;; When we are building the cross-compiler, we could be in a host
+    ;; lisp which implements CL macros (e.g. CL:AND) as special
+    ;; operators (while still providing a macroexpansion for
+    ;; compliance): therefore can't use the host's SPECIAL-OPERATOR-P
+    ;; as a discriminator, but that's OK because the set of forms the
+    ;; cross-compiler compiles is tightly controlled.  -- CSR,
+    ;; 2003-04-20
+    #-sb-xc-host
     (when (special-operator-p name)
       (error "The special operator ~S can't be redefined as a macro."
              name))
-    (let ((whole (gensym "WHOLE-"))
-         (environment (gensym "ENV-")))
+    (with-unique-names (whole environment)
       (multiple-value-bind (new-body local-decs doc)
-         (parse-defmacro lambda-list whole body name 'defmacro
-                         :environment environment)
-       (let ((def `(lambda (,whole ,environment)
-                     ,@local-decs
-                     (block ,name
-                       ,new-body))))
-         `(eval-when (:compile-toplevel :load-toplevel :execute)
-             (sb!c::%defmacro ',name #',def ',lambda-list ,doc)))))))
+          (parse-defmacro lambda-list whole body name 'defmacro
+                          :environment environment)
+        (let ((def `(#+sb-xc-host lambda
+                     ;; Use a named-lambda rather than a lambda so that
+                     ;; proper xref information can be stored. Use a
+                     ;; list-based name, since otherwise the compiler
+                     ;; will momentarily assume that it names a normal
+                     ;; function, and report spurious warnings about
+                     ;; redefinition a macro as a function, and then
+                     ;; vice versa.
+                     #-sb-xc-host named-lambda #-sb-xc-host (defmacro ,name)
+                     (,whole ,environment)
+                      ,@local-decs
+                      ,new-body))
+              (debug-name (sb!c::debug-name 'macro-function name)))
+          `(eval-when (:compile-toplevel :load-toplevel :execute)
+             (sb!c::%defmacro ',name #',def ',lambda-list
+                              ,doc ',debug-name)))))))
 
 (macrolet
-    ((def (times set-args-p)
+    ((def (times set-p)
        `(eval-when (,@times)
-          (defun sb!c::%defmacro (name definition lambda-list doc)
+          (defun sb!c::%defmacro (name definition lambda-list doc debug-name)
             ;; old note (ca. 1985, maybe:-): "Eventually %%DEFMACRO
             ;; should deal with clearing old compiler information for
             ;; the functional value."
+            ,@(unless set-p
+                '((declare (ignore lambda-list debug-name))))
             (ecase (info :function :kind name)
               ((nil))
               (:function
                     ;; being incompatibly redefined. Doing this right
                     ;; will involve finding the old macro lambda-list
                     ;; and comparing it with the new one.
-                    (style-warn "redefining ~S in DEFMACRO" name))
-            (setf (sb!xc:macro-function name) definition
-                  (fdocumentation name 'function) doc)
-            ,(when set-args-p
-                   `(case (widetag-of definition)
-                      (#.sb!vm:closure-header-widetag
-                       (setf (%simple-fun-arglist (%closure-fun definition))
-                             lambda-list))
-                      ((#.sb!vm:simple-fun-header-widetag
-                        #.sb!vm:closure-fun-header-widetag)
-                       (setf (%simple-fun-arglist definition) lambda-list))))
+                    (style-warn "redefining ~/sb-impl::print-symbol-with-prefix/ ~
+                                 in DEFMACRO" name))
+            (setf (sb!xc:macro-function name) definition)
+            ,(when set-p
+                   `(setf (%fun-doc definition) doc
+                          (%fun-lambda-list definition) lambda-list
+                          (%fun-name definition) debug-name))
             name))))
   (progn
     (def (:load-toplevel :execute) #-sb-xc-host t #+sb-xc-host nil)
-    (def (:compile-toplevel) nil)))
+    (def (#-sb-xc :compile-toplevel) nil)))
 
 ;;; Parse the definition and make an expander function. The actual
 ;;; definition is done by %DEFMACRO which we expand into. After the