Fix up lib:imports->objs and cleanup lib section

This commit is contained in:
Justin Ethier 2015-05-13 13:43:21 -04:00
parent 0ff0e2b4c7
commit cb941d8031

View file

@ -1791,7 +1791,7 @@
(cdr code)))) (cdr code))))
;; TODO: include, include-ci, cond-expand ;; TODO: include, include-ci, cond-expand
;; resolve library filename from an import ;; Resolve library filename from an import. Assumes ".sld" extension.
(define (lib:import->filename import) (define (lib:import->filename import)
(string-append (string-append
(apply (apply
@ -1801,23 +1801,30 @@
(string-append "/" (symbol->string i))) (string-append "/" (symbol->string i)))
import)) import))
".sld")) ".sld"))
;; Resolve, EG: (libs lib2) ==> lib2.o
;; Thing is though, what if a library includes another library? now the ;; Resolve a single import to its corresponding object file.
;; program needs to link to both .o files ;; EG: (libs lib2) ==> "lib2.o"
(define (lib:import->obj-file import) (define (lib:import->obj-file import)
(string-append (symbol->string (car (reverse import))) ".o")) (string-append (symbol->string (car (reverse import))) ".o"))
;; TODO: for a program import set, resolve each to their .o files, then ;; Given a program's import set, resolve each import to its .o file, then
;; process each import recursively to get the .o files that each one of those ;; process each import recursively to get the .o files that each one of those
;; libs requires. will probably need to prune duplicates from completed list. ;; libs requires. will probably need to prune duplicates from completed list.
;; longer-term, do we want to look at file timestamps to see if files need to ;; Longer-term, do we want to look at file timestamps to see if files need to
;; be recompiled? ;; be recompiled?
(define (lib:imports->objs imports basedir) (define (lib:imports->objs imports basedir)
(map (apply
(lambda (i) append
(append (lib:imports->objs (lib:read-imports i basedir)) (map
(lib:import->obj-file i))) (lambda (i)
imports)) (cons
(lib:import->obj-file i)
(lib:imports->objs (lib:read-imports i basedir) basedir)
))
imports)))
;; Given a single import from an import-set, open the corresponding
;; library file and retrieve the library's import-set.
(define (lib:read-imports import basedir) (define (lib:read-imports import basedir)
(let* ((dir (string-append basedir (lib:import->filename import))) (let* ((dir (string-append basedir (lib:import->filename import)))
(fp (open-input-file dir)) (fp (open-input-file dir))
@ -1834,6 +1841,7 @@
(exports (lib:exports (car lib)))) (exports (lib:exports (car lib))))
(close-input-port fp) (close-input-port fp)
exports)) exports))
;; Take a list of imports and resolve it to the imported vars ;; Take a list of imports and resolve it to the imported vars
(define (lib:resolve-imports imports basedir) (define (lib:resolve-imports imports basedir)
(apply (apply