From 233d166e02ae3090bfa48d576ccd4733b9f15345 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Mon, 10 Aug 2015 22:51:57 -0400 Subject: [PATCH] Compiling macros to C --- scheme/cyclone/transforms.sld | 8 +++++++- test2.scm | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/scheme/cyclone/transforms.sld b/scheme/cyclone/transforms.sld index d2fae9b7..3ea46750 100644 --- a/scheme/cyclone/transforms.sld +++ b/scheme/cyclone/transforms.sld @@ -24,6 +24,7 @@ *do-code-gen* *trace-level* *primitives* + get-macros built-in-syms trace trace:error @@ -135,6 +136,7 @@ ;; Built-in macros ;; TODO: just a stub, real code would read (define-syntax) ;; from a lib file or such +(define (get-macros) *defined-macros*) (define *defined-macros* (list (cons 'and @@ -1025,7 +1027,11 @@ (trans (caddr exp)) (body (cadr trans))) (set! *defined-macros* (cons (cons name body) *defined-macros*)) - #t)) + ;; 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 + ;; to do loading or expansion of macro bodies + `(define ,name ,(expand body)))) ((macro? exp *defined-macros*) (expand ;; Could expand into another macro (macro-expand exp *defined-macros*))) diff --git a/test2.scm b/test2.scm index 30a9e7c6..ba36d55e 100644 --- a/test2.scm +++ b/test2.scm @@ -5,6 +5,7 @@ ; ; (import (scheme base) + (scheme eval) (scheme write)) ;(define-syntax test @@ -42,3 +43,8 @@ (write (or #f 2 3 'or)) ;(test 'done) 'done + +(define x 1) +(write x) +(write + (eval 'x))