mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 12:35:05 +02:00
Only do macro env lookup once
This commit is contained in:
parent
0542b57cfd
commit
6a4e8032b7
1 changed files with 20 additions and 16 deletions
|
@ -52,23 +52,27 @@
|
||||||
result
|
result
|
||||||
(append begin-exprs (cdr exp))
|
(append begin-exprs (cdr exp))
|
||||||
env)))
|
env)))
|
||||||
;; 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)))
|
|
||||||
(expand-body
|
|
||||||
result
|
|
||||||
(cons expanded (cdr exp))
|
|
||||||
env)))
|
|
||||||
(else
|
(else
|
||||||
(expand-body
|
(let ((macro #f))
|
||||||
(cons
|
(when (and (app? (car exp))
|
||||||
(inner-expand (car exp) env)
|
(symbol? (caar exp)))
|
||||||
result)
|
(set! macro (env:lookup (caar exp) env #f)))
|
||||||
(cdr exp)
|
(if (tagged-list? 'macro macro)
|
||||||
env))))
|
;; Expand macro here so we can catch begins in the expanded code,
|
||||||
|
;; including nested begins
|
||||||
|
(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))
|
||||||
|
;; No macro, use main expand function to process
|
||||||
|
(expand-body
|
||||||
|
(cons
|
||||||
|
(inner-expand (car exp) env)
|
||||||
|
result)
|
||||||
|
(cdr exp)
|
||||||
|
env))))))
|
||||||
|
|
||||||
(define (my-expand exp env)
|
(define (my-expand exp env)
|
||||||
(inner-expand exp env))
|
(inner-expand exp env))
|
||||||
|
|
Loading…
Add table
Reference in a new issue