Raymond Toy pushed to branch master at cmucl / cmucl
Commits:
-
aeab122e
by Raymond Toy at 2025-06-30T07:18:34-07:00
-
32b15538
by Raymond Toy at 2025-06-30T07:18:34-07:00
7 changed files:
- bin/run-unit-tests.sh
- src/bootfiles/21e/boot-2024-08.lisp
- src/code/exports.lisp
- src/code/package.lisp
- src/code/print.lisp
- src/contrib/asdf/asdf.lisp
- src/i18n/locale/cmucl.pot
Changes:
| ... | ... | @@ -76,3 +76,24 @@ else |
| 76 | 76 | $LISP -nositeinit -noinit -load "$TESTDIR"/run-tests.lisp -eval "(progn (cmucl-test-runner:load-test-files) (cmucl-test-runner:run-test $result))"
|
| 77 | 77 | fi
|
| 78 | 78 | |
| 79 | +## Now run tests for trivial-package-local-nicknames
|
|
| 80 | +REPO=trivial-package-local-nicknames-mirror
|
|
| 81 | +BRANCH=cmucl-updates
|
|
| 82 | + |
|
| 83 | +set -x
|
|
| 84 | +if [ -d ../$REPO ]; then
|
|
| 85 | + (cd ../$REPO || exit 1; git stash; git checkout $BRANCH; git pull --rebase)
|
|
| 86 | +else
|
|
| 87 | + (cd ..; git clone https://gitlab.common-lisp.net/cmucl/trivial-package-local-nicknames-mirror.git)
|
|
| 88 | +fi
|
|
| 89 | + |
|
| 90 | +LISP=$PWD/$LISP
|
|
| 91 | +cd ../$REPO || exit 1
|
|
| 92 | +git checkout $BRANCH
|
|
| 93 | + |
|
| 94 | +# Run the tests. Exits with a non-zero code if there's a failure.
|
|
| 95 | +$LISP -noinit -nositeinit -batch <<'EOF'
|
|
| 96 | +(require :asdf)
|
|
| 97 | +(push (default-directory) asdf:*central-registry*)
|
|
| 98 | +(asdf:test-system :trivial-package-local-nicknames)
|
|
| 99 | +EOF |
| ... | ... | @@ -8,3 +8,125 @@ |
| 8 | 8 | (declare (ignore c))
|
| 9 | 9 | (invoke-restart 'continue))))
|
| 10 | 10 | (defconstant +ef-max+ 14))
|
| 11 | + |
|
| 12 | +;;; Bootstrap for adding %local-nicknames to package structure.
|
|
| 13 | +(in-package :lisp)
|
|
| 14 | + |
|
| 15 | +(intern "PACKAGE-LOCAL-NICKNAMES" "LISP")
|
|
| 16 | +(intern "ADD-PACKAGE-LOCAL-NICKNAME" "LISP")
|
|
| 17 | +(intern "REMOVE-PACKAGE-LOCAL-NICKNAME" "LISP")
|
|
| 18 | +(intern "PACKAGE-LOCALLY-NICKNAMED-BY-LIST" "LISP")
|
|
| 19 | + |
|
| 20 | +;; Make sure we don't accidentally load fasls from somewhere.
|
|
| 21 | +(setf (ext:search-list "target:")
|
|
| 22 | + '("src/"))
|
|
| 23 | + |
|
| 24 | +;; Ensure all packages have been set up, since package definition is broken
|
|
| 25 | +;; once this file has been loaded:
|
|
| 26 | +(load "target:code/exports-errno" :if-does-not-exist nil)
|
|
| 27 | +(load "target:code/exports")
|
|
| 28 | + |
|
| 29 | +(setf *enable-package-locked-errors* nil)
|
|
| 30 | + |
|
| 31 | +;;;
|
|
| 32 | +;;; Like DEFSTRUCT, but silently clobber old definitions.
|
|
| 33 | +;;;
|
|
| 34 | +(defmacro defstruct! (name &rest stuff)
|
|
| 35 | + `(handler-bind ((error (lambda (c)
|
|
| 36 | + (declare (ignore c))
|
|
| 37 | + (invoke-restart 'kernel::clobber-it))))
|
|
| 38 | + (defstruct ,name ,@stuff)))
|
|
| 39 | + |
|
| 40 | + |
|
| 41 | +(defstruct! (package
|
|
| 42 | + (:constructor internal-make-package)
|
|
| 43 | + (:predicate packagep)
|
|
| 44 | + (:print-function %print-package)
|
|
| 45 | + (:make-load-form-fun
|
|
| 46 | + (lambda (package)
|
|
| 47 | + (values `(package-or-lose ',(package-name package))
|
|
| 48 | + nil))))
|
|
| 49 | + (tables (list nil)) ; A list of all the hashtables for inherited symbols.
|
|
| 50 | + (%name nil :type (or simple-string null))
|
|
| 51 | + (%nicknames () :type list)
|
|
| 52 | + (%use-list () :type list)
|
|
| 53 | + (%used-by-list () :type list)
|
|
| 54 | + (internal-symbols (required-argument) :type package-hashtable)
|
|
| 55 | + (external-symbols (required-argument) :type package-hashtable)
|
|
| 56 | + (%shadowing-symbols () :type list)
|
|
| 57 | + (lock nil :type boolean)
|
|
| 58 | + (definition-lock nil :type boolean)
|
|
| 59 | + (%local-nicknames () :type list)
|
|
| 60 | + (doc-string nil :type (or simple-string null)))
|
|
| 61 | + |
|
| 62 | +;; Need to define this with the extra arg because compiling pcl uses
|
|
| 63 | +;; defpackage and we need this defined. This isn't the actual
|
|
| 64 | +;; implementation; we just added the extra arg.
|
|
| 65 | +(defun %defpackage (name nicknames size shadows shadowing-imports
|
|
| 66 | + use imports interns exports doc-string &optional local-nicknames)
|
|
| 67 | + (declare (type simple-base-string name)
|
|
| 68 | + (type list nicknames local-nicknames shadows shadowing-imports
|
|
| 69 | + imports interns exports)
|
|
| 70 | + (type (or list (member :default)) use)
|
|
| 71 | + (type (or simple-base-string null) doc-string))
|
|
| 72 | + (let ((package (or (find-package name)
|
|
| 73 | + (progn
|
|
| 74 | + (when (eq use :default)
|
|
| 75 | + (setf use *default-package-use-list*))
|
|
| 76 | + (make-package name
|
|
| 77 | + :use nil
|
|
| 78 | + :internal-symbols (or size 10)
|
|
| 79 | + :external-symbols (length exports))))))
|
|
| 80 | + (unless (string= (the string (package-name package)) name)
|
|
| 81 | + (error 'simple-package-error
|
|
| 82 | + :package name
|
|
| 83 | + :format-control (intl:gettext "~A is a nick-name for the package ~A")
|
|
| 84 | + :format-arguments (list name (package-name name))))
|
|
| 85 | + (enter-new-nicknames package nicknames)
|
|
| 86 | + ;; Shadows and Shadowing-imports.
|
|
| 87 | + (let ((old-shadows (package-%shadowing-symbols package)))
|
|
| 88 | + (shadow shadows package)
|
|
| 89 | + (dolist (sym-name shadows)
|
|
| 90 | + (setf old-shadows (remove (find-symbol sym-name package) old-shadows)))
|
|
| 91 | + (dolist (simports-from shadowing-imports)
|
|
| 92 | + (let ((other-package (package-or-lose (car simports-from))))
|
|
| 93 | + (dolist (sym-name (cdr simports-from))
|
|
| 94 | + (let ((sym (find-or-make-symbol sym-name other-package)))
|
|
| 95 | + (shadowing-import sym package)
|
|
| 96 | + (setf old-shadows (remove sym old-shadows))))))
|
|
| 97 | + (when old-shadows
|
|
| 98 | + (warn (intl:gettext "~A also shadows the following symbols:~% ~S")
|
|
| 99 | + name old-shadows)))
|
|
| 100 | + ;; Use
|
|
| 101 | + (unless (eq use :default)
|
|
| 102 | + (let ((old-use-list (package-use-list package))
|
|
| 103 | + (new-use-list (mapcar #'package-or-lose use)))
|
|
| 104 | + (use-package (set-difference new-use-list old-use-list) package)
|
|
| 105 | + (let ((laterize (set-difference old-use-list new-use-list)))
|
|
| 106 | + (when laterize
|
|
| 107 | + (unuse-package laterize package)
|
|
| 108 | + (warn (intl:gettext "~A previously used the following packages:~% ~S")
|
|
| 109 | + name
|
|
| 110 | + laterize)))))
|
|
| 111 | + ;; Import and Intern.
|
|
| 112 | + (dolist (sym-name interns)
|
|
| 113 | + (intern sym-name package))
|
|
| 114 | + (dolist (imports-from imports)
|
|
| 115 | + (let ((other-package (package-or-lose (car imports-from))))
|
|
| 116 | + (dolist (sym-name (cdr imports-from))
|
|
| 117 | + (import (list (find-or-make-symbol sym-name other-package))
|
|
| 118 | + package))))
|
|
| 119 | + ;; Exports.
|
|
| 120 | + (let ((old-exports nil)
|
|
| 121 | + (exports (mapcar #'(lambda (sym-name) (intern sym-name package))
|
|
| 122 | + exports)))
|
|
| 123 | + (do-external-symbols (sym package)
|
|
| 124 | + (push sym old-exports))
|
|
| 125 | + (export exports package)
|
|
| 126 | + (let ((diff (set-difference old-exports exports)))
|
|
| 127 | + (when diff
|
|
| 128 | + (warn (intl:gettext "~A also exports the following symbols:~% ~S")
|
|
| 129 | + name diff))))
|
|
| 130 | + ;; Documentation
|
|
| 131 | + (setf (package-doc-string package) doc-string)
|
|
| 132 | + package)) |
| ... | ... | @@ -1857,6 +1857,11 @@ |
| 1857 | 1857 | (:import-from "KERNEL" "*ANSI-DEFSTRUCT-OPTIONS-P*")
|
| 1858 | 1858 | (:import-from "SYSTEM" "MAKE-INDENTING-STREAM" "INDENTING-STREAM-P"
|
| 1859 | 1859 | "BINARY-TEXT-STREAM")
|
| 1860 | + (:import-from "LISP"
|
|
| 1861 | + "PACKAGE-LOCAL-NICKNAMES"
|
|
| 1862 | + "ADD-PACKAGE-LOCAL-NICKNAME"
|
|
| 1863 | + "REMOVE-PACKAGE-LOCAL-NICKNAME"
|
|
| 1864 | + "PACKAGE-LOCALLY-NICKNAMED-BY-LIST")
|
|
| 1860 | 1865 | #+double-double
|
| 1861 | 1866 | (:import-from "KERNEL" "DOUBLE-DOUBLE-FLOAT" "DD-PI")
|
| 1862 | 1867 | (:export "*AFTER-GC-HOOKS*" "*AFTER-SAVE-INITIALIZATIONS*"
|
| ... | ... | @@ -2109,7 +2114,12 @@ |
| 2109 | 2114 | "DESCRIBE-EXTERNAL-FORMAT"
|
| 2110 | 2115 | "LIST-ALL-EXTERNAL-FORMATS"
|
| 2111 | 2116 | "STRING-ENCODE" "STRING-DECODE"
|
| 2112 | - "SET-SYSTEM-EXTERNAL-FORMAT"))
|
|
| 2117 | + "SET-SYSTEM-EXTERNAL-FORMAT")
|
|
| 2118 | + ;; Package-local-nicknames
|
|
| 2119 | + (:export "PACKAGE-LOCAL-NICKNAMES"
|
|
| 2120 | + "ADD-PACKAGE-LOCAL-NICKNAME"
|
|
| 2121 | + "REMOVE-PACKAGE-LOCAL-NICKNAME"
|
|
| 2122 | + "PACKAGE-LOCALLY-NICKNAMED-BY-LIST"))
|
|
| 2113 | 2123 | |
| 2114 | 2124 | (defpackage "STREAM"
|
| 2115 | 2125 | (:import-from "SYSTEM" "LISP-STREAM")
|
| ... | ... | @@ -41,6 +41,8 @@ |
| 41 | 41 | #+relative-package-names
|
| 42 | 42 | (sys:register-lisp-feature :relative-package-names)
|
| 43 | 43 | |
| 44 | +(sys:register-lisp-feature :package-local-nicknames)
|
|
| 45 | + |
|
| 44 | 46 | (defvar *default-package-use-list* '("COMMON-LISP")
|
| 45 | 47 | "The list of packages to use by default of no :USE argument is supplied
|
| 46 | 48 | to MAKE-PACKAGE or other package creation forms.")
|
| ... | ... | @@ -91,6 +93,9 @@ |
| 91 | 93 | (lock nil :type boolean)
|
| 92 | 94 | (definition-lock nil :type boolean)
|
| 93 | 95 | |
| 96 | + ;; Package local nicknames
|
|
| 97 | + (%local-nicknames () :type list)
|
|
| 98 | + |
|
| 94 | 99 | ;; Documentation string for this package
|
| 95 | 100 | (doc-string nil :type (or simple-string null)))
|
| 96 | 101 | |
| ... | ... | @@ -397,6 +402,12 @@ |
| 397 | 402 | (setq package tmp))
|
| 398 | 403 | (relative-to package name))))))))
|
| 399 | 404 | |
| 405 | +(defun local-nickname-to-package (name)
|
|
| 406 | + ;; Skip all of this if we're doing package-init!
|
|
| 407 | + (unless *in-package-init*
|
|
| 408 | + (cdr (assoc name (package-%local-nicknames *package*)
|
|
| 409 | + :test #'string=))))
|
|
| 410 | + |
|
| 400 | 411 | ;;; find-package -- Public
|
| 401 | 412 | ;;;
|
| 402 | 413 | ;;;
|
| ... | ... | @@ -405,7 +416,8 @@ |
| 405 | 416 | (if (packagep name)
|
| 406 | 417 | name
|
| 407 | 418 | (let ((name (package-namify name)))
|
| 408 | - (or (package-name-to-package name)
|
|
| 419 | + (or (local-nickname-to-package name)
|
|
| 420 | + (package-name-to-package name)
|
|
| 409 | 421 | #+relative-package-names
|
| 410 | 422 | (relative-package-name-to-package name)))))
|
| 411 | 423 | |
| ... | ... | @@ -420,7 +432,8 @@ |
| 420 | 432 | thing)
|
| 421 | 433 | (t
|
| 422 | 434 | (let ((thing (package-namify thing)))
|
| 423 | - (cond ((package-name-to-package thing))
|
|
| 435 | + (cond ((local-nickname-to-package thing))
|
|
| 436 | + ((package-name-to-package thing))
|
|
| 424 | 437 | (t
|
| 425 | 438 | ;; ANSI spec's type-error where this is called. But,
|
| 426 | 439 | ;; but the resulting message is somewhat unclear.
|
| ... | ... | @@ -923,8 +936,10 @@ |
| 923 | 936 | (:EXPORT {symbol-name}*)
|
| 924 | 937 | (:INTERN {symbol-name}*)
|
| 925 | 938 | (:SIZE <integer>)
|
| 939 | + (:LOCAL-NICKNAMES {({nickname package}*)})
|
|
| 926 | 940 | All options except :SIZE and :DOCUMENTATION can be used multiple times."
|
| 927 | 941 | (let ((nicknames nil)
|
| 942 | + (local-nicknames nil)
|
|
| 928 | 943 | (size nil)
|
| 929 | 944 | (shadows nil)
|
| 930 | 945 | (shadowing-imports nil)
|
| ... | ... | @@ -940,6 +955,11 @@ |
| 940 | 955 | (case (car option)
|
| 941 | 956 | (:nicknames
|
| 942 | 957 | (setf nicknames (stringify-names (cdr option) "package")))
|
| 958 | + (:local-nicknames
|
|
| 959 | + (setf local-nicknames
|
|
| 960 | + (mapcar #'(lambda (o)
|
|
| 961 | + (stringify-names o "package"))
|
|
| 962 | + (cdr option))))
|
|
| 943 | 963 | (:size
|
| 944 | 964 | (cond (size
|
| 945 | 965 | (simple-program-error (intl:gettext "Can't specify :SIZE twice.")))
|
| ... | ... | @@ -994,9 +1014,9 @@ |
| 994 | 1014 | `(:shadowing-import-from
|
| 995 | 1015 | ,@(apply #'append (mapcar #'rest shadowing-imports))))
|
| 996 | 1016 | `(eval-when (compile load eval)
|
| 997 | - (%defpackage ,(stringify-name package "package") ',nicknames ',size
|
|
| 998 | - ',shadows ',shadowing-imports ',(if use-p use :default)
|
|
| 999 | - ',imports ',interns ',exports ',doc))))
|
|
| 1017 | + (%defpackage ,(stringify-name package "package") ',nicknames
|
|
| 1018 | + ',size ',shadows ',shadowing-imports ',(if use-p use :default)
|
|
| 1019 | + ',imports ',interns ',exports ',doc ',local-nicknames))))
|
|
| 1000 | 1020 | |
| 1001 | 1021 | (defun check-disjoint (&rest args)
|
| 1002 | 1022 | ;; Check whether all given arguments specify disjoint sets of symbols.
|
| ... | ... | @@ -1014,9 +1034,9 @@ |
| 1014 | 1034 | key1 key2 common))))
|
| 1015 | 1035 | |
| 1016 | 1036 | (defun %defpackage (name nicknames size shadows shadowing-imports
|
| 1017 | - use imports interns exports doc-string)
|
|
| 1037 | + use imports interns exports doc-string &optional local-nicknames)
|
|
| 1018 | 1038 | (declare (type simple-base-string name)
|
| 1019 | - (type list nicknames shadows shadowing-imports
|
|
| 1039 | + (type list nicknames local-nicknames shadows shadowing-imports
|
|
| 1020 | 1040 | imports interns exports)
|
| 1021 | 1041 | (type (or list (member :default)) use)
|
| 1022 | 1042 | (type (or simple-base-string null) doc-string))
|
| ... | ... | @@ -1034,6 +1054,7 @@ |
| 1034 | 1054 | :format-control (intl:gettext "~A is a nick-name for the package ~A")
|
| 1035 | 1055 | :format-arguments (list name (package-name name))))
|
| 1036 | 1056 | (enter-new-nicknames package nicknames)
|
| 1057 | + (enter-new-local-nicknames package local-nicknames)
|
|
| 1037 | 1058 | ;; Shadows and Shadowing-imports.
|
| 1038 | 1059 | (let ((old-shadows (package-%shadowing-symbols package)))
|
| 1039 | 1060 | (shadow shadows package)
|
| ... | ... | @@ -1128,6 +1149,12 @@ |
| 1128 | 1149 | (setf (gethash n *package-names*) package)
|
| 1129 | 1150 | (push n (package-%nicknames package)))))))
|
| 1130 | 1151 | |
| 1152 | +(defun enter-new-local-nicknames (package local-nicknames)
|
|
| 1153 | + (dolist (entry local-nicknames)
|
|
| 1154 | + (destructuring-bind (nick actual)
|
|
| 1155 | + entry
|
|
| 1156 | + (add-package-local-nickname nick actual package))))
|
|
| 1157 | + |
|
| 1131 | 1158 | |
| 1132 | 1159 | ;;; Make-Package -- Public
|
| 1133 | 1160 | ;;;
|
| ... | ... | @@ -1225,6 +1252,14 @@ |
| 1225 | 1252 | (enter-new-nicknames package new-nicknames)
|
| 1226 | 1253 | package))
|
| 1227 | 1254 | |
| 1255 | +;; Given a package designator, convert it to the corresponding package
|
|
| 1256 | +;; object.
|
|
| 1257 | +(declaim (inline designator-package))
|
|
| 1258 | +(defun designator-package (designator)
|
|
| 1259 | + (if (packagep designator)
|
|
| 1260 | + designator
|
|
| 1261 | + (package-name-to-package (package-namify designator))))
|
|
| 1262 | + |
|
| 1228 | 1263 | ;;; Delete-Package -- Public
|
| 1229 | 1264 | ;;;
|
| 1230 | 1265 | (defun delete-package (package-or-name)
|
| ... | ... | @@ -1254,6 +1289,13 @@ |
| 1254 | 1289 | (mapcar #'package-name use-list))))
|
| 1255 | 1290 | (dolist (p use-list)
|
| 1256 | 1291 | (unuse-package package p))))
|
| 1292 | + ;; Find all the packages that have a local nickname to this
|
|
| 1293 | + ;; package and remove the local nickname entry.
|
|
| 1294 | + (dolist (pkg (package-locally-nicknamed-by-list package))
|
|
| 1295 | + (setf (package-%local-nicknames pkg)
|
|
| 1296 | + (delete package
|
|
| 1297 | + (package-%local-nicknames pkg)
|
|
| 1298 | + :key #'cdr)))
|
|
| 1257 | 1299 | (dolist (used (package-use-list package))
|
| 1258 | 1300 | (unuse-package used package))
|
| 1259 | 1301 | (do-symbols (sym package)
|
| ... | ... | @@ -1928,7 +1970,128 @@ |
| 1928 | 1970 | (result symbol))
|
| 1929 | 1971 | string package)
|
| 1930 | 1972 | (result)))
|
| 1931 | - |
|
| 1973 | + |
|
| 1974 | +;;;; Support for package local nicknames
|
|
| 1975 | + |
|
| 1976 | +;;; PACKAGE-LOCAL-NICKNAMES -- public.
|
|
| 1977 | +;;;
|
|
| 1978 | +(defun package-local-nicknames (package)
|
|
| 1979 | + "Returns an alist of (local-nickname . actual-package) describing the
|
|
| 1980 | + nicknames local to Package."
|
|
| 1981 | + ;; Should we return a new list?
|
|
| 1982 | + (copy-list (package-%local-nicknames (designator-package package))))
|
|
| 1983 | + |
|
| 1984 | +;;; ADD-PACKAGE-LOCAL-NICKNAME -- public.
|
|
| 1985 | +;;;
|
|
| 1986 | +(defun add-package-local-nickname (local-nickname actual-package &optional (package *package*))
|
|
| 1987 | + "For the designated package Package (defaulting to *PACKAGE*), add
|
|
| 1988 | + Local-Nickname as a package local nickname to the package
|
|
| 1989 | + Actual-Package. Actual-Package and Package must be an package
|
|
| 1990 | + designator. Local-Nickname should be a string designator.
|
|
| 1991 | + |
|
| 1992 | + Returns the designated package.
|
|
| 1993 | + |
|
| 1994 | + Signals a continuable error if any of the following are true:
|
|
| 1995 | + - Local-Nickname is already a local nickname for a different package
|
|
| 1996 | + - Local-Nickname is one of \"CL\", \"COMMON-LISP\", or \"KEYWORD\"
|
|
| 1997 | + - Local-Nickname is a global name or nickname for designated package"
|
|
| 1998 | + |
|
| 1999 | + (let* ((pkg (designator-package package))
|
|
| 2000 | + (actual-pkg (designator-package actual-package))
|
|
| 2001 | + (nicks (package-%local-nicknames pkg))
|
|
| 2002 | + (local-nickname (package-namify local-nickname)))
|
|
| 2003 | + (when (member local-nickname '("CL" "COMMON-LISP" "KEYWORD")
|
|
| 2004 | + :test #'string=)
|
|
| 2005 | + (cerror "Add nickname anyway"
|
|
| 2006 | + 'simple-package-error
|
|
| 2007 | + :package pkg
|
|
| 2008 | + :format-control (intl:gettext "Local nickname cannot be \"CL\", \"COMMON-LISP\" or \"KEYWORD\"")
|
|
| 2009 | + :format-arguments (list local-nickname)))
|
|
| 2010 | + (let ((found-it (find-if #'(lambda (nick)
|
|
| 2011 | + (string= nick local-nickname))
|
|
| 2012 | + nicks :key #'car)))
|
|
| 2013 | + (when found-it
|
|
| 2014 | + ;; If the local nickname alread exists and it's the same
|
|
| 2015 | + ;; package, there's nothing to do.
|
|
| 2016 | + (when (eq (cdr found-it) actual-pkg)
|
|
| 2017 | + (return-from add-package-local-nickname pkg))
|
|
| 2018 | + ;; Otherwise, signal an error that the packages don't match.
|
|
| 2019 | + (restart-case
|
|
| 2020 | + (error 'simple-package-error
|
|
| 2021 | + :package pkg
|
|
| 2022 | + :format-control (intl:gettext "~A is already a local nickname for the package ~A in ~A")
|
|
| 2023 | + :format-arguments (list local-nickname actual-pkg pkg))
|
|
| 2024 | + (keep-old-nickname ()
|
|
| 2025 | + :report (lambda (stream)
|
|
| 2026 | + (format stream "Keep ~A as a local nickname for ~A~%"
|
|
| 2027 | + local-nickname (cdr found-it)))
|
|
| 2028 | + (return-from add-package-local-nickname (cdr found-it)))
|
|
| 2029 | + (use-new-nickname ()
|
|
| 2030 | + :report (lambda (stream)
|
|
| 2031 | + (format stream "Use ~A as a local nickname for ~A instead~%"
|
|
| 2032 | + local-nickname actual-pkg))
|
|
| 2033 | + (setf (cdr found-it) actual-pkg)
|
|
| 2034 | + (return-from add-package-local-nickname actual-pkg)))))
|
|
| 2035 | + |
|
| 2036 | + ;; The new LOCAL-NICKNAME can't be the same as PACKAGE.
|
|
| 2037 | + (when (string= local-nickname (package-name pkg))
|
|
| 2038 | + (cerror "Add nickname anyway"
|
|
| 2039 | + 'simple-package-error
|
|
| 2040 | + :package pkg
|
|
| 2041 | + :format-control (intl:gettext "~A cannot be a package local nickname for the global package~_ ~A with the same name")
|
|
| 2042 | + :format-arguments (list local-nickname pkg)))
|
|
| 2043 | + |
|
| 2044 | + ;; Can't be a local nickname for any of the nicknames
|
|
| 2045 | + (let ((found-it (find local-nickname
|
|
| 2046 | + (package-nicknames pkg)
|
|
| 2047 | + :test #'string=)))
|
|
| 2048 | + (when found-it
|
|
| 2049 | + (cerror "Use it as a local nickname anyway"
|
|
| 2050 | + 'simple-package-error
|
|
| 2051 | + :format-control (intl:gettext "~A cannot be a package local nickname for the global package~_ ~A with nickname ~A")
|
|
| 2052 | + :format-arguments (list local-nickname pkg found-it))))
|
|
| 2053 | +
|
|
| 2054 | + (setf (package-%local-nicknames pkg)
|
|
| 2055 | + (push (cons local-nickname
|
|
| 2056 | + (designator-package actual-package))
|
|
| 2057 | + nicks))
|
|
| 2058 | + pkg))
|
|
| 2059 | + |
|
| 2060 | +;;; REMOVE-PACKAGE-LOCAL-NICKNAME -- public.
|
|
| 2061 | +;;;
|
|
| 2062 | +(defun remove-package-local-nickname (old-nickname &optional (package *package*))
|
|
| 2063 | + "If Package has Old-Nickname as a local nickname, it is removed.
|
|
| 2064 | + Returns true if the nickname existed and was removed. Otherwise
|
|
| 2065 | + returns NIL."
|
|
| 2066 | + (let* ((old-nick (if (packagep old-nickname)
|
|
| 2067 | + (package-namestring old-nickname)
|
|
| 2068 | + (package-namify old-nickname)))
|
|
| 2069 | + (pkg (designator-package package))
|
|
| 2070 | + (nicks (package-%local-nicknames pkg))
|
|
| 2071 | + deletedp)
|
|
| 2072 | + (setf (package-%local-nicknames pkg)
|
|
| 2073 | + (delete-if #'(lambda (local-nick)
|
|
| 2074 | + (when (string= local-nick old-nick)
|
|
| 2075 | + (setf deletedp t)))
|
|
| 2076 | + nicks :key #'car))
|
|
| 2077 | + deletedp))
|
|
| 2078 | + |
|
| 2079 | +;;; PACKAGE-LOCALLY-NICKNAMED-BY-LIST -- public
|
|
| 2080 | +;;;
|
|
| 2081 | +;;; FIXME: This is pretty inefficient because we have list all the
|
|
| 2082 | +;;; packages and look throught the %local-nicknames to find the
|
|
| 2083 | +;;; packages. We could probably make it faster if we added a new slot
|
|
| 2084 | +;;; to the package structure similar to how we have %use-list and
|
|
| 2085 | +;;; %used-by-list.
|
|
| 2086 | +(defun package-locally-nicknamed-by-list (package)
|
|
| 2087 | + "Returns a list of packages which have a local nickname for Package."
|
|
| 2088 | + (let ((pkg (designator-package package)))
|
|
| 2089 | + (loop for p in (list-all-packages)
|
|
| 2090 | + when (find pkg
|
|
| 2091 | + (package-%local-nicknames p)
|
|
| 2092 | + :key #'cdr
|
|
| 2093 | + :test #'eq)
|
|
| 2094 | + collect p)))
|
|
| 1932 | 2095 | |
| 1933 | 2096 | |
| 1934 | 2097 | ;;; Initialization.
|
| ... | ... | @@ -696,7 +696,15 @@ |
| 696 | 696 | ;; qualified. This can happen if the symbol has been inherited
|
| 697 | 697 | ;; from a package other than its home package.
|
| 698 | 698 | (unless (and accessible (eq symbol object))
|
| 699 | - (output-symbol-name (package-name package) stream)
|
|
| 699 | + ;; If the actual symbol package has a local nickname in
|
|
| 700 | + ;; *package*, use that as the package name instead of the
|
|
| 701 | + ;; actual symbol package name.
|
|
| 702 | + (let ((local-nicks (package-%local-nicknames *package*))
|
|
| 703 | + (pkg-name (package-name package)))
|
|
| 704 | + (when local-nicks
|
|
| 705 | + (setf pkg-name (or (car (rassoc package local-nicks))
|
|
| 706 | + pkg-name)))
|
|
| 707 | + (output-symbol-name pkg-name stream))
|
|
| 700 | 708 | (multiple-value-bind (symbol externalp)
|
| 701 | 709 | (find-external-symbol name package)
|
| 702 | 710 | (declare (ignore symbol))
|
| ... | ... | @@ -138,7 +138,7 @@ |
| 138 | 138 | #+(or clasp abcl ecl cmu) #:ext
|
| 139 | 139 | #+ccl #:ccl
|
| 140 | 140 | #+lispworks #:hcl
|
| 141 | - #-(or allegro sbcl clasp abcl ccl lispworks ecl)
|
|
| 141 | + #-(or allegro sbcl clasp abcl ccl lispworks ecl cmu)
|
|
| 142 | 142 | (error "Don't know from which package this lisp supplies the local-package-nicknames API.")
|
| 143 | 143 | #:remove-package-local-nickname #:package-local-nicknames #:add-package-local-nickname)
|
| 144 | 144 | (:export
|
| ... | ... | @@ -8208,6 +8208,7 @@ msgid "" |
| 8208 | 8208 | " (:EXPORT {symbol-name}*)\n"
|
| 8209 | 8209 | " (:INTERN {symbol-name}*)\n"
|
| 8210 | 8210 | " (:SIZE <integer>)\n"
|
| 8211 | +" (:LOCAL-NICKNAMES {({nickname package}*)})\n"
|
|
| 8211 | 8212 | " All options except :SIZE and :DOCUMENTATION can be used multiple times."
|
| 8212 | 8213 | msgstr ""
|
| 8213 | 8214 | |
| ... | ... | @@ -8551,6 +8552,58 @@ msgid "" |
| 8551 | 8552 | " found instead of describing them."
|
| 8552 | 8553 | msgstr ""
|
| 8553 | 8554 | |
| 8555 | +#: src/code/package.lisp
|
|
| 8556 | +msgid ""
|
|
| 8557 | +"Returns an alist of (local-nickname . actual-package) describing the\n"
|
|
| 8558 | +" nicknames local to Package."
|
|
| 8559 | +msgstr ""
|
|
| 8560 | + |
|
| 8561 | +#: src/code/package.lisp
|
|
| 8562 | +msgid ""
|
|
| 8563 | +"For the designated package Package (defaulting to *PACKAGE*), add\n"
|
|
| 8564 | +" Local-Nickname as a package local nickname to the package\n"
|
|
| 8565 | +" Actual-Package. Actual-Package and Package must be an package\n"
|
|
| 8566 | +" designator. Local-Nickname should be a string designator.\n"
|
|
| 8567 | +"\n"
|
|
| 8568 | +" Returns the designated package.\n"
|
|
| 8569 | +"\n"
|
|
| 8570 | +" Signals a continuable error if any of the following are true:\n"
|
|
| 8571 | +" - Local-Nickname is already a local nickname for a different package\n"
|
|
| 8572 | +" - Local-Nickname is one of \"CL\", \"COMMON-LISP\", or \"KEYWORD\"\n"
|
|
| 8573 | +" - Local-Nickname is a global name or nickname for designated package"
|
|
| 8574 | +msgstr ""
|
|
| 8575 | + |
|
| 8576 | +#: src/code/package.lisp
|
|
| 8577 | +msgid "Local nickname cannot be \"CL\", \"COMMON-LISP\" or \"KEYWORD\""
|
|
| 8578 | +msgstr ""
|
|
| 8579 | + |
|
| 8580 | +#: src/code/package.lisp
|
|
| 8581 | +msgid "~A is already a local nickname for the package ~A in ~A"
|
|
| 8582 | +msgstr ""
|
|
| 8583 | + |
|
| 8584 | +#: src/code/package.lisp
|
|
| 8585 | +msgid ""
|
|
| 8586 | +"~A cannot be a package local nickname for the global package~_ ~A with the "
|
|
| 8587 | +"same name"
|
|
| 8588 | +msgstr ""
|
|
| 8589 | + |
|
| 8590 | +#: src/code/package.lisp
|
|
| 8591 | +msgid ""
|
|
| 8592 | +"~A cannot be a package local nickname for the global package~_ ~A with "
|
|
| 8593 | +"nickname ~A"
|
|
| 8594 | +msgstr ""
|
|
| 8595 | + |
|
| 8596 | +#: src/code/package.lisp
|
|
| 8597 | +msgid ""
|
|
| 8598 | +"If Package has Old-Nickname as a local nickname, it is removed.\n"
|
|
| 8599 | +" Returns true if the nickname existed and was removed. Otherwise\n"
|
|
| 8600 | +" returns NIL."
|
|
| 8601 | +msgstr ""
|
|
| 8602 | + |
|
| 8603 | +#: src/code/package.lisp
|
|
| 8604 | +msgid "Returns a list of packages which have a local nickname for Package."
|
|
| 8605 | +msgstr ""
|
|
| 8606 | + |
|
| 8554 | 8607 | #: src/code/reader.lisp
|
| 8555 | 8608 | msgid "Float format for 1.0E1"
|
| 8556 | 8609 | msgstr ""
|