Added (lib:includes ast)

This commit is contained in:
Justin Ethier 2015-05-14 14:25:32 -04:00
parent e29511cc99
commit dd955d9b2f

View file

@ -7,50 +7,8 @@
;; various utility functions used by the compiler. ;; various utility functions used by the compiler.
;; ;;
(define *version* "0.0.1 (Pre-release)") (load (string-append (cyc:get-lib-dir) "scheme/cyclone.scm"))
(define *version-banner*
(string-append "
:@
@@@
@@@@:
`@@@@@+
.@@@+@@@ Cyclone
@@ @@ An experimental Scheme compiler
,@ https://github.com/justinethier/cyclone
'@
.@
@@ #@ (c) 2014 Justin Ethier
`@@@#@@@. Version " *version* "
#@@@@@
+@@@+
@@#
`@.
"))
(define *c-file-header-comment*
(string-append "/**
** This file was automatically generated by the Cyclone scheme compiler
**
** (c) 2014 Justin Ethier
** Version " *version* "
**
**/
"))
;; Features implemented by this Scheme
(define *features* '(cyclone))
;; Built-in functions
;; TODO: relocate these somewhere else, like a lib.scm!!!
;; TODO: Longer-term, we will want to insert all these but then have an
;; algorithm in place to remove the definitions that are not used.
;; Basically, after the expansion phase but before alpha conversion,
;; there should be enough information to figure out what is unused, and
;; discard it. Obviously this may be a no-go in certain situations, such
;; as if a (read (eval)) REPL is present. Although maybe not, since that
;; would use the interpreter.
(define *built-ins* `( (define *built-ins* `(
(define *Cyc-version-banner* ,*version-banner*) (define *Cyc-version-banner* ,*version-banner*)
;; TODO: The whitespace characters are space, tab, line feed, form feed (not in parser yet), and carriage return. ;; TODO: The whitespace characters are space, tab, line feed, form feed (not in parser yet), and carriage return.
@ -1777,6 +1735,10 @@
;; Helper function that returns an empty list as a default value ;; Helper function that returns an empty list as a default value
(define (lib:result result) (define (lib:result result)
(if result result '())) (if result result '()))
;; TODO: most of these below assume 0 or 1 instances of the directive.
;; may need to replace some of these later with filter operations to
;; support more than 1 instance.
(define (lib:exports ast) (define (lib:exports ast)
(lib:result (lib:result
(and-let* ((code (assoc 'export (cddr ast)))) (and-let* ((code (assoc 'export (cddr ast))))
@ -1789,7 +1751,16 @@
(lib:result (lib:result
(and-let* ((code (assoc 'begin (cddr ast)))) (and-let* ((code (assoc 'begin (cddr ast))))
(cdr code)))) (cdr code))))
;; TODO: include, include-ci, cond-expand (define (lib:includes ast)
(map
(lambda (inc-lst)
(cadr inc-lst))
(filter
(lambda (code)
(tagged-list? 'include code))
(cddr ast))))
;; TODO: include-ci, cond-expand
;; Resolve library filename given an import. ;; Resolve library filename given an import.
;; Assumes ".sld" file extension if one is not specified. ;; Assumes ".sld" file extension if one is not specified.
@ -1798,7 +1769,7 @@
(if (null? ext) (if (null? ext)
".sld" ".sld"
(car ext))) (car ext)))
(filename (filename*
(string-append (string-append
(apply (apply
string-append string-append
@ -1806,8 +1777,12 @@
(lambda (i) (lambda (i)
(string-append "/" (symbol->string i))) (string-append "/" (symbol->string i)))
import)) import))
file-ext))) file-ext))
(substring filename 1 (string-length filename)))) (filename
(substring filename* 1 (string-length filename*))))
(if (tagged-list? 'scheme import)
(string-append (cyc:get-lib-dir filename)) ;; Built-in library
filename)))
; !!!!!!!!!!!!!!!!!!!!!!!! ; !!!!!!!!!!!!!!!!!!!!!!!!
;TODO: all this basedir stuff below is silly. all we need is a way of saying OK, this ;TODO: all this basedir stuff below is silly. all we need is a way of saying OK, this