* install-library now takes an extra visibility flag.

* installed-libraries now takes an optional "all?" flag:
  - if all? is true, it returns all libraries.
  - if all? is false, it returns only the visible libraries
  - all? defaults to #t.
This commit is contained in:
Abdulaziz Ghuloum 2007-05-07 04:52:22 -04:00
parent 4c8029ab3e
commit 8226619438
6 changed files with 69 additions and 47 deletions

Binary file not shown.

View File

@ -73,6 +73,7 @@ void ik_fasl_load(ikpcb* pcb, char* fasl_file){
bzero(p.marks, p.marks_size * sizeof(ikp*)); bzero(p.marks, p.marks_size * sizeof(ikp*));
} }
ikp val = ik_exec_code(pcb, v); ikp val = ik_exec_code(pcb, v);
val = void_object;
if(val != void_object){ if(val != void_object){
ik_print(val); ik_print(val);
} }

Binary file not shown.

View File

@ -3,7 +3,7 @@
(library (ikarus library-manager) (library (ikarus library-manager)
(export imported-label->binding library-subst (export imported-label->binding library-subst
installed-libraries installed-libraries
find-library-by-name install-library find-library-by-name install-library
library-spec invoke-library) library-spec invoke-library)
(import (except (ikarus) installed-libraries)) (import (except (ikarus) installed-libraries))
@ -30,7 +30,8 @@
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
visible?))
(define (find-dependencies ls) (define (find-dependencies ls)
(cond (cond
@ -64,28 +65,36 @@
(define label->binding-table (make-hash-table)) (define label->binding-table (make-hash-table))
(define (install-library id name ver (define install-library
imp* vis* inv* exp-subst exp-env visit-code invoke-code) (case-lambda
(let ([imp-lib* (map find-library-by-spec/die imp*)] ; [(id name ver imp* vis* inv* exp-subst exp-env
[vis-lib* (map find-library-by-spec/die vis*)] ; visit-code invoke-code)
[inv-lib* (map find-library-by-spec/die inv*)]) ; (install-library id name ver imp* vis* inv* exp-subst exp-env
(unless (and (symbol? id) (list? name) (list? ver)) ; visit-code invoke-code #t)]
(error 'install-library "invalid spec ~s ~s ~s" id name ver)) [(id name ver imp* vis* inv* exp-subst exp-env
(when (library-exists? name) visit-code invoke-code visible?)
(error 'install-library "~s is already installed" name)) (let ([imp-lib* (map find-library-by-spec/die imp*)]
(let ([lib (make-library id name ver imp-lib* vis-lib* inv-lib* [vis-lib* (map find-library-by-spec/die vis*)]
exp-subst exp-env visit-code invoke-code)]) [inv-lib* (map find-library-by-spec/die inv*)])
(for-each (unless (and (symbol? id) (list? name) (list? ver))
(lambda (x) (error 'install-library "invalid spec ~s ~s ~s" id name ver))
(let ([label (car x)] [binding (cdr x)]) (when (library-exists? name)
(let ([binding (error 'install-library "~s is already installed" name))
(case (car binding) (let ([lib (make-library id name ver imp-lib* vis-lib* inv-lib*
[(global) exp-subst exp-env visit-code invoke-code
(cons 'global (cons lib (cdr binding)))] visible?)])
[else binding])]) (for-each
(put-hash-table! label->binding-table label binding)))) (lambda (x)
exp-env) (let ([label (car x)] [binding (cdr x)])
((current-library-collection) lib)))) (let ([binding
(case (car binding)
[(global)
(cons 'global (cons lib (cdr binding)))]
[else binding])])
(put-hash-table! label->binding-table label binding))))
exp-env)
((current-library-collection) lib)
lib))]))
(define (imported-label->binding lab) (define (imported-label->binding lab)
(get-hash-table label->binding-table lab #f)) (get-hash-table label->binding-table lab #f))
@ -105,7 +114,16 @@
(invoke-library (find-library-by-spec/die spec))) (invoke-library (find-library-by-spec/die spec)))
(define installed-libraries (define installed-libraries
(lambda () ((current-library-collection)))) (case-lambda
[(all?)
(let f ([ls ((current-library-collection))])
(cond
[(null? ls) '()]
[(or all? (library-visible? (car ls)))
(cons (car ls) (f (cdr ls)))]
[else (f (cdr ls))]))]
[() (installed-libraries #f)]))
(define library-spec (define library-spec
(lambda (x) (lambda (x)
(unless (library? x) (unless (library? x)

View File

@ -2166,7 +2166,8 @@
(install-library id name ver (install-library id name ver
imp* vis* inv* export-subst export-env imp* vis* inv* export-subst export-env
void ;;; FIXME void ;;; FIXME
(lambda () (eval-core invoke-code))) (lambda () (eval-core invoke-code))
#t)
(values invoke-code export-subst export-env)))) (values invoke-code export-subst export-env))))
(define (boot-library-expand x) (define (boot-library-expand x)
(let-values ([(invoke-code export-subst export-env) (let-values ([(invoke-code export-subst export-env)

View File

@ -97,25 +97,25 @@
[or (macro . or)])) [or (macro . or)]))
(define library-legend (define library-legend
'([i (ikarus)] '([i (ikarus) #t]
[r (r6rs)] [r (r6rs) #t]
[$all (ikarus system $all)] [$all (ikarus system $all) #f]
[$pairs (ikarus system $pairs)] [$pairs (ikarus system $pairs) #f]
[$lists (ikarus system $lists)] [$lists (ikarus system $lists) #f]
[$chars (ikarus system $chars)] [$chars (ikarus system $chars) #f]
[$strings (ikarus system $strings)] [$strings (ikarus system $strings) #f]
[$vectors (ikarus system $vectors)] [$vectors (ikarus system $vectors) #f]
[$fx (ikarus system $fx)] [$fx (ikarus system $fx) #f]
[$symbols (ikarus system $symbols)] [$symbols (ikarus system $symbols) #f]
[$records (ikarus system $records)] [$records (ikarus system $records) #f]
[$ports (ikarus system $ports)] [$ports (ikarus system $ports) #f]
[$codes (ikarus system $codes)] [$codes (ikarus system $codes) #f]
[$tcbuckets (ikarus system $tcbuckets)] [$tcbuckets (ikarus system $tcbuckets) #f]
[$io (ikarus system $io)] [$io (ikarus system $io) #f]
[$arg-list (ikarus system $arg-list)] [$arg-list (ikarus system $arg-list) #f]
[$stack (ikarus system $stack)] [$stack (ikarus system $stack) #f]
[$interrupts (ikarus system $interrupts)] [$interrupts (ikarus system $interrupts) #f]
[$boot (ikarus system $bootstrap)] [$boot (ikarus system $bootstrap) #f]
)) ))
(define ikarus-macros-map (define ikarus-macros-map
@ -629,7 +629,9 @@
(define (build-system-library export-subst export-env primlocs) (define (build-system-library export-subst export-env primlocs)
(define (build-library legend-entry) (define (build-library legend-entry)
(let ([key (car legend-entry)] [name (cadr legend-entry)]) (let ([key (car legend-entry)]
[name (cadr legend-entry)]
[visible? (caddr legend-entry)])
(let ([id (gensym)] (let ([id (gensym)]
[name name] [name name]
[version '()] [version '()]
@ -644,7 +646,7 @@
'()))]) '()))])
`(install-library `(install-library
',id ',name ',version ',import-libs ',visit-libs ',invoke-libs ',id ',name ',version ',import-libs ',visit-libs ',invoke-libs
',subst ',env void void))))) ',subst ',env void void ',visible?)))))
(let ([code `(library (ikarus primlocs) (let ([code `(library (ikarus primlocs)
(export) ;;; must be empty (export) ;;; must be empty
(import (import