0.6.12.37;
[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 (type 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 (type 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 *compiler-trace-output*)
77 (defvar *constraint-number*)
78 (defvar *converting-for-interpreter*)
79 (defvar *count-vop-usages*)
80 (defvar *current-path*)
81 (defvar *current-component*)
82 (defvar *delayed-ir1-transforms*)
83 (defvar *policy*)
84 (defvar *dynamic-counts-tn*)
85 (defvar *elsewhere*)
86 (defvar *event-info*)
87 (defvar *event-note-threshold*)
88 (defvar *failure-p*)
89 (defvar *fixups*)
90 (defvar *in-pack*)
91 (defvar *info-environment*)
92 (defvar *lexenv*)
93 (defvar *source-info*)
94 (defvar *trace-table*)
95 (defvar *undefined-warnings*)
96 (defvar *warnings-p*)
97 \f
98 ;;;; miscellaneous utilities
99
100 ;;; Delete any undefined warnings for NAME and KIND. This is for the
101 ;;; benefit of the compiler, but it's sometimes called from stuff like
102 ;;; type-defining code which isn't logically part of the compiler.
103 (declaim (ftype (function ((or symbol cons) keyword) (values))
104                 note-name-defined))
105 (defun note-name-defined (name kind)
106   ;; We do this BOUNDP check because this function can be called when
107   ;; not in a compilation unit (as when loading top-level forms).
108   (when (boundp '*undefined-warnings*)
109     (setq *undefined-warnings*
110           (delete-if (lambda (x)
111                        (and (equal (undefined-warning-name x) name)
112                             (eq (undefined-warning-kind x) kind)))
113                      *undefined-warnings*)))
114   (values))
115
116 ;;; to be called when a variable is lexically bound
117 (declaim (ftype (function (symbol) (values)) note-lexical-binding))
118 (defun note-lexical-binding (symbol)
119   (let ((name (symbol-name symbol)))
120     ;; This check is intended to protect us from getting silently
121     ;; burned when we define
122     ;;   foo.lisp:
123     ;;     (DEFVAR *FOO* -3)
124     ;;     (DEFUN FOO (X) (+ X *FOO*))
125     ;;   bar.lisp:
126     ;;     (DEFUN BAR (X)
127     ;;       (LET ((*FOO* X))
128     ;;         (FOO 14)))
129     ;; and then we happen to compile bar.lisp before foo.lisp.
130     (when (and (char= #\* (aref name 0))
131                (char= #\* (aref name (1- (length name)))))
132       ;; FIXME: should be COMPILER-STYLE-WARNING?
133       (style-warn "using the lexical binding of the symbol ~S, not the~@
134 dynamic binding, even though the symbol name follows the usual naming~@
135 convention (names like *FOO*) for special variables" symbol)))
136   (values))