1 ;;;; REQUIRE, PROVIDE, and friends
3 ;;;; Note that this module file is based on the old system, and is being
4 ;;;; spliced into the current sources to reflect the last minute deprecated
5 ;;;; addition of modules to the X3J13 ANSI standard.
7 ;;;; FIXME: This implementation has cruft not required by the ANSI
8 ;;;; spec, notably DEFMODULE. We should probably minimize it, since
9 ;;;; it's deprecated anyway.
11 ;;;; This software is part of the SBCL system. See the README file for
12 ;;;; more information.
14 ;;;; This software is derived from the CMU CL system, which was
15 ;;;; written at Carnegie Mellon University and released into the
16 ;;;; public domain. The software is in the public domain and is
17 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
18 ;;;; files for more information.
20 (in-package "SB!IMPL")
25 ;;;; exported specials
29 "This is a list of module names that have been loaded into Lisp so far.
30 It is used by PROVIDE and REQUIRE.")
33 ;;;; FIXME: Remove this.
35 (defvar *module-file-translations* (make-hash-table :test 'equal))
36 (defmacro defmodule (name &rest files)
38 "Defines a module by registering the files that need to be loaded when
39 the module is required. If name is a symbol, its print name is used
41 `(%define-module ,name ',files))
43 (defun %define-module (name files)
44 (setf (gethash (module-name-string name) *module-file-translations*)
47 (defun module-files (name)
48 (gethash name *module-file-translations*))
50 ;;;; PROVIDE and REQUIRE
52 (defun provide (module-name)
54 "Adds a new module name to *MODULES* indicating that it has been loaded.
55 Module-name may be either a case-sensitive string or a symbol; if it is
56 a symbol, its print name is downcased and used."
57 (pushnew (module-name-string module-name) *modules* :test #'string=)
60 (defun require (module-name &optional pathname)
62 "Loads a module when it has not been already. PATHNAME, if supplied,
63 is a single pathname or list of pathnames to be loaded if the module
64 needs to be. If PATHNAME is not supplied, then a list of files are
65 looked for that were registered by a DEFMODULE form. If the module
66 has not been defined, then a file will be loaded whose name is formed
67 by merging \"modules:\" and MODULE-NAME (downcased if it is a symbol).
68 This merged name will be probed with both a .lisp extension and any
69 architecture-specific FASL extensions, and LOAD will be called on it
71 ;; KLUDGE: Does this really match the doc string any more? (Did it ever
72 ;; match the doc string? Arguably this isn't a high priority question
73 ;; since REQUIRE is deprecated anyway and I've not been very motivated
74 ;; to maintain CMU CL extensions like DEFMODULE.. -- WHN 19990804
76 (module-name-string module-name))
77 (unless (member module-name *modules* :test #'string=)
79 (unless (listp pathname) (setf pathname (list pathname)))
80 (let ((files (module-files module-name)))
83 (setf pathname (list (merge-pathnames "modules:" module-name))))))
84 (dolist (ele pathname t)
89 (defun module-name-string (name)
92 (symbol (string-downcase (symbol-name name)))
93 (t (error 'simple-type-error
95 :expected-type '(or string symbol)
96 :format-control "Module name must be a string or symbol -- ~S."
97 :format-arguments (list name)))))