mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
Only add newly-defined macros to meta files
This commit is contained in:
parent
a82a34f964
commit
52894f0f29
3 changed files with 24 additions and 7 deletions
|
@ -12,6 +12,7 @@
|
|||
(scheme cyclone util)
|
||||
(scheme cyclone cgen)
|
||||
(scheme cyclone transforms)
|
||||
(scheme cyclone macros)
|
||||
(scheme cyclone libraries))
|
||||
|
||||
(cond-expand
|
||||
|
@ -285,7 +286,7 @@
|
|||
(lambda ()
|
||||
(display ";; This file was automatically generated by the Cyclone Scheme compiler")
|
||||
(newline)
|
||||
(write (get-macros))))
|
||||
(write (macro:get-defined-macros))))
|
||||
;; Compile library
|
||||
(let ((comp-lib-cmd
|
||||
(string-append "gcc " src-file " -g -c -o " exec-file ".o")))
|
||||
|
|
|
@ -4,17 +4,29 @@
|
|||
; TODO: really need export-all for these cyclone libs!!
|
||||
(export
|
||||
define-syntax?
|
||||
macro?
|
||||
macro-expand
|
||||
macro:macro?
|
||||
macro:expand
|
||||
macro:add!
|
||||
macro:get-defined-macros
|
||||
)
|
||||
(begin
|
||||
;; A list of all macros defined by the program/library being compiled
|
||||
(define *macro:defined-macros* '())
|
||||
|
||||
(define (macro:add! name body)
|
||||
(set! *macro:defined-macros*
|
||||
(cons (cons name body) *macro:defined-macros*))
|
||||
#t)
|
||||
|
||||
(define (macro:get-defined-macros) *macro:defined-macros*)
|
||||
|
||||
;; Macro section
|
||||
;; TODO: place this in another module? could speed development
|
||||
(define (define-syntax? exp)
|
||||
(tagged-list? 'define-syntax exp))
|
||||
|
||||
(define (macro? exp defined-macros) (assoc (car exp) defined-macros))
|
||||
(define (macro-expand exp defined-macros)
|
||||
(define (macro:macro? exp defined-macros) (assoc (car exp) defined-macros))
|
||||
(define (macro:expand exp defined-macros)
|
||||
(let ((macro (assoc (car exp) defined-macros)))
|
||||
;; assumes ER macro
|
||||
(if macro
|
||||
|
|
|
@ -1028,6 +1028,10 @@
|
|||
(trans (caddr exp))
|
||||
(body (cadr trans)))
|
||||
(set! *defined-macros* (cons (cons name body) *defined-macros*))
|
||||
;; Keep track of macros added during compilation.
|
||||
;; Previous list should eventually go away once macros are
|
||||
;; moved from that static list to libraries
|
||||
(macro:add! name body)
|
||||
;; Keep as a 'define' form so available at runtime
|
||||
;; TODO: may run into issues with expanding now, before some
|
||||
;; of the macros are defined. may need to make a special pass
|
||||
|
@ -1039,9 +1043,9 @@
|
|||
;; (alpha, cps, closure, etc). otherwise code has to be interpreted during expansion
|
||||
;;
|
||||
`(define ,name ,(expand body))))
|
||||
((macro? exp *defined-macros*)
|
||||
((macro:macro? exp *defined-macros*)
|
||||
(expand ;; Could expand into another macro
|
||||
(macro-expand exp *defined-macros*)))
|
||||
(macro:expand exp *defined-macros*)))
|
||||
(else
|
||||
(map expand exp))))
|
||||
(else
|
||||
|
|
Loading…
Add table
Reference in a new issue