This commit is contained in:
Justin Ethier 2016-10-06 18:43:26 -04:00
parent 1293b5fc8e
commit c5f9ffb5dd
2 changed files with 22 additions and 10 deletions

View file

@ -11,13 +11,13 @@
;;; > huski life.scm ;;; > huski life.scm
;;; ;;;
(import (scheme base) (import (scheme base)
(example life) ; (example life)
(example grid)) (example grid)
;; TODO: ;; TODO:
; (only (example life) life) (only (example life) life)
; (rename (prefix (example grid) grid-) ; (rename (prefix (example grid) grid-)
; (grid-make make-grid))) ; (grid-make make-grid)))
)
;; Initialize a grid with a glider. ;; Initialize a grid with a glider.
;(define grid (make-grid 24 24)) ;(define grid (make-grid 24 24))
;(grid-put! grid 1 1 #t) ;(grid-put! grid 1 1 #t)

View file

@ -31,6 +31,7 @@
lib:body lib:body
lib:includes lib:includes
lib:include-c-headers lib:include-c-headers
lib:import->library-name
lib:import->filename lib:import->filename
lib:import->metalist lib:import->metalist
lib:import->path lib:import->path
@ -67,7 +68,7 @@
;; Convert name (as list of symbols) to a mangled string ;; Convert name (as list of symbols) to a mangled string
(define (lib:name->string name) (define (lib:name->string name)
(apply string-append (map mangle name))) (apply string-append (map mangle (lib:import->library-name name))))
;; Convert library name to a unique symbol ;; Convert library name to a unique symbol
(define (lib:name->symbol name) (define (lib:name->symbol name)
@ -194,16 +195,26 @@
;; Given a single import from an import-set, open the corresponding ;; Given a single import from an import-set, open the corresponding
;; library file and retrieve the library's import-set. ;; library file and retrieve the library's import-set.
(define (lib:read-imports import) (define (lib:read-imports import)
(let* ((dir (lib:import->filename import)) (let* ((lib-name (lib:import->library-name import))
(dir (lib:import->filename lib-name))
(fp (open-input-file dir)) (fp (open-input-file dir))
(lib (read-all fp)) (lib (read-all fp))
(imports (lib:imports (car lib)))) (imports (lib:imports (car lib))))
(close-input-port fp) (close-input-port fp)
imports)) imports))
(define (lib:import->library-name import)
(cond
((or (tagged-list? 'only import)
(tagged-list? 'except import))
(cadr import))
(else
import)))
;; Read export list for a given import ;; Read export list for a given import
(define (lib:import->export-list import) (define (lib:import->export-list import)
(let* ((dir (string-append (lib:import->filename import))) (let* ((lib-name (lib:import->library-name import))
(dir (string-append (lib:import->filename lib-name)))
(fp (open-input-file dir)) (fp (open-input-file dir))
(lib (read-all fp)) (lib (read-all fp))
(exports (lib:exports (car lib)))) (exports (lib:exports (car lib))))
@ -259,7 +270,8 @@
#f))) #f)))
(define (lib:import->metalist import) (define (lib:import->metalist import)
(let ((file (lib:import->filename import ".meta")) (let* ((lib-name (lib:import->library-name import))
(file (lib:import->filename lib-name ".meta"))
(fp #f) (fp #f)
(result '())) (result '()))
(cond (cond