From 41d7a8e876bccf505dd94a957698405f543337bd Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 29 Mar 2016 23:52:49 -0400 Subject: [PATCH] Adding import db support functions --- scheme/cyclone/libraries.sld | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/scheme/cyclone/libraries.sld b/scheme/cyclone/libraries.sld index 88dff058..3f3ceced 100644 --- a/scheme/cyclone/libraries.sld +++ b/scheme/cyclone/libraries.sld @@ -38,6 +38,9 @@ lib:resolve-meta lib:get-all-import-deps lib:get-dep-list + lib:imports->idb + lib:idb:ids + lib:idb:id->import ) (begin ; (define read cyc-read) @@ -190,6 +193,46 @@ (lib:import->export-list import)) (lib:list->import-set imports)))) +;; Take a list of imports and create a "database" from them +;; consisting of maps between each exported identifier and the +;; library that imports that identifier. An exception is raised +;; if the same identifier is exported from more than one library. +;; +;; TODO: convert this to use a hashtable. Initially a-lists +;; will be used to prove out the concept, but this is inefficient +(define (lib:imports->idb imports) + +;; TODO: build the list, then check for duplicate keys before returning + + (apply + append + (map + (lambda (import) + (foldr + (lambda (id ids) + (cons + (cons id import) + ids)) + '() + (lib:import->export-list import)) + ) + (lib:list->import-set imports)))) + +;; Convert from the import DB to a list of identifiers that are imported. +;; EG: '((call/cc . (scheme base))) ==> '(call/cc) +(define (lib:idb:ids db) + (foldr + (lambda (i is) (cons (car i) is)) + '() + db)) + +;; Map from identifier to the library that imported it +(define (lib:idb:id->import db identifier) + (let ((entry (assoc identifier db))) + (if entry + (cdr entry) + #f))) + (define (lib:import->metalist import) (let ((file (lib:import->filename import ".meta")) (fp #f)