mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 04:25:06 +02:00
WIP
This commit is contained in:
parent
f2ec269573
commit
d3c270e8e6
2 changed files with 68 additions and 12 deletions
|
@ -12,11 +12,11 @@
|
||||||
;;;
|
;;;
|
||||||
(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))
|
||||||
|
|
|
@ -31,13 +31,16 @@
|
||||||
lib:body
|
lib:body
|
||||||
lib:includes
|
lib:includes
|
||||||
lib:include-c-headers
|
lib:include-c-headers
|
||||||
|
lib:import-set:library-name?
|
||||||
|
lib:import-set->import-set
|
||||||
lib:import->library-name
|
lib:import->library-name
|
||||||
lib:import->filename
|
lib:import->filename
|
||||||
lib:import->metalist
|
lib:import->metalist
|
||||||
lib:import->path
|
lib:import->path
|
||||||
lib:read-imports
|
lib:read-imports
|
||||||
lib:import->export-list
|
lib:import->export-list
|
||||||
lib:resolve-imports
|
lib:import-set/exports->imports
|
||||||
|
;lib:resolve-imports
|
||||||
lib:resolve-meta
|
lib:resolve-meta
|
||||||
lib:get-all
|
lib:get-all
|
||||||
lib:get-all-import-deps
|
lib:get-all-import-deps
|
||||||
|
@ -68,6 +71,19 @@
|
||||||
(define (lib:name ast)
|
(define (lib:name ast)
|
||||||
(lib:list->import-set (cadr ast)))
|
(lib:list->import-set (cadr ast)))
|
||||||
|
|
||||||
|
;; Is import set just a library name?
|
||||||
|
(define (lib:import-set:library-name? import-set)
|
||||||
|
(not
|
||||||
|
(or (tagged-list? 'only import-set)
|
||||||
|
(tagged-list? 'except import-set)
|
||||||
|
(tagged-list? 'prefix import-set)
|
||||||
|
(tagged-list? 'rename import-set))))
|
||||||
|
|
||||||
|
;; lib:import-set->import-set -> list -> list
|
||||||
|
;; Extract next import set from given input set
|
||||||
|
(define (lib:import-set->import-set import-set)
|
||||||
|
(cadr import-set))
|
||||||
|
|
||||||
;; Convert an import-set to its corresponding library name.
|
;; Convert an import-set to its corresponding library name.
|
||||||
;; These are not always the same thing, but each import-set
|
;; These are not always the same thing, but each import-set
|
||||||
;; does reference a specific library.
|
;; does reference a specific library.
|
||||||
|
@ -82,7 +98,6 @@
|
||||||
(else
|
(else
|
||||||
import)))
|
import)))
|
||||||
|
|
||||||
|
|
||||||
;; 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 (lib:import->library-name name))))
|
(apply string-append (map mangle (lib:import->library-name name))))
|
||||||
|
@ -228,6 +243,8 @@
|
||||||
(lib (read-all fp))
|
(lib (read-all fp))
|
||||||
(exports (lib:exports (car lib))))
|
(exports (lib:exports (car lib))))
|
||||||
(close-input-port fp)
|
(close-input-port fp)
|
||||||
|
;; TODO: don't even both with below and call this instead:
|
||||||
|
;;(define (lib:import-set/exports->imports import-set exports)
|
||||||
(cond
|
(cond
|
||||||
;; TODO: how to handle these recursively? IE: import set could be
|
;; TODO: how to handle these recursively? IE: import set could be
|
||||||
;; a rename that has a prefix that has a library name
|
;; a rename that has a prefix that has a library name
|
||||||
|
@ -242,20 +259,59 @@
|
||||||
(lambda (sym)
|
(lambda (sym)
|
||||||
(not (member sym (cddr import))))
|
(not (member sym (cddr import))))
|
||||||
exports))
|
exports))
|
||||||
|
|
||||||
;; TODO: if prefix or rename, can resolve to original lib identifier.
|
;; TODO: if prefix or rename, can resolve to original lib identifier.
|
||||||
;; would need another function somewhere to compute the renames though.
|
;; would need another function somewhere to compute the renames though.
|
||||||
;; maybe compute both and return a list of both???
|
;; maybe compute both and return a list of both???
|
||||||
(else
|
(else
|
||||||
exports))))
|
exports))))
|
||||||
|
|
||||||
|
;; Take an import set and the corresponding list of exports. Process all of the
|
||||||
|
;; import set directives (only, except, rename, prefix) and return a list of:
|
||||||
|
;; - identifiers to import
|
||||||
|
;; - renames: identifiers that will be imported using a different name
|
||||||
|
(define (lib:import-set/exports->imports import-set exports)
|
||||||
|
;; TODO: how to handle if a var is renamed more than once? really just want one mapping from lib-var-name => renamed-var-name
|
||||||
|
|
||||||
|
;; TODO: if import-set is not library name, recursively process it, then deal with results here
|
||||||
|
; (unless (lib:import-set:library-name? import-set)
|
||||||
|
; (let ((result (lib:import-set/exports->imports
|
||||||
|
; (lib:import-set->import-set import-set)
|
||||||
|
; exports)))
|
||||||
|
; ;; TODO: (set! ?? result)))
|
||||||
|
|
||||||
|
(cond
|
||||||
|
((tagged-list? 'only import-set)
|
||||||
|
;; Filter to symbols from "only" that appear in export list
|
||||||
|
(filter
|
||||||
|
(lambda (sym)
|
||||||
|
(member sym exports))
|
||||||
|
(cddr import-set)))
|
||||||
|
((tagged-list? 'except import-set)
|
||||||
|
(filter
|
||||||
|
(lambda (sym)
|
||||||
|
(not (member sym (cddr import-set))))
|
||||||
|
exports))
|
||||||
|
;;((tagged-list? 'prefix import-set)
|
||||||
|
;; same as rename, but add given prefix to all exports
|
||||||
|
|
||||||
|
;;((tagged-list? 'rename import-set)
|
||||||
|
;; for each rename
|
||||||
|
;; let's keep it simple and replace "ident" in exports with
|
||||||
|
;; the mapping "(ident rename)". of course, that punts the
|
||||||
|
;; job of dealing with the rename back to the caller, but
|
||||||
|
;; I think that will be OK.
|
||||||
|
(else
|
||||||
|
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)
|
;(define (lib:resolve-imports imports)
|
||||||
(apply
|
; (apply
|
||||||
append
|
; append
|
||||||
(map
|
; (map
|
||||||
(lambda (import)
|
; (lambda (import)
|
||||||
(lib:import->export-list import))
|
; (lib:import->export-list import))
|
||||||
(map lib:list->import-set imports))))
|
; (map lib:list->import-set imports))))
|
||||||
|
|
||||||
;; Take a list of imports and create a "database" from them
|
;; Take a list of imports and create a "database" from them
|
||||||
;; consisting of maps between each exported identifier and the
|
;; consisting of maps between each exported identifier and the
|
||||||
|
|
Loading…
Add table
Reference in a new issue