mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-14 08:17:35 +02:00
Allow a program to have macros expand into a top-level import
expression.
This commit is contained in:
parent
ad4309416a
commit
d0772c2238
2 changed files with 46 additions and 3 deletions
|
@ -1,5 +1,11 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.7 - TBD
|
||||||
|
|
||||||
|
Features
|
||||||
|
|
||||||
|
- Allow a program to have macros expand into a top-level `import` expression.
|
||||||
|
|
||||||
## 0.6.3 - September 16, 2017
|
## 0.6.3 - September 16, 2017
|
||||||
|
|
||||||
Features
|
Features
|
||||||
|
|
43
cyclone.scm
43
cyclone.scm
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
; c-compile-and-emit : (string -> A) exp -> void
|
; c-compile-and-emit : (string -> A) exp -> void
|
||||||
(define (c-compile-and-emit input-program program:imports/code
|
(define (c-compile-and-emit input-program program:imports/code
|
||||||
lib-deps src-file append-dirs prepend-dirs)
|
lib-deps change-lib-deps! src-file append-dirs prepend-dirs)
|
||||||
(call/cc
|
(call/cc
|
||||||
(lambda (return)
|
(lambda (return)
|
||||||
(define globals '())
|
(define globals '())
|
||||||
|
@ -173,6 +173,36 @@
|
||||||
(trace:info "---------------- after macro expansion cleanup:")
|
(trace:info "---------------- after macro expansion cleanup:")
|
||||||
(trace:info input-program) ;pretty-print
|
(trace:info input-program) ;pretty-print
|
||||||
|
|
||||||
|
;; If a program, check to see if any macros expanded into top-level imports
|
||||||
|
(when program?
|
||||||
|
(let ((program:imports/code (import-reduction input-program (base-expander))))
|
||||||
|
(when (not (null? (car program:imports/code)))
|
||||||
|
;(trace:info "debug")
|
||||||
|
;(trace:info program:imports/code)
|
||||||
|
(trace:info "-------------- macro expanded into import expression(s):")
|
||||||
|
(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))
|
||||||
|
(trace:info "resolved imports:")
|
||||||
|
(trace:info imported-vars)
|
||||||
|
(let ((meta (lib:resolve-meta imports append-dirs prepend-dirs)))
|
||||||
|
(set! *defined-macros* (append meta *defined-macros*))
|
||||||
|
(trace:info "resolved macros:")
|
||||||
|
(trace:info meta))
|
||||||
|
(set! input-program (cdr program:imports/code))
|
||||||
|
;(set! lib-deps (append lib-deps (lib:get-all-import-deps (car program:imports/code) append-dirs prepend-dirs)))
|
||||||
|
(let ((new-lib-deps (lib:get-all-import-deps (car program:imports/code) append-dirs prepend-dirs)))
|
||||||
|
(for-each
|
||||||
|
(lambda (dep)
|
||||||
|
(if (not (member dep lib-deps))
|
||||||
|
(set! lib-deps (cons dep lib-deps))))
|
||||||
|
new-lib-deps)
|
||||||
|
(change-lib-deps! lib-deps))
|
||||||
|
(trace:info lib-deps)
|
||||||
|
)))
|
||||||
|
;; END additional top-level imports
|
||||||
|
|
||||||
;; Separate global definitions from the rest of the top-level code
|
;; Separate global definitions from the rest of the top-level code
|
||||||
(set! input-program
|
(set! input-program
|
||||||
(isolate-globals input-program program? lib-name rename-env))
|
(isolate-globals input-program program? lib-name rename-env))
|
||||||
|
@ -531,8 +561,15 @@
|
||||||
(with-output-to-file
|
(with-output-to-file
|
||||||
src-file
|
src-file
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(c-compile-and-emit program program:imports/code
|
(c-compile-and-emit
|
||||||
lib-deps in-file append-dirs prepend-dirs)))))
|
program
|
||||||
|
program:imports/code
|
||||||
|
lib-deps
|
||||||
|
(lambda (new-lib-deps)
|
||||||
|
(set! lib-deps new-lib-deps))
|
||||||
|
in-file
|
||||||
|
append-dirs
|
||||||
|
prepend-dirs)))))
|
||||||
(result (create-c-file in-prog)))
|
(result (create-c-file in-prog)))
|
||||||
|
|
||||||
;; Compile the generated C file
|
;; Compile the generated C file
|
||||||
|
|
Loading…
Add table
Reference in a new issue