1 ;;;; This software is part of the SBCL system. See the README file for
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
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.
23 package-data-import-from
25 (defstruct package-data
26 ;; a string designator for the package name
27 (name (error "missing PACKAGE-DATA-NAME datum"))
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.)
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)
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
45 ;; a tree of string designators for package names of other packages
46 ;; which this package uses
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"
63 "ARRAY-TOTAL-SIZE-LIMIT"
80 "CALL-ARGUMENTS-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"
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"
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"
128 "COMPILE-FILE-PATHNAME"
129 "*COMPILE-FILE-PATHNAME*"
130 "*COMPILE-FILE-TRUENAME*"
133 "COMPILER-MACRO-FUNCTION"
136 "DEFINE-MODIFY-MACRO"
137 "DEFINE-SETF-EXPANDER"
138 "DEFMACRO" "DEFSETF" "DEFSTRUCT" "DEFTYPE"
139 "DEPOSIT-FIELD" "DPB"
140 "GENSYM" "*GENSYM-COUNTER*"
143 "LISP-IMPLEMENTATION-TYPE" "LISP-IMPLEMENTATION-VERSION"
145 "MACROEXPAND" "MACROEXPAND-1" "*MACROEXPAND-HOOK*"
147 "MAKE-LOAD-FORM-SAVING-SLOTS"
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
)))
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
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
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
202 (let ((s (find-symbol name from-package
)))
204 (error "can't find ~S in ~S"
208 ;; new way, works for SB!DI stuff
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.
220 ((reexport (package-data)
221 (let ((package (find-package (package-data-name package-data
))))
223 ((member package done
))
224 ((null (package-data-reexport package-data
))
230 (member x
(package-data-use package-data
)
233 :key
#'package-data-name
))
235 (flatten (package-data-reexport package-data
)))
236 (multiple-value-bind (symbol status
)
237 (find-symbol symbol-name package
)
239 (error "No symbol named ~S is accessible in ~S."
240 symbol-name package
))
241 (when (eq (symbol-package symbol
) package
)
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
)
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.
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
)
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
279 :use
(mapcar 'package-name
280 (package-use-list asm-package
))