Changeset 499
- Timestamp:
- Feb 7, 2004, 4:11:13 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/ccl/level-1/l1-files.lisp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ccl/level-1/l1-files.lisp
r490 r499 1166 1166 (return t)))))) 1167 1167 1168 (defun provide (module &aux (str (string module))) 1169 (when (null module) (report-bad-arg module '(not (member nil)))) 1170 (setq *modules* (adjoin str *modules* :test #'string-equal)) 1171 (let* ((cell (assoc str *module-file-alist* :test #'string-equal)) 1172 (path *loading-file-source-file*)) 1173 (if cell 1174 (setf (cdr cell) path) 1175 (push (cons str path) *module-file-alist*))) 1176 str) 1168 (defun provide (module) 1169 (pushnew (string module) *modules* :test #'string=) 1170 module) 1177 1171 1178 1172 (defparameter *loading-modules* () "Internal. Prevents circularity") 1179 1180 (defun require (module &optional pathname &aux (str (string module))) 1181 (when (null module) (report-bad-arg module '(not null))) 1182 (when (and (not (member str *modules* :test #'string-equal)) 1183 (not (member str *loading-modules* :test #'string-equal)) 1184 (or pathname 1185 (setq pathname (find-module-pathnames str)) 1186 (progn 1187 (cerror "If ~S still hasn't been provided, 1188 you will be asked to choose a file." 1189 "The module ~S was required while loading ~S. 1190 No file could be found for that module." 1191 str *loading-file-source-file*) 1192 (unless (member str *modules* :test #'string-equal) 1193 (with-terminal-input 1194 (format t "~&pathname: ") 1195 (setq pathname (read))) ) 1196 pathname))) 1197 (let ((*loading-modules* (cons str *loading-modules*))) 1198 (if (consp pathname) 1199 (dolist (path pathname) (load path)) 1200 (load pathname))) 1201 (setq *modules* (adjoin str *modules* :test #'string-equal))) 1202 str) 1173 (defparameter *module-provider-functions* '(module-provide-search-path)) 1174 1175 (defun module-provide-search-path (module) 1176 ;; (format *debug-io* "trying module-provide-search-path~%") 1177 (let* ((module-name (string module)) 1178 (pathname (find-module-pathnames module-name))) 1179 (when pathname 1180 (if (consp pathname) 1181 (dolist (path pathname) (load path)) 1182 (load pathname)) 1183 (provide module)))) 1184 1185 (defun require (module &optional pathname) 1186 (let* ((str (string module)) 1187 (original-modules (copy-list *modules*))) 1188 (unless (or (member str *modules* :test #'string=) 1189 (member str *loading-modules* :test #'string=)) 1190 ;; The check of (and binding of) *LOADING-MODULES* is a 1191 ;; traditional defense against circularity. (Another 1192 ;; defense is not having circularity, of course.) The 1193 ;; effect is that if something's in the process of being 1194 ;; REQUIREd and it's REQUIREd again (transitively), 1195 ;; the inner REQUIRE is a no-op. 1196 (let ((*loading-modules* (cons str *loading-modules*))) 1197 (if pathname 1198 (dolist (path (if (atom pathname) (list pathname) pathname)) 1199 (load path)) 1200 (unless (some (lambda (p) (funcall p module)) 1201 *module-provider-functions*) 1202 (error "Don't know how to load ~A" module))))) 1203 (values module 1204 (set-difference *modules* original-modules)))) 1203 1205 1204 1206 (defun find-module-pathnames (module) 1205 1207 "Returns the file or list of files making up the module" 1206 (or (cdr (assoc module *module-file-alist* :test #'string-equal)) 1207 (let ((mod-path (make-pathname :name (string-downcase module) :defaults nil)) path) 1208 (let ((mod-path (make-pathname :name (string-downcase module) :defaults nil)) path) 1208 1209 (dolist (path-cand *module-search-path* nil) 1209 1210 (when (setq path (find-load-file (merge-pathnames mod-path path-cand))) 1210 (return path))))) )1211 (return path))))) 1211 1212 1212 1213 (defun wild-pathname-p (pathname &optional field-key)
Note:
See TracChangeset
for help on using the changeset viewer.
