Only do macro env lookup once

This commit is contained in:
Justin Ethier 2016-02-02 22:43:24 -05:00
parent 0542b57cfd
commit 6a4e8032b7

View file

@ -52,23 +52,27 @@
result
(append begin-exprs (cdr exp))
env)))
(else
(let ((macro #f))
(when (and (app? (car exp))
(symbol? (caar exp)))
(set! macro (env:lookup (caar exp) env #f)))
(if (tagged-list? 'macro macro)
;; Expand macro here so we can catch begins in the expanded code,
;; including nested begins
((and (app? (car exp))
(symbol? (caar exp))
(tagged-list? 'macro (env:lookup (caar exp) env #f)))
(let ((expanded (macro:expand (car exp) (env:lookup (caar exp) env #f) env)))
(let ((expanded (macro:expand (car exp) macro env)))
;; Call with expanded macro in case we need to expand again
(expand-body
result
(cons expanded (cdr exp))
env)))
(else
env))
;; No macro, use main expand function to process
(expand-body
(cons
(inner-expand (car exp) env)
result)
(cdr exp)
env))))
env))))))
(define (my-expand exp env)
(inner-expand exp env))