0.7.3.18:
[sbcl.git] / src / code / defbangconstant.lisp
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
4 ;;;; This software is derived from the CMU CL system, which was
5 ;;;; written at Carnegie Mellon University and released into the
6 ;;;; public domain. The software is in the public domain and is
7 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
8 ;;;; files for more information.
9
10 (in-package "SB!KERNEL")
11 \f
12 ;;;; the DEF!CONSTANT macro
13
14 ;;; FIXME: This code was created by cut-and-paste from the
15 ;;; corresponding code for DEF!TYPE. DEF!CONSTANT, DEF!TYPE and
16 ;;; DEF!MACRO are currently very parallel, and if we ever manage to
17 ;;; rationalize the use of UNCROSS in the cross-compiler, they should
18 ;;; become completely parallel, at which time they should be merged to
19 ;;; eliminate the duplicate code.
20
21 ;;; *sigh* -- Even the comments are cut'n'pasted :-/ If I were more
22 ;;; confident in my understanding, I might try to do drastic surgery,
23 ;;; but my head is currently spinning (host? target? both?) so I'll go
24 ;;; for the minimal changeset... -- CSR, 2002-05-11
25 (defmacro def!constant (&rest rest name value &optional doc)
26   `(progn
27      #-sb-xc-host
28      (defconstant ,@rest)
29      #+sb-xc-host
30      ,(unless (eql (find-symbol (symbol-name name) :cl) name)
31         `(defconstant ,@rest))
32      #+sb-xc-host 
33      ,(let ((form `(sb!xc:defconstant ,@rest)))
34         (if (boundp '*delayed-def!constants*)
35             `(push ',form *delayed-def!constants*)
36             form))))
37
38 ;;; machinery to implement DEF!CONSTANT delays
39 #+sb-xc-host
40 (progn
41   (/show "binding *DELAYED-DEF!CONSTANTS*")
42   (defvar *delayed-def!constants* nil)
43   (/show "done binding *DELAYED-DEF!CONSTANTS*")
44   (defun force-delayed-def!constants ()
45     (if (boundp '*delayed-def!constants*)
46         (progn
47           (mapc #'eval *delayed-def!constants*)
48           (makunbound '*delayed-def!constants*))
49         ;; This condition is probably harmless if it comes up when
50         ;; interactively experimenting with the system by loading a
51         ;; source file into it more than once. But it's worth warning
52         ;; about it because it definitely shouldn't come up in an
53         ;; ordinary build process.
54         (warn "*DELAYED-DEF!CONSTANTS* is already unbound."))))