tests: Depend on sb-thread feature in x86-64-codegen.impure.lisp
[sbcl.git] / src / cold / set-up-cold-packages.lisp
blob32a0868e7b4a2f536ebf7054a7e173ad6e19a1cb
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
4 ;;;; This software is derived from the CMU CL system, which was
5 ;;;; written at Carnegie Mellon University and released into the
6 ;;;; public domain. The software is in the public domain and is
7 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
8 ;;;; files for more information.
10 (in-package "SB-COLD")
12 ;;; an entry in the table which describes the non-standard part (i.e. not
13 ;;; CL/CL-USER/KEYWORD) of the package structure of the SBCL system
14 ;;;
15 ;;; We make no attempt to be fully general; our table doesn't need to be
16 ;;; able to express features which we don't happen to use.
17 (export '(genesis
18 package-data
19 make-package-data
20 package-data-name
21 package-data-export
22 package-data-reexport
23 package-data-import-from
24 package-data-use))
25 (defstruct package-data
26 ;; a string designator for the package name
27 (name (error "missing PACKAGE-DATA-NAME datum"))
28 ;; a doc string
29 (doc (error "missing PACKAGE-DOC datum"))
30 ;; a tree containing names for exported symbols which'll be set up at package
31 ;; creation time, and NILs, which are ignored. (This is a tree in order to
32 ;; allow constructs like '("ENOSPC" #!+LINUX ("EDQUOT" "EISNAM" "ENAVAIL"
33 ;; "EREMOTEIO")) to be used in initialization. NIL entries in the tree are
34 ;; ignored for the same reason of notational convenience.)
35 export
36 ;; a list of string designators for exported symbols which don't necessarily
37 ;; originate in this package (so their EXPORT operations should be handled
38 ;; after USE operations have been done, so that duplicates aren't created)
39 reexport
40 ;; a list of sublists describing imports. Each sublist has the format as an
41 ;; IMPORT-FROM list in DEFPACKAGE: the first element is the name of the
42 ;; package to import from, and the remaining elements are the names of
43 ;; symbols to import.
44 import-from
45 ;; a tree of string designators for package names of other packages
46 ;; which this package uses
47 use)
49 ;; The running-in-the-host-Lisp Python cross-compiler defines its
50 ;; own versions of a number of functions which should not overwrite
51 ;; host-Lisp functions. Instead we put them in a special package.
53 ;; The common theme of the functions, macros, constants, and so
54 ;; forth in this package is that they run in the host and affect the
55 ;; compilation of the target.
56 (let ((package-name "SB-XC"))
57 (make-package package-name :use nil :nicknames nil)
58 (dolist (name '(;; the constants (except for T and NIL which have
59 ;; a specially hacked correspondence between
60 ;; cross-compilation host Lisp and target Lisp)
61 "ARRAY-DIMENSION-LIMIT"
62 "ARRAY-RANK-LIMIT"
63 "ARRAY-TOTAL-SIZE-LIMIT"
64 "BOOLE-1"
65 "BOOLE-2"
66 "BOOLE-AND"
67 "BOOLE-ANDC1"
68 "BOOLE-ANDC2"
69 "BOOLE-C1"
70 "BOOLE-C2"
71 "BOOLE-CLR"
72 "BOOLE-EQV"
73 "BOOLE-IOR"
74 "BOOLE-NAND"
75 "BOOLE-NOR"
76 "BOOLE-ORC1"
77 "BOOLE-ORC2"
78 "BOOLE-SET"
79 "BOOLE-XOR"
80 "CALL-ARGUMENTS-LIMIT"
81 "CHAR-CODE-LIMIT"
82 "DOUBLE-FLOAT-EPSILON"
83 "DOUBLE-FLOAT-NEGATIVE-EPSILON"
84 "INTERNAL-TIME-UNITS-PER-SECOND"
85 "LAMBDA-LIST-KEYWORDS"
86 "LAMBDA-PARAMETERS-LIMIT"
87 "LEAST-NEGATIVE-DOUBLE-FLOAT"
88 "LEAST-NEGATIVE-LONG-FLOAT"
89 "LEAST-NEGATIVE-NORMALIZED-DOUBLE-FLOAT"
90 "LEAST-NEGATIVE-NORMALIZED-LONG-FLOAT"
91 "LEAST-NEGATIVE-NORMALIZED-SHORT-FLOAT"
92 "LEAST-NEGATIVE-NORMALIZED-SINGLE-FLOAT"
93 "LEAST-NEGATIVE-SHORT-FLOAT"
94 "LEAST-NEGATIVE-SINGLE-FLOAT"
95 "LEAST-POSITIVE-DOUBLE-FLOAT"
96 "LEAST-POSITIVE-LONG-FLOAT"
97 "LEAST-POSITIVE-NORMALIZED-DOUBLE-FLOAT"
98 "LEAST-POSITIVE-NORMALIZED-LONG-FLOAT"
99 "LEAST-POSITIVE-NORMALIZED-SHORT-FLOAT"
100 "LEAST-POSITIVE-NORMALIZED-SINGLE-FLOAT"
101 "LEAST-POSITIVE-SHORT-FLOAT"
102 "LEAST-POSITIVE-SINGLE-FLOAT"
103 "LONG-FLOAT-EPSILON"
104 "LONG-FLOAT-NEGATIVE-EPSILON"
105 "MOST-NEGATIVE-DOUBLE-FLOAT"
106 "MOST-NEGATIVE-FIXNUM"
107 "MOST-NEGATIVE-LONG-FLOAT"
108 "MOST-NEGATIVE-SHORT-FLOAT"
109 "MOST-NEGATIVE-SINGLE-FLOAT"
110 "MOST-POSITIVE-DOUBLE-FLOAT"
111 "MOST-POSITIVE-FIXNUM"
112 "MOST-POSITIVE-LONG-FLOAT"
113 "MOST-POSITIVE-SHORT-FLOAT"
114 "MOST-POSITIVE-SINGLE-FLOAT"
115 "MULTIPLE-VALUES-LIMIT"
116 "PI"
117 "SHORT-FLOAT-EPSILON"
118 "SHORT-FLOAT-NEGATIVE-EPSILON"
119 "SINGLE-FLOAT-EPSILON"
120 "SINGLE-FLOAT-NEGATIVE-EPSILON"
122 ;; everything else which needs a separate
123 ;; existence in xc and target
124 "BYTE" "BYTE-POSITION" "BYTE-SIZE"
125 "CHAR-CODE"
126 "CODE-CHAR"
127 "COMPILE-FILE"
128 "COMPILE-FILE-PATHNAME"
129 "*COMPILE-FILE-PATHNAME*"
130 "*COMPILE-FILE-TRUENAME*"
131 "*COMPILE-PRINT*"
132 "*COMPILE-VERBOSE*"
133 "COMPILER-MACRO-FUNCTION"
134 "CONSTANTP"
135 "DEFCONSTANT"
136 "DEFINE-MODIFY-MACRO"
137 "DEFINE-SETF-EXPANDER"
138 "DEFMACRO" "DEFSETF" "DEFSTRUCT" "DEFTYPE"
139 "DEPOSIT-FIELD" "DPB"
140 "GENSYM" "*GENSYM-COUNTER*"
141 "GET-SETF-EXPANSION"
142 "LDB" "LDB-TEST"
143 "LISP-IMPLEMENTATION-TYPE" "LISP-IMPLEMENTATION-VERSION"
144 "MACRO-FUNCTION"
145 "MACROEXPAND" "MACROEXPAND-1" "*MACROEXPAND-HOOK*"
146 "MAKE-LOAD-FORM"
147 "MAKE-LOAD-FORM-SAVING-SLOTS"
148 "MASK-FIELD"
149 "PROCLAIM"
150 "SPECIAL-OPERATOR-P"
151 "SUBTYPEP"
152 "TYPE-OF" "TYPEP"
153 "UPGRADED-ARRAY-ELEMENT-TYPE"
154 "UPGRADED-COMPLEX-PART-TYPE"
155 "WITH-COMPILATION-UNIT"))
156 (export (intern name package-name) package-name)))
158 ;; Symbols that we want never to accidentally see the host's definition of.
159 (defparameter *shadowing-imports*
160 (mapcar (lambda (name) (find-symbol name "SB-XC"))
161 '("BYTE" "BYTE-POSITION" "BYTE-SIZE"
162 "DPB" "LDB" "LDB-TEST"
163 "DEPOSIT-FIELD" "MASK-FIELD")))
165 (let ((package-data-list (read-from-file "package-data-list.lisp-expr")))
166 (labels ((flatten (tree)
167 (mapcan (lambda (x) (if (listp x) (flatten x) (list x)))
168 tree)))
170 ;; Build all packages that we need, and initialize them as far as we
171 ;; can without referring to any other packages.
172 (dolist (package-data package-data-list)
173 (let* ((package (make-package
174 (package-data-name package-data)
175 ;; Note: As of 0.7.0, the only nicknames we use
176 ;; for our implementation packages are hacks
177 ;; not needed at cross-compile time (e.g. the
178 ;; deprecated SB-C-CALL nickname for SB-ALIEN).
179 ;; So support for nicknaming during xc is gone,
180 ;; since any nicknames are hacked in during
181 ;; cold init.
182 :nicknames nil
183 :use nil)))
184 (shadowing-import *shadowing-imports* package)
185 ;; Walk the tree of exported names, exporting each name.
186 (dolist (string (flatten (package-data-export package-data)))
187 (export (intern string package) package))))
189 ;; Now that all packages exist, we can set up package-package
190 ;; references.
191 (dolist (package-data package-data-list)
192 (use-package (package-data-use package-data)
193 (package-data-name package-data))
194 (dolist (sublist (package-data-import-from package-data))
195 (let* ((from-package (first sublist))
196 (symbol-names (rest sublist))
197 (symbols (mapcar (lambda (name)
198 ;; old way, broke for importing symbols
199 ;; like SB!C::DEBUG-SOURCE-FORM into
200 ;; SB!DI -- WHN 19990714
201 #+nil
202 (let ((s (find-symbol name from-package)))
203 (unless s
204 (error "can't find ~S in ~S"
205 name
206 from-package))
208 ;; new way, works for SB!DI stuff
209 ;; -- WHN 19990714
210 (intern name from-package))
211 (flatten symbol-names))))
212 (import symbols (package-data-name package-data)))))
214 ;; Now that all package-package references exist, we can handle
215 ;; REEXPORT operations. (We have to wait until now because they
216 ;; interact with USE operations.) This code handles dependencies
217 ;; properly, but is somewhat ugly.
218 (let (done)
219 (labels
220 ((reexport (package-data)
221 (let ((package (find-package (package-data-name package-data))))
222 (cond
223 ((member package done))
224 ((null (package-data-reexport package-data))
225 (push package done))
227 (mapcar #'reexport
228 (remove-if-not
229 (lambda (x)
230 (member x (package-data-use package-data)
231 :test #'string=))
232 package-data-list
233 :key #'package-data-name))
234 (dolist (symbol-name
235 (flatten (package-data-reexport package-data)))
236 (multiple-value-bind (symbol status)
237 (find-symbol symbol-name package)
238 (unless status
239 (error "No symbol named ~S is accessible in ~S."
240 symbol-name package))
241 (when (eq (symbol-package symbol) package)
242 (error
243 "~S is not inherited/imported, but native to ~S."
244 symbol-name package))
245 (export symbol package)))
246 (push package done))))))
247 (dolist (x package-data-list)
248 (reexport x))
249 (assert (= (length done) (length package-data-list)))))))
251 (defun make-assembler-package (pkg-name)
252 (when (find-package pkg-name)
253 (delete-package pkg-name))
254 (let ((pkg (make-package pkg-name
255 :use '("CL" "SB!INT" "SB!EXT" "SB!KERNEL" "SB!VM"
256 "SB!SYS" ; for SAP accessors
257 ;; Dependence of the assembler on the compiler
258 ;; feels a bit backwards, but assembly needs
259 ;; TN-SC, TN-OFFSET, etc. because the compiler
260 ;; doesn't speak the assembler's language.
261 ;; Rather vice-versa.
262 "SB!C"))))
263 (shadowing-import *shadowing-imports* pkg)
264 ;; Both SB-ASSEM and SB-DISASSEM export these two symbols.
265 ;; Neither is shadowing-imported. If you need one, package-qualify it.
266 (shadow '("SEGMENT" "MAKE-SEGMENT") pkg)
267 (use-package '("SB!ASSEM" "SB!DISASSEM") pkg)
268 pkg))
270 ;; Each backend should have a different package for its instruction set
271 ;; so that they can co-exist.
272 (make-assembler-package (backend-asm-package-name))
274 (defun package-list-for-genesis ()
275 (append (read-from-file "package-data-list.lisp-expr")
276 (let ((asm-package (backend-asm-package-name)))
277 (list (make-package-data
278 :name asm-package
279 :use (mapcar 'package-name
280 (package-use-list asm-package))
281 :doc nil)))))