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