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.
17 (export '(package-data
21 package-data-import-from
23 (defstruct package-data
24 ;; a string designator for the package name
25 (name (error "missing PACKAGE-DATA-NAME datum"))
27 (doc (error "missing PACKAGE-DOC datum"))
28 ;; a tree containing names for exported symbols which'll be set up at package
29 ;; creation time, and NILs, which are ignored. (This is a tree in order to
30 ;; allow constructs like '("ENOSPC" #!+LINUX ("EDQUOT" "EISNAM" "ENAVAIL"
31 ;; "EREMOTEIO")) to be used in initialization. NIL entries in the tree are
32 ;; ignored for the same reason of notational convenience.)
34 ;; a list of string designators for exported symbols which don't necessarily
35 ;; originate in this package (so their EXPORT operations should be handled
36 ;; after USE operations have been done, so that duplicates aren't created)
38 ;; a list of sublists describing imports. Each sublist has the format as an
39 ;; IMPORT-FROM list in DEFPACKAGE: the first element is the name of the
40 ;; package to import from, and the remaining elements are the names of
43 ;; a tree of string designators for package names of other packages
44 ;; which this package uses
47 (let ((package-data-list (read-from-file "package-data-list.lisp-expr")))
49 ;; Build all packages that we need, and initialize them as far as we
50 ;; can without referring to any other packages.
51 (dolist (package-data package-data-list)
52 (let* ((package (make-package
53 (package-data-name package-data)
54 ;; Note: As of 0.7.0, the only nicknames we use
55 ;; for our implementation packages are hacks
56 ;; not needed at cross-compile time (e.g. the
57 ;; deprecated SB-C-CALL nickname for SB-ALIEN).
58 ;; So support for nicknaming during xc is gone,
59 ;; since any nicknames are hacked in during
63 #-clisp ; As of "2.27 (released 2001-07-17) (built 3215971334)"
64 ; CLISP didn't support DOCUMENTATION on PACKAGE values.
66 #!+sb-doc (setf (documentation package t)
67 (package-data-doc package-data)))
68 ;; Walk the tree of exported names, exporting each name.
69 (labels ((recurse (tree)
71 ;; FIXME: The comments above say the structure is a tree,
72 ;; but here we're sleazily treating it as though
73 ;; dotted lists never occur. Replace this LIST case
74 ;; with separate NULL and CONS cases to fix this.
75 (list (mapc #'recurse tree))
76 (string (export (intern tree package) package)))))
77 (recurse (package-data-export package-data)))))
79 ;; Now that all packages exist, we can set up package-package
81 (dolist (package-data package-data-list)
82 (use-package (package-data-use package-data)
83 (package-data-name package-data))
84 (dolist (sublist (package-data-import-from package-data))
85 (let* ((from-package (first sublist))
86 (symbol-names (rest sublist))
87 (symbols (mapcar (lambda (name)
88 ;; old way, broke for importing symbols
89 ;; like SB!C::DEBUG-SOURCE-FORM into
90 ;; SB!DI -- WHN 19990714
92 (let ((s (find-symbol name from-package)))
94 (error "can't find ~S in ~S"
98 ;; new way, works for SB!DI stuff
100 (intern name from-package))
102 (import symbols (package-data-name package-data)))))
104 ;; Now that all package-package references exist, we can handle
105 ;; REEXPORT operations. (We have to wait until now because they
106 ;; interact with USE operations.) KLUDGE: This code doesn't detect
107 ;; dependencies and do exports in proper order to work around them, so
108 ;; it could break randomly (with build-time errors, not with silent
109 ;; errors or runtime errors) if multiple levels of re-exportation are
110 ;; used, e.g. package A exports X, package B uses A and reexports X,
111 ;; and package C uses B and reexports X. That doesn't seem to be an
112 ;; issue in the current code, and it's hard to see why anyone would
113 ;; want to do it, and it should be straightforward (though tedious) to
114 ;; extend the code here to deal with that if it ever becomes necessary.
115 (dolist (package-data package-data-list)
116 (let ((package (find-package (package-data-name package-data))))
117 (dolist (symbol-name (package-data-reexport package-data))
118 (multiple-value-bind (symbol status)
119 (find-symbol symbol-name package)
121 (error "No symbol named ~S is accessible in ~S."
124 (when (eq (symbol-package symbol) package)
125 (error "~S is not inherited/imported, but native to ~S."
128 (export symbol package))))))