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.
7 ;;;; This software is part of the SBCL system. See the README file for
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.
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)
22 "symbols which are magical in a lambda list")
24 ;;;; cross-compiler-only versions of CL special variables, so that we
25 ;;;; don't have weird interactions with the host compiler
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*)
32 ;;;; miscellaneous types used both in the cross-compiler and on the target
34 ;;;; FIXME: The INDEX and LAYOUT-DEPTHOID definitions probably belong
35 ;;;; somewhere else, not "early-c", since they're after all not part
38 ;;; the type of LAYOUT-DEPTHOID slot values
39 (def!type sb!kernel::layout-depthoid () '(or index (integer -1 -1)))
41 ;;; a value for an optimization declaration
42 (def!type sb!c::cookie-quality () '(or (rational 0 3) null))
44 ;;; A COOKIE holds information about the compilation environment for a
45 ;;; node. See the LEXENV definition for a description of how it is
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))
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)))
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.
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
80 ;;; possible values for the INLINE-ness of a function.
82 '(member :inline :maybe-inline :notinline nil))
83 (defconstant inlinep-translations
85 (notinline . :notinline)
86 (maybe-inline . :maybe-inline)))
88 ;;; The lexical environment we are currently converting in.
90 (declaim (type lexenv *lexenv*))
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*))
99 ;;; We use the same Constant structure to represent all equal anonymous
100 ;;; constants. This hashtable translates from constants to the Leafs that
103 (declaim (hash-table *constants*))
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*)
122 (defvar *event-info*)
123 (defvar *event-note-threshold*)
127 (defvar *info-environment*)
129 (defvar *source-info*)
130 (defvar *trace-table*)
131 (defvar *undefined-warnings*)
132 (defvar *warnings-p*)
134 ;;;; miscellaneous utilities
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))
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*)))
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
160 ;; (DEFUN FOO (X) (1+ X *FOO*))
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)))