123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- ; Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees. See file COPYING.
- ; flatloaded -> load
- (define *noisy?* #f)
- (define (flatload struct . env-option)
- (let ((env (if (null? env-option)
- (interaction-environment)
- (car env-option)))
- (l '())
- (set-package-loaded?! set-package-loaded?!))
- (walk-packages (list struct)
- (lambda (p)
- (not (package-loaded? p)))
- (lambda (file p)
- (let* ((fn (package-file-name p))
- (file (namestring file
- (if fn
- (file-name-directory fn)
- #f)
- *load-file-type*)))
- (if *noisy?*
- (begin (display #\space) (display file)))
- (set! l (cons (lambda () (apply fload file env-option))
- l))))
- (lambda (forms p)
- (set! l (cons (lambda ()
- (for-each (lambda (form)
- (eval form env))
- forms))
- l)))
- (lambda (p)
- (set! l (cons (lambda ()
- (set-package-loaded?! p #t))
- l))))
- (for-each (lambda (thunk) (thunk)) (reverse l))
- (newline)))
- (define (fload filename . rest)
- (let ((save filename))
- (dynamic-wind (lambda () (set! *source-file-name* filename))
- (lambda ()
- (apply load filename rest))
- (lambda () (set! *source-file-name* save)))))
- (define (walk-packages structs process? file-action forms-action after-action)
- (let ((seen '()))
- (letrec ((recur
- (lambda (s)
- (let ((p (structure-package s)))
- (if (not (memq p seen))
- (begin
- (set! seen (cons p seen))
- (if (process? p)
- (begin
- (if *noisy?*
- (begin (newline)
- (display "[")
- (write (structure-name s))))
- ;; (write (structure-name s)) (display " ")
- (for-each recur (package-opens p))
- (for-each (lambda (name+struct)
- (recur (cdr name+struct)))
- (package-accesses p))
- (for-each (lambda (clause)
- (case (car clause)
- ((files)
- (for-each (lambda (f)
- (file-action f p))
- (cdr clause)))
- ((begin)
- (forms-action (cdr clause) p))))
- (package-clauses p))
- (after-action p)
- (if *noisy?* (display "]"))))))))))
- (for-each recur structs))
- (if *noisy?* (newline))
- seen))
- ; Return list of names of all files needed to build a particular structure.
- ; This is handy for creating dependency lists for "make".
- (define (all-file-names struct . base-option)
- (let ((l '())
- (b '()))
- (walk-packages base-option
- (lambda (p) #t)
- (lambda (filename p) #f)
- (lambda (forms p) #f)
- (lambda (p)
- (set! b (cons p b))))
- (walk-packages (list struct)
- (lambda (p)
- (not (memq p b)))
- (lambda (filename p)
- (let ((dir (file-name-directory (package-file-name p))))
- (set! l (cons (namestring filename dir *load-file-type*)
- l))))
- (lambda (forms p)
- (display "Package contains (begin ...) clause: ")
- (write forms)
- (newline))
- (lambda (p) #f))
- (reverse l)))
|