| 1 |
;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil; Package: SYSTEM -*- |
| 2 |
;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab: |
| 3 |
|
| 4 |
;;;; |
| 5 |
;;;; Copyright (c) 1984, Taiichi Yuasa and Masami Hagiya. |
| 6 |
;;;; Copyright (c) 1990, Giuseppe Attardi. |
| 7 |
;;;; |
| 8 |
;;;; See file 'LICENSE' for the copyright details. |
| 9 |
|
| 10 |
;;;; module routines |
| 11 |
|
| 12 |
;; This is taken from SBCL's code/module.lisp which is in the public |
| 13 |
;; domain. |
| 14 |
|
| 15 |
(in-package "SYSTEM") |
| 16 |
|
| 17 |
;;;; exported specials |
| 18 |
|
| 19 |
(defparameter *modules* () |
| 20 |
"This is a list of module names that have been loaded into Lisp so far. |
| 21 |
It is used by PROVIDE and REQUIRE.") |
| 22 |
|
| 23 |
(defparameter *module-provider-functions* nil |
| 24 |
"See function documentation for REQUIRE") |
| 25 |
|
| 26 |
;;;; PROVIDE and REQUIRE |
| 27 |
|
| 28 |
(defun provide (module-name) |
| 29 |
"Adds a new module name to *MODULES* indicating that it has been loaded. |
| 30 |
Module-name is a string designator" |
| 31 |
(pushnew (string module-name) *modules* :test #'string=) |
| 32 |
t) |
| 33 |
|
| 34 |
(defparameter *requiring* nil) |
| 35 |
|
| 36 |
(defun require-error (control &rest arguments) |
| 37 |
(error "Module error: ~?" control arguments)) |
| 38 |
|
| 39 |
(defun require (module-name &optional pathnames) |
| 40 |
"Loads a module, unless it already has been loaded. PATHNAMES, if supplied, |
| 41 |
is a designator for a list of pathnames to be loaded if the module |
| 42 |
needs to be. If PATHNAMES is not supplied, functions from the list |
| 43 |
*MODULE-PROVIDER-FUNCTIONS* are called in order with MODULE-NAME |
| 44 |
as an argument, until one of them returns non-NIL. User code is |
| 45 |
responsible for calling PROVIDE to indicate a successful load of the |
| 46 |
module." |
| 47 |
(let ((name (string module-name))) |
| 48 |
(when (member name *requiring* :test #'string=) |
| 49 |
(require-error "~@<Could not ~S ~A: circularity detected. Please check ~ |
| 50 |
your configuration.~:@>" 'require module-name)) |
| 51 |
(let ((saved-modules (copy-list *modules*)) |
| 52 |
(*requiring* (cons name *requiring*))) |
| 53 |
(unless (member name *modules* :test #'string=) |
| 54 |
(cond (pathnames |
| 55 |
(unless (listp pathnames) (setf pathnames (list pathnames))) |
| 56 |
;; ambiguity in standard: should we try all pathnames in the |
| 57 |
;; list, or should we stop as soon as one of them calls PROVIDE? |
| 58 |
(dolist (ele pathnames t) |
| 59 |
(load ele))) |
| 60 |
(t |
| 61 |
(unless (some (lambda (p) (funcall p module-name)) |
| 62 |
*module-provider-functions*) |
| 63 |
(require-error "Don't know how to ~S ~A." |
| 64 |
'require module-name))))) |
| 65 |
(set-difference *modules* saved-modules)))) |
| 66 |
|
| 67 |
(pushnew #'(lambda (module) |
| 68 |
(let* ((module (string module))) |
| 69 |
(or |
| 70 |
(let ((path (make-pathname :name module :defaults "SYS:"))) |
| 71 |
(load path :if-does-not-exist nil)) |
| 72 |
(let ((path (make-pathname :name (string-downcase module) |
| 73 |
:defaults "SYS:"))) |
| 74 |
(load path :if-does-not-exist nil))))) |
| 75 |
*module-provider-functions*) |