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