0.6.9.17:
[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-eqx sb!xc:lambda-list-keywords
20   '(&optional &rest &key &aux &body &whole &allow-other-keys &environment)
21   #!+sb-doc
22   #'equal
23   "symbols which are magical in a lambda list")
24 \f
25 ;;;; cross-compiler-only versions of CL special variables, so that we
26 ;;;; don't have weird interactions with the host compiler
27
28 (defvar sb!xc:*compile-file-pathname*)
29 (defvar sb!xc:*compile-file-truename*)
30 (defvar sb!xc:*compile-print*)
31 (defvar sb!xc:*compile-verbose*)
32 \f
33 ;;;; miscellaneous types used both in the cross-compiler and on the target
34
35 ;;;; FIXME: The INDEX and LAYOUT-DEPTHOID definitions probably belong
36 ;;;; somewhere else, not "early-c", since they're after all not part
37 ;;;; of the compiler.
38
39 ;;; the type of LAYOUT-DEPTHOID slot values
40 (def!type sb!kernel::layout-depthoid () '(or index (integer -1 -1)))
41 \f
42 ;;; possible values for the INLINE-ness of a function.
43 (deftype inlinep ()
44   '(member :inline :maybe-inline :notinline nil))
45 (defparameter *inlinep-translations*
46   '((inline . :inline)
47     (notinline . :notinline)
48     (maybe-inline . :maybe-inline)))
49
50 ;;; the lexical environment we are currently converting in
51 (defvar *lexenv*)
52 (declaim (type lexenv *lexenv*))
53
54 ;;; *FREE-VARIABLES* translates from the names of variables referenced
55 ;;; globally to the LEAF structures for them. *FREE-FUNCTIONS* is like
56 ;;; *FREE-VARIABLES*, only it deals with function names.
57 (defvar *free-variables*)
58 (defvar *free-functions*)
59 (declaim (hash-table *free-variables* *free-functions*))
60
61 ;;; We use the same Constant structure to represent all equal anonymous
62 ;;; constants. This hashtable translates from constants to the Leafs that
63 ;;; represent them.
64 (defvar *constants*)
65 (declaim (hash-table *constants*))
66
67 ;;; miscellaneous forward declarations
68 (defvar *code-segment*)
69 #!+sb-dyncount (defvar *collect-dynamic-statistics*)
70 (defvar *component-being-compiled*)
71 (defvar *compiler-error-context*)
72 (defvar *compiler-error-count*)
73 (defvar *compiler-warning-count*)
74 (defvar *compiler-style-warning-count*)
75 (defvar *compiler-note-count*)
76 (defvar *converting-for-interpreter*)
77 (defvar *count-vop-usages*)
78 (defvar *current-path*)
79 (defvar *current-component*)
80 (defvar *policy*)
81 (defvar *interface-policy*)
82 (defvar *dynamic-counts-tn*)
83 (defvar *elsewhere*)
84 (defvar *event-info*)
85 (defvar *event-note-threshold*)
86 (defvar *failure-p*)
87 (defvar *fixups*)
88 (defvar *in-pack*)
89 (defvar *info-environment*)
90 (defvar *lexenv*)
91 (defvar *source-info*)
92 (defvar *trace-table*)
93 (defvar *undefined-warnings*)
94 (defvar *warnings-p*)
95 \f
96 ;;;; miscellaneous utilities
97
98 ;;; Delete any undefined warnings for NAME and KIND. This is for the
99 ;;; benefit of the compiler, but it's sometimes called from stuff like
100 ;;; type-defining code which isn't logically part of the compiler.
101 (declaim (ftype (function ((or symbol cons) keyword) (values))
102                 note-name-defined))
103 (defun note-name-defined (name kind)
104   ;; We do this BOUNDP check because this function can be called when
105   ;; not in a compilation unit (as when loading top-level forms).
106   (when (boundp '*undefined-warnings*)
107     (setq *undefined-warnings*
108           (delete-if (lambda (x)
109                        (and (equal (undefined-warning-name x) name)
110                             (eq (undefined-warning-kind x) kind)))
111                      *undefined-warnings*)))
112   (values))
113
114 ;;; to be called when a variable is lexically bound
115 (declaim (ftype (function (symbol) (values)) note-lexical-binding))
116 (defun note-lexical-binding (symbol)
117   (let ((name (symbol-name symbol)))
118     ;; This check is intended to protect us from getting silently
119     ;; burned when we define
120     ;;   foo.lisp:
121     ;;     (DEFVAR *FOO* -3)
122     ;;     (DEFUN FOO (X) (+ X *FOO*))
123     ;;   bar.lisp:
124     ;;     (DEFUN BAR (X)
125     ;;       (LET ((*FOO* X))
126     ;;         (FOO 14)))
127     ;; and then we happen to compile bar.lisp before foo.lisp.
128     (when (and (char= #\* (aref name 0))
129                (char= #\* (aref name (1- (length name)))))
130       ;; FIXME: should be COMPILER-STYLE-WARNING?
131       (style-warn "using the lexical binding of the symbol ~S, not the~@
132 dynamic binding, even though the symbol name follows the usual naming~@
133 convention (names like *FOO*) for special variables" symbol)))
134   (values))