From e2a455ca3f126b8c42ab53f73172b8ba7713a56d Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 2 Feb 2016 03:30:54 -0500 Subject: [PATCH] WIP --- macro-test.scm | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/macro-test.scm b/macro-test.scm index 77764386..1e079304 100644 --- a/macro-test.scm +++ b/macro-test.scm @@ -12,7 +12,17 @@ ;(scheme cyclone libraries) ) -(define input-program '(lambda (x) (begin (+ x x) 1 2 3))) +;(define input-program '(lambda (x) (begin (+ x x) 1 2 3))) +(define input-program + '((lambda () + (define-syntax test + (er-macro-transformer + (lambda (expr rename compare) + `(begin 1 (define tmp #t) 3)))) + (test) + (test) + (write tmp) + ))) ;; Load macros for expansion phase (let ((macros (filter @@ -32,8 +42,6 @@ ;; A first step towards splicing begin, but this doesn't handle ;; begin being introduced as part of a macro -;; may need to add back the define-syntax code and introduce a macro -;; that expands into a begin (define (expand-body result exp env) (cond ((null? exp) (reverse result)) @@ -54,6 +62,13 @@ env)))) (define (my-expand exp env) + (inner-expand exp env #f)) + +;; TODO: replace my-expand's below (and above in expand-body) with inner-expand. still trying to figure out how to use body? arg though. +;; TODO: need to be able to splice expanded begins somehow. +;; maybe pass built up exp list to it and splice the begin into that before +;; continuing expansion +(define (inner-expand exp env body?) (cond ((const? exp) exp) ((prim? exp) exp) @@ -84,6 +99,14 @@ #f))) ((app? exp) (cond + ((define-syntax? exp) + (let* ((name (cadr exp)) + (trans (caddr exp)) + (body (cadr trans))) + (set! *defined-macros* (cons (cons name body) *defined-macros*)) + (macro:add! name body) + (env:define-variable! name (list 'macro body) env) + `(define ,name ,(expand body env)))) ((symbol? (car exp)) (let ((val (env:lookup (car exp) env #f))) (if (tagged-list? 'macro val)