From 6a1377178a143b288275c6d61ff21259bba40ee5 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Mon, 28 Sep 2020 13:32:13 -0400 Subject: [PATCH] Issue #412 - Fix expand within a cond-expand Allow these dependencies to be recognized by Cyclone. --- CHANGELOG.md | 3 +++ cyclone.scm | 4 ++-- examples/game-of-life/example/grid.sld | 3 +++ examples/game-of-life/example/life.sld | 18 +++++++----------- scheme/cyclone/libraries.sld | 11 +++++++---- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abf9c5b7..3655d32d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ 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. +- 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 diff --git a/cyclone.scm b/cyclone.scm index a2030c48..45248a58 100644 --- a/cyclone.scm +++ b/cyclone.scm @@ -182,7 +182,7 @@ (report:elapsed "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:") (trace:info "resolved imports:") (trace:info imported-vars) @@ -245,7 +245,7 @@ (set! imports (append imports (car program:imports/code))) (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:") (trace:info "resolved imports:") (trace:info imported-vars) diff --git a/examples/game-of-life/example/grid.sld b/examples/game-of-life/example/grid.sld index cfefb242..52a9431a 100644 --- a/examples/game-of-life/example/grid.sld +++ b/examples/game-of-life/example/grid.sld @@ -1,7 +1,10 @@ ; Example from draft 6 of R7RS (define-library (example grid) + (cond-expand + (cyclone (export make rows cols ref each put!) ;(rename put! set!)) + )) (import (scheme base)) (begin ;; Create an NxM grid. diff --git a/examples/game-of-life/example/life.sld b/examples/game-of-life/example/life.sld index 86780dd0..0b87f0cc 100644 --- a/examples/game-of-life/example/life.sld +++ b/examples/game-of-life/example/life.sld @@ -1,21 +1,17 @@ (define-library (example life) - (import (except (scheme base) set!) - ; (scheme write) - ; (example grid) - ) + (import (except (scheme base) set!)) (cond-expand (cyclone (import (scheme write)) -; )) -; (cond-expand -; (cyclone (import (example grid)) - )) + + )) - ;(cond-expand - ; (cyclone + (cond-expand + (cyclone (export life) - ;)) + )) + (cond-expand (cyclone (begin diff --git a/scheme/cyclone/libraries.sld b/scheme/cyclone/libraries.sld index 8d690bf7..ef73f487 100644 --- a/scheme/cyclone/libraries.sld +++ b/scheme/cyclone/libraries.sld @@ -440,12 +440,15 @@ " ")) ;; 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)) (dir (string-append (lib:import->filename lib-name ".sld" append-dirs prepend-dirs))) (fp (open-input-file dir)) (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) (lib:import-set/exports->imports import exports))) @@ -551,7 +554,7 @@ ;; ;; 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 append-dirs prepend-dirs) +(define (lib:imports->idb imports append-dirs prepend-dirs expander) (apply append (map @@ -563,7 +566,7 @@ (cons id lib-name) 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)))) ;; Convert from the import DB to a list of identifiers that are imported.