1 ;;;; code to tweak compilation environment, used to set up
2 ;;;; for different phases of cross-compilation
4 ;;;; This software is part of the SBCL system. See the README file for
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
13 (in-package "SB-COLD")
15 ;;; a helper macro for WITH-ADDITIONAL-NICKNAME and WITHOUT-SOME-NICKNAME
16 (defmacro with-given-nicknames ((package-designator nicknames) &body body)
17 (let ((p (gensym "P"))
20 `(let* ((,p ,package-designator) ; PACKAGE-DESIGNATOR, evaluated only once
21 (,n ,nicknames) ; NICKNAMES, evaluated only once
22 (,o (package-nicknames ,p))) ; old package nicknames
23 (rename-package-carefully ,p (package-name ,p) ,n)
26 (unless (nicknames= ,n (package-nicknames ,p))
27 ;; This probably didn't happen on purpose, and it's not clear anyway
28 ;; what we should do when it did happen, so die noisily:
29 (error "package nicknames changed within WITH-GIVEN-NICKNAMES: ~
30 expected ~S, found ~S"
32 (package-nicknames ,p)))
33 (rename-package-carefully ,p (package-name ,p) ,o)))))
35 ;;; Execute BODY with NICKNAME added as a nickname for PACKAGE-DESIGNATOR.
36 (defmacro with-additional-nickname ((package-designator nickname) &body body)
37 (let ((p (gensym "P"))
39 `(let* ((,p ,package-designator) ; PACKAGE-DESIGNATOR, evaluated only once
40 (,n ,nickname)) ; NICKNAME, evaluated only once
42 (error "~S is already a package name." ,n)
43 (with-given-nicknames (,p (cons ,n (package-nicknames ,p)))
46 ;;; Execute BODY with NICKNAME removed as a nickname for PACKAGE-DESIGNATOR.
47 (defmacro without-given-nickname ((package-designator nickname) &body body)
48 (let ((p (gensym "P"))
51 `(let* ((,p ,package-designator) ; PACKAGE-DESIGNATOR, evaluated only once
52 (,n ,nickname) ; NICKNAME, evaluated only once
53 (,o (package-nicknames ,p))) ; old package nicknames
54 (if (find ,n ,o :test #'string=)
55 (with-given-nicknames (,p (remove ,n ,o :test #'string=))
57 (error "~S is not a nickname for ~S." ,n ,p)))))
59 ;;; a helper function for WITH-NICKNAME: Are two collections of package
60 ;;; nicknames the same?
61 (defun nicknames= (x y)
62 (equal (sort (mapcar #'string x) #'string<)
63 (sort (mapcar #'string y) #'string<)))
66 ;;; helper functions for WITH-ADDITIONAL-NICKNAMES and WITHOUT-GIVEN-NICKNAMES
67 (defun %with-additional-nickname (package-designator nickname body-fn)
68 (with-additional-nickname (package-designator nickname)
70 (defun %without-given-nickname (package-designator nickname body-fn)
71 (without-given-nickname (package-designator nickname)
73 (defun %multi-nickname-magic (nd-list single-nn-fn body-fn)
74 (labels ((multi-nd (nd-list body-fn) ; multiple nickname descriptors
77 (single-nd (first nd-list)
79 (multi-nd (rest nd-list) body-fn)))))
80 (single-nd (nd body-fn) ; single nickname descriptor
81 (destructuring-bind (package-descriptor nickname-list) nd
82 (multi-nn package-descriptor nickname-list body-fn)))
83 (multi-nn (nn-list package-descriptor body-fn) ; multiple nicknames
90 (multi-nn package-descriptor
93 (multi-nd nd-list body-fn)))
94 (compile '%with-additional-nickname)
95 (compile '%without-given-nickname)
96 (compile '%multi-nickname-magic)
98 ;;; This is like WITH-ADDITIONAL-NICKNAME and WITHOUT-GIVEN-NICKNAMES,
99 ;;; except working on arbitrary lists of nickname descriptors instead
100 ;;; of single nickname/package pairs.
102 ;;; A nickname descriptor is a list of the form
103 ;;; PACKAGE-DESIGNATOR NICKNAME*
104 (defmacro with-additional-nicknames (nickname-descriptor-list &body body)
105 `(%multi-nickname-magic ,nickname-descriptor-list
106 #'%with-additional-nickname
108 (defmacro without-given-nicknames (nickname-descriptor-list &body body)
109 `(%multi-nickname-magic ,nickname-descriptor-list
110 #'%without-additional-nickname