* added a "current-library-collection" primitive.
Calling (current-library-collection) returns a procedure that: - when called with no arguments, it returns a list of the set of libraries in the collection. - when called with a single argument, it adds that library to the set of libraries in the collection. Calling (current-library-collection f) sets the current library collection to be the procedure f which must follow the protocol above.
This commit is contained in:
parent
34fa59f9d4
commit
6922733809
BIN
src/ikarus.boot
BIN
src/ikarus.boot
Binary file not shown.
|
@ -1,8 +1,30 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(library (ikarus library-manager)
|
(library (ikarus library-manager)
|
||||||
(export)
|
(export)
|
||||||
(import (scheme))
|
(import (scheme))
|
||||||
|
|
||||||
|
|
||||||
|
(define (make-collection)
|
||||||
|
(let ([set '()])
|
||||||
|
(define (set-cons x ls)
|
||||||
|
(cond
|
||||||
|
[(memq x ls) ls]
|
||||||
|
[else (cons x ls)]))
|
||||||
|
(case-lambda
|
||||||
|
[() set]
|
||||||
|
[(x) (set! set (set-cons x set))])))
|
||||||
|
|
||||||
|
(define lm:current-library-collection
|
||||||
|
(make-parameter (make-collection)
|
||||||
|
(lambda (x)
|
||||||
|
(unless (procedure? x)
|
||||||
|
(error 'current-library-collection
|
||||||
|
"~s is not a procedure" x))
|
||||||
|
x)))
|
||||||
|
|
||||||
(define-record library
|
(define-record library
|
||||||
(id name ver imp* vis* inv* subst env visit-state invoke-state))
|
(id name ver imp* vis* inv* subst env visit-state invoke-state))
|
||||||
|
|
||||||
|
@ -11,10 +33,8 @@
|
||||||
[(null? ls) '()]
|
[(null? ls) '()]
|
||||||
[else (error 'find-dependencies "cannot handle deps yet")]))
|
[else (error 'find-dependencies "cannot handle deps yet")]))
|
||||||
|
|
||||||
(define *all-libraries* '())
|
|
||||||
|
|
||||||
(define (find-library-by pred)
|
(define (find-library-by pred)
|
||||||
(let f ([ls *all-libraries*])
|
(let f ([ls ((lm:current-library-collection))])
|
||||||
(cond
|
(cond
|
||||||
[(null? ls) #f]
|
[(null? ls) #f]
|
||||||
[(pred (car ls)) (car ls)]
|
[(pred (car ls)) (car ls)]
|
||||||
|
@ -45,8 +65,7 @@
|
||||||
(error 'install-library "~s is already installed" name))
|
(error 'install-library "~s is already installed" name))
|
||||||
(let ([lib (make-library id name ver imp-lib* vis-lib* inv-lib*
|
(let ([lib (make-library id name ver imp-lib* vis-lib* inv-lib*
|
||||||
exp-subst exp-env visit-code invoke-code)])
|
exp-subst exp-env visit-code invoke-code)])
|
||||||
(set! *all-libraries* (cons lib *all-libraries*))
|
((lm:current-library-collection) lib))))
|
||||||
)))
|
|
||||||
|
|
||||||
(define scheme-env ; the-env
|
(define scheme-env ; the-env
|
||||||
'([define define-label (define)]
|
'([define define-label (define)]
|
||||||
|
@ -491,10 +510,11 @@
|
||||||
[imported-label->binding imported-label->binding-label (core-prim . imported-label->binding)]
|
[imported-label->binding imported-label->binding-label (core-prim . imported-label->binding)]
|
||||||
[imported-loc->library imported-loc->library-label (core-prim . imported-loc->library)]
|
[imported-loc->library imported-loc->library-label (core-prim . imported-loc->library)]
|
||||||
[library-spec library-spec-label (core-prim . library-spec)]
|
[library-spec library-spec-label (core-prim . library-spec)]
|
||||||
|
[current-library-collection current-library-collection-label (core-prim . current-library-collection)]
|
||||||
[invoke-library invoke-library-label (core-prim . invoke-library)]
|
[invoke-library invoke-library-label (core-prim . invoke-library)]
|
||||||
))
|
))
|
||||||
(define (lm:imported-label->binding lab)
|
(define (lm:imported-label->binding lab)
|
||||||
(let f ([ls *all-libraries*])
|
(let f ([ls ((lm:current-library-collection))])
|
||||||
(cond
|
(cond
|
||||||
[(null? ls) #f]
|
[(null? ls) #f]
|
||||||
[(assq lab (library-env (car ls))) => cdr]
|
[(assq lab (library-env (car ls))) => cdr]
|
||||||
|
@ -508,7 +528,7 @@
|
||||||
(or (and (eq? (car binding) 'global)
|
(or (and (eq? (car binding) 'global)
|
||||||
(eq? (cdr binding) loc))
|
(eq? (cdr binding) loc))
|
||||||
(loc-in-env? (cdr ls)))))))
|
(loc-in-env? (cdr ls)))))))
|
||||||
(let f ([ls *all-libraries*])
|
(let f ([ls ((lm:current-library-collection))])
|
||||||
(cond
|
(cond
|
||||||
[(null? ls) #f]
|
[(null? ls) #f]
|
||||||
[(loc-in-env? (library-env (car ls))) (car ls)]
|
[(loc-in-env? (library-env (car ls))) (car ls)]
|
||||||
|
@ -541,7 +561,7 @@
|
||||||
void void))
|
void void))
|
||||||
|
|
||||||
(primitive-set! 'installed-libraries
|
(primitive-set! 'installed-libraries
|
||||||
(lambda () *all-libraries*))
|
(lambda () ((lm:current-library-collection))))
|
||||||
(primitive-set! 'library-subst/env
|
(primitive-set! 'library-subst/env
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(unless (library? x)
|
(unless (library? x)
|
||||||
|
@ -556,5 +576,6 @@
|
||||||
(primitive-set! 'imported-label->binding lm:imported-label->binding)
|
(primitive-set! 'imported-label->binding lm:imported-label->binding)
|
||||||
(primitive-set! 'imported-loc->library lm:imported-loc->library)
|
(primitive-set! 'imported-loc->library lm:imported-loc->library)
|
||||||
(primitive-set! 'invoke-library lm:invoke-library)
|
(primitive-set! 'invoke-library lm:invoke-library)
|
||||||
|
(primitive-set! 'current-library-collection lm:current-library-collection)
|
||||||
(primitive-set! 'install-library lm:install-library))
|
(primitive-set! 'install-library lm:install-library))
|
||||||
|
|
||||||
|
|
|
@ -2018,7 +2018,7 @@
|
||||||
(map build-export lex*)
|
(map build-export lex*)
|
||||||
(chi-expr* init* r mr))))])
|
(chi-expr* init* r mr))))])
|
||||||
(let-values ([(export-subst export-env)
|
(let-values ([(export-subst export-env)
|
||||||
(find-exports rib r exp-int* exp-ext*)])
|
(find-exports exp-int* exp-ext* rib r)])
|
||||||
(values
|
(values
|
||||||
name imp* (rtc)
|
name imp* (rtc)
|
||||||
(build-letrec no-source lex* rhs* body)
|
(build-letrec no-source lex* rhs* body)
|
||||||
|
@ -2027,10 +2027,6 @@
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(let-values ([(name imp* run* invoke-code export-subst export-env)
|
(let-values ([(name imp* run* invoke-code export-subst export-env)
|
||||||
(core-library-expander x)])
|
(core-library-expander x)])
|
||||||
;;; we need: name/ver/id,
|
|
||||||
;;; imports, visit, invoke name/ver/id
|
|
||||||
;;; export-subst, export-env
|
|
||||||
;;; visit-code, invoke-code
|
|
||||||
(let ([id (gensym)]
|
(let ([id (gensym)]
|
||||||
[name name]
|
[name name]
|
||||||
[ver '()] ;;; FIXME
|
[ver '()] ;;; FIXME
|
||||||
|
@ -2050,22 +2046,7 @@
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
;;; exports use the same gensym
|
;;; exports use the same gensym
|
||||||
`(#%$set-symbol-value! ',x ,x)))
|
`(#%$set-symbol-value! ',x ,x)))
|
||||||
(define find-export
|
(define (find-exports int* ext* rib r)
|
||||||
(lambda (rib r)
|
|
||||||
(lambda (sym)
|
|
||||||
(let* ([id (stx sym top-mark* (list rib))]
|
|
||||||
[label (id->label id)]
|
|
||||||
[b (label->binding label r)]
|
|
||||||
[type (binding-type b)])
|
|
||||||
(unless label
|
|
||||||
(stx-error id "cannot export unbound identifier"))
|
|
||||||
(case type
|
|
||||||
[(lexical)
|
|
||||||
;;; exports use the same gensym
|
|
||||||
(list sym label 'global (binding-value b))]
|
|
||||||
[else (error #f "cannot export ~s of type ~s" sym type)])))))
|
|
||||||
(define (find-exports rib r int* ext*)
|
|
||||||
;;; FIXME: check unique exports
|
|
||||||
(let f ([int* int*] [ext* ext*] [subst '()] [env '()])
|
(let f ([int* int*] [ext* ext*] [subst '()] [env '()])
|
||||||
(cond
|
(cond
|
||||||
[(null? int*) (values subst env)]
|
[(null? int*) (values subst env)]
|
||||||
|
|
Loading…
Reference in New Issue