Issue #412 - Fix expand within a cond-expand

Allow these dependencies to be recognized by Cyclone.
This commit is contained in:
Justin Ethier 2020-09-28 13:32:13 -04:00
parent f0bf9fc1d4
commit 6a1377178a
5 changed files with 22 additions and 17 deletions

View file

@ -5,6 +5,9 @@
Bug Fixes Bug Fixes
- The compiler now displays a helpful error message to the user when compilation of a program fails due to an error building a dependent library. - The compiler now displays a helpful error message to the user when compilation of a program fails due to an error building a dependent library.
- Enhanced `cond-expand` support in a library declaration to
- Properly handle cases where there is more than one `cond-expand` sub-expression. EG: two `begin` expressions, a `begin` / `import`, etc.
- Properly handle the case where `export` is defined by `cond-expand`. Previously such exports would not be recognized by code importing the library.
## 0.21 - September 17, 2020 ## 0.21 - September 17, 2020

View file

@ -182,7 +182,7 @@
(report:elapsed "imports:") (report:elapsed "imports:")
(trace:info "imports:") (trace:info "imports:")
(trace:info imports) (trace:info imports)
(set! imported-vars (lib:imports->idb imports append-dirs prepend-dirs)) (set! imported-vars (lib:imports->idb imports append-dirs prepend-dirs (base-expander)))
(report:elapsed "resolved imports:") (report:elapsed "resolved imports:")
(trace:info "resolved imports:") (trace:info "resolved imports:")
(trace:info imported-vars) (trace:info imported-vars)
@ -245,7 +245,7 @@
(set! imports (append imports (car program:imports/code))) (set! imports (append imports (car program:imports/code)))
(trace:info "imports:") (trace:info "imports:")
(trace:info imports) (trace:info imports)
(set! imported-vars (lib:imports->idb imports append-dirs prepend-dirs)) (set! imported-vars (lib:imports->idb imports append-dirs prepend-dirs (base-expander)))
(report:elapsed "resolved imports:") (report:elapsed "resolved imports:")
(trace:info "resolved imports:") (trace:info "resolved imports:")
(trace:info imported-vars) (trace:info imported-vars)

View file

@ -1,7 +1,10 @@
; Example from draft 6 of R7RS ; Example from draft 6 of R7RS
(define-library (example grid) (define-library (example grid)
(cond-expand
(cyclone
(export make rows cols ref each (export make rows cols ref each
put!) ;(rename put! set!)) put!) ;(rename put! set!))
))
(import (scheme base)) (import (scheme base))
(begin (begin
;; Create an NxM grid. ;; Create an NxM grid.

View file

@ -1,21 +1,17 @@
(define-library (example life) (define-library (example life)
(import (except (scheme base) set!) (import (except (scheme base) set!))
; (scheme write)
; (example grid)
)
(cond-expand (cond-expand
(cyclone (cyclone
(import (scheme write)) (import (scheme write))
; ))
; (cond-expand
; (cyclone
(import (example grid)) (import (example grid))
))
))
;(cond-expand (cond-expand
; (cyclone (cyclone
(export life) (export life)
;)) ))
(cond-expand (cond-expand
(cyclone (cyclone
(begin (begin

View file

@ -440,12 +440,15 @@
" ")) " "))
;; Read export list for a given import ;; Read export list for a given import
(define (lib:import->export-list import append-dirs prepend-dirs) (define (lib:import->export-list import append-dirs prepend-dirs expander)
(let* ((lib-name (lib:import->library-name import)) (let* ((lib-name (lib:import->library-name import))
(dir (string-append (lib:import->filename lib-name ".sld" append-dirs prepend-dirs))) (dir (string-append (lib:import->filename lib-name ".sld" append-dirs prepend-dirs)))
(fp (open-input-file dir)) (fp (open-input-file dir))
(lib (read-all fp)) (lib (read-all fp))
(exports (lib:exports (car lib)))) (lib* (if expander
(list (lib:cond-expand (car lib) expander))
lib))
(exports (lib:exports (car lib*))))
(close-input-port fp) (close-input-port fp)
(lib:import-set/exports->imports import exports))) (lib:import-set/exports->imports import exports)))
@ -551,7 +554,7 @@
;; ;;
;; TODO: convert this to use a hashtable. Initially a-lists ;; TODO: convert this to use a hashtable. Initially a-lists
;; will be used to prove out the concept, but this is inefficient ;; will be used to prove out the concept, but this is inefficient
(define (lib:imports->idb imports append-dirs prepend-dirs) (define (lib:imports->idb imports append-dirs prepend-dirs expander)
(apply (apply
append append
(map (map
@ -563,7 +566,7 @@
(cons id lib-name) (cons id lib-name)
ids)) ids))
'() '()
(lib:import->export-list import-set append-dirs prepend-dirs)))) (lib:import->export-list import-set append-dirs prepend-dirs expander))))
(map lib:list->import-set imports)))) (map lib:list->import-set imports))))
;; Convert from the import DB to a list of identifiers that are imported. ;; Convert from the import DB to a list of identifiers that are imported.