1 ;;;; DEFMACRO machinery
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB!IMPL")
14 ;;; the guts of the DEFMACRO macro, pulled out into a separate
15 ;;; function in order to make it easier to express the common
17 ;;; CL:DEFMACRO SB!XC:DEFMACRO
18 ;;; SB!XC:DEFMACRO CL:DEFMACRO
19 (eval-when (:compile-toplevel :load-toplevel :execute)
20 (defun %expander-for-defmacro (name lambda-list body)
21 (let ((whole (gensym "WHOLE-"))
22 (environment (gensym "ENV-")))
23 (multiple-value-bind (new-body local-decs doc)
24 (parse-defmacro lambda-list whole body name 'defmacro
25 :environment environment)
26 (let ((def `(lambda (,whole ,environment)
30 `(sb!c::%defmacro ',name #',def ',lambda-list ,doc))))))
32 ;;; Ordinarily this definition of SB!C:%DEFMACRO as an ordinary
33 ;;; function is not used: the parallel (but different) definition as
34 ;;; an IR1 transform takes precedence. However, this definition is
35 ;;; still useful in the target interpreter, and in the
36 ;;; cross-compilation host.
37 (defun sb!c::%defmacro (name definition lambda-list doc)
38 (declare (ignore lambda-list))
39 (sb!c::%%defmacro name definition doc))
41 ;;; (called by SB!C::%DEFMACRO)
42 (eval-when (:compile-toplevel :load-toplevel :execute)
43 (defun sb!c::%%defmacro (name definition doc)
44 ;; old note (ca. 1985, maybe:-): "Eventually %%DEFMACRO should
45 ;; deal with clearing old compiler information for the functional
47 (clear-info :function :where-from name)
48 ;; FIXME: It would be nice to warn about DEFMACRO of an
49 ;; already-defined macro, but that's slightly hard to do because
50 ;; in common usage DEFMACRO is defined at compile time and then
51 ;; redefined at load time. We'd need to make a distinction between
52 ;; the defined-at-compile-time state and the defined-at-load-time
53 ;; state to make this work. (Trying to warn about duplicate
54 ;; DEFTYPEs runs into the same problem.)
55 #+nil (when (sb!xc:macro-function name)
56 (style-warn "redefining ~S in DEFMACRO" name))
57 (setf (sb!xc:macro-function name) definition
58 (fdocumentation name 'function) doc)
61 ;;; Parse the definition and make an expander function. The actual
62 ;;; definition is done by %DEFMACRO which we expand into, and which is
63 ;;; handled magically by an IR1 transform. After the compiler has
64 ;;; gotten the information it wants out of macro definition, it
65 ;;; compiles a call to %%DEFMACRO which happens at load time.
66 (defmacro sb!xc:defmacro (name lambda-list &rest body)
67 (%expander-for-defmacro name lambda-list body))
69 ;;; In the cross-compiler, we not only need to support the definition
70 ;;; of target macros at cross-compiler-build-time (with SB!XC:DEFMACRO
71 ;;; running in the cross-compilation host), we also need to support
72 ;;; the definition of target macros at target compilation time (with
73 ;;; CL:DEFMACRO processed by the cross-compiler)..
75 (sb!xc:defmacro defmacro (name lambda-list &rest body)
76 (%expander-for-defmacro name lambda-list body))
78 ;;; DEFMACRO-MUNDANELY is like SB!XC:DEFMACRO, except that it doesn't
79 ;;; have any EVAL-WHEN or IR1 magic associated with it, so it only
80 ;;; takes effect in :LOAD-TOPLEVEL or :EXECUTE situations.
82 ;;; FIXME: It'd probably be good (especially for DEFMACRO)
83 ;;; to make this share more code with DEFMACRO.
84 (def!macro defmacro-mundanely (name lambda-list &body body)
85 (let ((whole (gensym "WHOLE-"))
86 (environment (gensym "ENVIRONMENT-")))
87 (multiple-value-bind (new-body local-decs doc)
88 (parse-defmacro lambda-list whole body name 'defmacro
89 :environment environment)
91 (setf (sb!xc:macro-function ',name)
92 (lambda (,whole ,environment)
96 (setf (fdocumentation ',name 'macro)