From 65529629d5c2b720704d1f0732e8715677badb2b Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 11 Feb 2016 22:31:09 -0500 Subject: [PATCH] Beginnings of syntax-rules support --- scheme/cyclone/transforms.sld | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scheme/cyclone/transforms.sld b/scheme/cyclone/transforms.sld index 78845554..4e830418 100644 --- a/scheme/cyclone/transforms.sld +++ b/scheme/cyclone/transforms.sld @@ -752,6 +752,7 @@ ;TODO: modify this whole section to use macros:get-env instead of *defined-macros*. macro:get-env becomes the mac-env. any new scopes need to extend that env, and an env parameter needs to be added to (expand). any macros defined with define-syntax use that env as their mac-env (how to store that)? ; expand : exp -> exp (define (expand exp env) + ;(trace:error `(expand ,exp)) (cond ((const? exp) exp) ((prim? exp) exp) @@ -789,6 +790,12 @@ (let* ((name (cadr exp)) (trans (caddr exp)) (body (cadr trans))) + (cond + ((tagged-list? 'syntax-rules trans) ;; TODO: what if syntax-rules is renamed? + (expand + `(define-syntax ,name ,(expand trans env)) + env)) + (else (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 @@ -805,7 +812,7 @@ ;; - no, we need to do this here so code is carried though all transforms ;; (alpha, cps, closure, etc). otherwise code has to be interpreted during expansion ;; - `(define ,name ,(expand body env)))) + `(define ,name ,(expand body env)))))) ((define-c? exp) exp) ((symbol? (car exp)) (let ((val (env:lookup (car exp) env #f)))