1
;;;; Copyright (c) 1984, Taiichi Yuasa and Masami Hagiya.
2
;;;; Copyright (c) 1990, Giuseppe Attardi.
4
;;;; This program is free software; you can redistribute it and/or
5
;;;; modify it under the terms of the GNU Library General Public
6
;;;; License as published by the Free Software Foundation; either
7
;;;; version 2 of the License, or (at your option) any later version.
9
;;;; See file '../Copyright' for full details.
13
;; This is taken from SBCL's code/module.lisp which is in the public
18
;;;; exported specials
21
"This is a list of module names that have been loaded into Lisp so far.
22
It is used by PROVIDE and REQUIRE.")
24
(defvar *module-provider-functions* nil
25
"See function documentation for REQUIRE")
27
;;;; PROVIDE and REQUIRE
29
(defun provide (module-name)
30
"Adds a new module name to *MODULES* indicating that it has been loaded.
31
Module-name is a string designator"
32
(pushnew (string module-name) *modules* :test #'string=)
35
(defvar *requiring* nil)
37
(defun require-error (control &rest arguments)
38
(error "Module error: ~?" control arguments))
40
(defun require (module-name &optional pathnames)
41
"Loads a module, unless it already has been loaded. PATHNAMES, if supplied,
42
is a designator for a list of pathnames to be loaded if the module
43
needs to be. If PATHNAMES is not supplied, functions from the list
44
*MODULE-PROVIDER-FUNCTIONS* are called in order with MODULE-NAME
45
as an argument, until one of them returns non-NIL. User code is
46
responsible for calling PROVIDE to indicate a successful load of the
48
(let ((name (string module-name)))
49
(when (member name *requiring* :test #'string=)
50
(require-error "~@<Could not ~S ~A: circularity detected. Please check ~
51
your configuration.~:@>" 'require module-name))
52
(let ((saved-modules (copy-list *modules*))
53
(*requiring* (cons name *requiring*)))
54
(unless (member name *modules* :test #'string=)
56
(unless (listp pathnames) (setf pathnames (list pathnames)))
57
;; ambiguity in standard: should we try all pathnames in the
58
;; list, or should we stop as soon as one of them calls PROVIDE?
59
(dolist (ele pathnames t)
62
(unless (some (lambda (p) (funcall p module-name))
63
*module-provider-functions*)
64
(require-error "Don't know how to ~S ~A."
65
'require module-name)))))
66
(set-difference *modules* saved-modules))))
68
(pushnew #'(lambda (module)
69
(let* ((sysdir (translate-logical-pathname #P"SYS:"))
70
(module (string module)))
72
(let ((path (merge-pathnames (make-pathname :name module) sysdir)))
73
(load path :if-does-not-exist nil))
74
(let ((path (merge-pathnames (make-pathname :name (string-downcase module)) sysdir)))
75
(load path :if-does-not-exist nil)))))
76
*module-provider-functions*)