This commit is contained in:
Justin Ethier 2016-02-02 03:30:54 -05:00
parent 18c14799c1
commit e2a455ca3f

View file

@ -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)