0.6.7.22: removed CVS dollar-Header-dollar tags from sources
[sbcl.git] / src / compiler / early-c.lisp
1 ;;;; This file contains compiler code and compiler-related stuff which
2 ;;;; can be built early on. Some of the stuff may be here because it's
3 ;;;; needed early on, some other stuff (e.g. constants) just because
4 ;;;; it might as well be done early so we don't have to think about
5 ;;;; whether it's done early enough.
6
7 ;;;; This software is part of the SBCL system. See the README file for
8 ;;;; more information.
9 ;;;;
10 ;;;; This software is derived from the CMU CL system, which was
11 ;;;; written at Carnegie Mellon University and released into the
12 ;;;; public domain. The software is in the public domain and is
13 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
14 ;;;; files for more information.
15
16 (in-package "SB!C")
17
18 ;;; FIXME: shouldn't SB-C::&MORE be in this list?
19 (defconstant sb!xc:lambda-list-keywords
20   '(&optional &rest &key &aux &body &whole &allow-other-keys &environment)
21   #!+sb-doc
22   "symbols which are magical in a lambda list")
23 \f
24 ;;;; cross-compiler-only versions of CL special variables, so that we
25 ;;;; don't have weird interactions with the host compiler
26
27 (defvar sb!xc:*compile-file-pathname*)
28 (defvar sb!xc:*compile-file-truename*)
29 (defvar sb!xc:*compile-print*)
30 (defvar sb!xc:*compile-verbose*)
31 \f
32 ;;;; miscellaneous types used both in the cross-compiler and on the target
33
34 ;;;; FIXME: The INDEX and LAYOUT-DEPTHOID definitions probably belong
35 ;;;; somewhere else, not "early-c", since they're after all not part
36 ;;;; of the compiler.
37
38 ;;; the type of LAYOUT-DEPTHOID slot values
39 (def!type sb!kernel::layout-depthoid () '(or index (integer -1 -1)))
40
41 ;;; a value for an optimization declaration
42 (def!type sb!c::cookie-quality () '(or (rational 0 3) null))
43 \f
44 ;;; A COOKIE holds information about the compilation environment for a
45 ;;; node. See the LEXENV definition for a description of how it is
46 ;;; used.
47 (def!struct (cookie (:copier nil))
48   (speed   nil :type cookie-quality)
49   (space   nil :type cookie-quality)
50   (safety  nil :type cookie-quality)
51   (cspeed  nil :type cookie-quality)
52   (brevity nil :type cookie-quality)
53   (debug   nil :type cookie-quality))
54
55 ;;; KLUDGE: This needs to be executable in cold init toplevel forms, earlier
56 ;;; than the default copier closure created by DEFSTRUCT toplevel forms would
57 ;;; be available, and earlier than LAYOUT-INFO is initialized (which is a
58 ;;; prerequisite for COPY-STRUCTURE to work), so we define it explicitly using
59 ;;; DEFUN, so that it can be installed by the cold loader, and using
60 ;;; hand-written, hand-maintained slot-by-slot copy it doesn't need to call
61 ;;; COPY-STRUCTURE. -- WHN 19991019
62 (defun copy-cookie (cookie)
63   (make-cookie :speed   (cookie-speed   cookie)
64                :space   (cookie-space   cookie)
65                :safety  (cookie-safety  cookie)
66                :cspeed  (cookie-cspeed  cookie)
67                :brevity (cookie-brevity cookie)
68                :debug   (cookie-debug   cookie)))
69
70 ;;; *DEFAULT-COOKIE* holds the current global compiler policy information.
71 ;;; Whenever the policy is changed, we copy the structure so that old uses will
72 ;;; still get the old values. *DEFAULT-INTERFACE-COOKIE* holds any values
73 ;;; specified by an OPTIMIZE-INTERFACE declaration.
74 ;;;
75 ;;; FIXME: Why isn't COOKIE called POLICY?
76 (declaim (type cookie *default-cookie* *default-interface-cookie*))
77 (defvar *default-cookie*)          ; initialized in cold init
78 (defvar *default-interface-cookie*) ; initialized in cold init
79
80 ;;; possible values for the INLINE-ness of a function.
81 (deftype inlinep ()
82   '(member :inline :maybe-inline :notinline nil))
83 (defconstant inlinep-translations
84   '((inline . :inline)
85     (notinline . :notinline)
86     (maybe-inline . :maybe-inline)))
87
88 ;;; The lexical environment we are currently converting in.
89 (defvar *lexenv*)
90 (declaim (type lexenv *lexenv*))
91
92 ;;; *FREE-VARIABLES* translates from the names of variables referenced
93 ;;; globally to the LEAF structures for them. *FREE-FUNCTIONS* is like
94 ;;; *FREE-VARIABLES*, only it deals with function names.
95 (defvar *free-variables*)
96 (defvar *free-functions*)
97 (declaim (hash-table *free-variables* *free-functions*))
98
99 ;;; We use the same Constant structure to represent all equal anonymous
100 ;;; constants. This hashtable translates from constants to the Leafs that
101 ;;; represent them.
102 (defvar *constants*)
103 (declaim (hash-table *constants*))
104
105 ;;; miscellaneous forward declarations
106 (defvar *code-segment*)
107 #!+sb-dyncount (defvar *collect-dynamic-statistics*)
108 (defvar *component-being-compiled*)
109 (defvar *compiler-error-context*)
110 (defvar *compiler-error-count*)
111 (defvar *compiler-warning-count*)
112 (defvar *compiler-style-warning-count*)
113 (defvar *compiler-note-count*)
114 (defvar *converting-for-interpreter*)
115 (defvar *count-vop-usages*)
116 (defvar *current-path*)
117 (defvar *current-component*)
118 (defvar *default-cookie*)
119 (defvar *default-interface-cookie*)
120 (defvar *dynamic-counts-tn*)
121 (defvar *elsewhere*)
122 (defvar *event-info*)
123 (defvar *event-note-threshold*)
124 (defvar *failure-p*)
125 (defvar *fixups*)
126 (defvar *in-pack*)
127 (defvar *info-environment*)
128 (defvar *lexenv*)
129 (defvar *source-info*)
130 (defvar *trace-table*)
131 (defvar *undefined-warnings*)
132 (defvar *warnings-p*)
133 \f
134 ;;;; miscellaneous utilities
135
136 ;;; Delete any undefined warnings for NAME and KIND. This is for the
137 ;;; benefit of the compiler, but it's sometimes called from stuff like
138 ;;; type-defining code which isn't logically part of the compiler.
139 (declaim (ftype (function ((or symbol cons) keyword) (values))
140                 note-name-defined))
141 (defun note-name-defined (name kind)
142   ;; We do this BOUNDP check because this function can be called when
143   ;; not in a compilation unit (as when loading top-level forms).
144   (when (boundp '*undefined-warnings*)
145     (setq *undefined-warnings*
146           (delete-if (lambda (x)
147                        (and (equal (undefined-warning-name x) name)
148                             (eq (undefined-warning-kind x) kind)))
149                      *undefined-warnings*)))
150   (values))
151
152 ;;; to be called when a variable is lexically bound
153 (declaim (ftype (function (symbol) (values)) note-lexical-binding))
154 (defun note-lexical-binding (symbol)
155   (let ((name (symbol-name symbol)))
156     ;; This check is intended to protect us from getting silently burned when
157     ;; we define
158     ;;   foo.lisp:
159     ;;     (DEFVAR *FOO*)
160     ;;     (DEFUN FOO (X) (1+ X *FOO*))
161     ;;   bar.lisp:
162     ;;     (DEFUN BAR (X)
163     ;;       (LET ((*FOO* X))
164     ;;         (FOO 14)))
165     ;; and then we happen to compile bar.lisp before foo.lisp.
166     (when (and (char= #\* (aref name 0))
167                (char= #\* (aref name (1- (length name)))))
168       (style-warn "using the lexical binding of the symbol ~S, not the~@
169 dynamic binding, even though the symbol name follows the usual naming~@
170 convention (names like *FOO*) for special variables" symbol)))
171   (values))