diff --git a/cyclone.scm b/cyclone.scm index 252b4d17..4985cc6b 100644 --- a/cyclone.scm +++ b/cyclone.scm @@ -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"))) diff --git a/scheme/cyclone/macros.sld b/scheme/cyclone/macros.sld index a1dc40d6..cb0e59c5 100644 --- a/scheme/cyclone/macros.sld +++ b/scheme/cyclone/macros.sld @@ -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 diff --git a/scheme/cyclone/transforms.sld b/scheme/cyclone/transforms.sld index aeb95186..4d874417 100644 --- a/scheme/cyclone/transforms.sld +++ b/scheme/cyclone/transforms.sld @@ -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