mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 04:25:06 +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 util)
|
||||||
(scheme cyclone cgen)
|
(scheme cyclone cgen)
|
||||||
(scheme cyclone transforms)
|
(scheme cyclone transforms)
|
||||||
|
(scheme cyclone macros)
|
||||||
(scheme cyclone libraries))
|
(scheme cyclone libraries))
|
||||||
|
|
||||||
(cond-expand
|
(cond-expand
|
||||||
|
@ -285,7 +286,7 @@
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(display ";; This file was automatically generated by the Cyclone Scheme compiler")
|
(display ";; This file was automatically generated by the Cyclone Scheme compiler")
|
||||||
(newline)
|
(newline)
|
||||||
(write (get-macros))))
|
(write (macro:get-defined-macros))))
|
||||||
;; Compile library
|
;; Compile library
|
||||||
(let ((comp-lib-cmd
|
(let ((comp-lib-cmd
|
||||||
(string-append "gcc " src-file " -g -c -o " exec-file ".o")))
|
(string-append "gcc " src-file " -g -c -o " exec-file ".o")))
|
||||||
|
|
|
@ -4,17 +4,29 @@
|
||||||
; TODO: really need export-all for these cyclone libs!!
|
; TODO: really need export-all for these cyclone libs!!
|
||||||
(export
|
(export
|
||||||
define-syntax?
|
define-syntax?
|
||||||
macro?
|
macro:macro?
|
||||||
macro-expand
|
macro:expand
|
||||||
|
macro:add!
|
||||||
|
macro:get-defined-macros
|
||||||
)
|
)
|
||||||
(begin
|
(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
|
;; Macro section
|
||||||
;; TODO: place this in another module? could speed development
|
;; TODO: place this in another module? could speed development
|
||||||
(define (define-syntax? exp)
|
(define (define-syntax? exp)
|
||||||
(tagged-list? 'define-syntax exp))
|
(tagged-list? 'define-syntax exp))
|
||||||
|
|
||||||
(define (macro? exp defined-macros) (assoc (car exp) defined-macros))
|
(define (macro:macro? exp defined-macros) (assoc (car exp) defined-macros))
|
||||||
(define (macro-expand exp defined-macros)
|
(define (macro:expand exp defined-macros)
|
||||||
(let ((macro (assoc (car exp) defined-macros)))
|
(let ((macro (assoc (car exp) defined-macros)))
|
||||||
;; assumes ER macro
|
;; assumes ER macro
|
||||||
(if macro
|
(if macro
|
||||||
|
|
|
@ -1028,6 +1028,10 @@
|
||||||
(trans (caddr exp))
|
(trans (caddr exp))
|
||||||
(body (cadr trans)))
|
(body (cadr trans)))
|
||||||
(set! *defined-macros* (cons (cons name body) *defined-macros*))
|
(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
|
;; Keep as a 'define' form so available at runtime
|
||||||
;; TODO: may run into issues with expanding now, before some
|
;; TODO: may run into issues with expanding now, before some
|
||||||
;; of the macros are defined. may need to make a special pass
|
;; 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
|
;; (alpha, cps, closure, etc). otherwise code has to be interpreted during expansion
|
||||||
;;
|
;;
|
||||||
`(define ,name ,(expand body))))
|
`(define ,name ,(expand body))))
|
||||||
((macro? exp *defined-macros*)
|
((macro:macro? exp *defined-macros*)
|
||||||
(expand ;; Could expand into another macro
|
(expand ;; Could expand into another macro
|
||||||
(macro-expand exp *defined-macros*)))
|
(macro:expand exp *defined-macros*)))
|
||||||
(else
|
(else
|
||||||
(map expand exp))))
|
(map expand exp))))
|
||||||
(else
|
(else
|
||||||
|
|
Loading…
Add table
Reference in a new issue