mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 12:35:05 +02:00
Handle nested begins
This commit is contained in:
parent
bab266d897
commit
0542b57cfd
1 changed files with 7 additions and 9 deletions
|
@ -40,26 +40,24 @@
|
||||||
(write "---------------- after macro expansion:")
|
(write "---------------- after macro expansion:")
|
||||||
(write input-program) ;pretty-print
|
(write input-program) ;pretty-print
|
||||||
|
|
||||||
;; A first step towards splicing begin, but this doesn't handle
|
;; Expand lambda body here so we can splice in any begin's
|
||||||
;; begin being introduced as part of a macro
|
|
||||||
(define (expand-body result exp env)
|
(define (expand-body result exp env)
|
||||||
(cond
|
(cond
|
||||||
((null? exp) (reverse result))
|
((null? exp) (reverse result))
|
||||||
|
;; Splice in begin contents and keep expanding body
|
||||||
((begin? (car exp))
|
((begin? (car exp))
|
||||||
(let* ((expr (car exp))
|
(let* ((expr (car exp))
|
||||||
(begin-exprs (begin->exps expr))
|
(begin-exprs (begin->exps expr)))
|
||||||
(expanded-exprs (map (lambda (expr) (inner-expand expr env)) begin-exprs)))
|
|
||||||
;(write `(begin-DEBUG result: ,result begin-exprs: ,begin-exprs expanded-exprs: ,expanded-exprs))
|
|
||||||
(expand-body
|
(expand-body
|
||||||
(append (reverse expanded-exprs) result)
|
result
|
||||||
(cdr exp)
|
(append begin-exprs (cdr exp))
|
||||||
env)))
|
env)))
|
||||||
;; TODO: test concept of expanding/splicing begin here
|
;; Expand macro here so we can catch begins in the expanded code,
|
||||||
|
;; including nested begins
|
||||||
((and (app? (car exp))
|
((and (app? (car exp))
|
||||||
(symbol? (caar exp))
|
(symbol? (caar exp))
|
||||||
(tagged-list? 'macro (env:lookup (caar exp) env #f)))
|
(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) (env:lookup (caar exp) env #f) env)))
|
||||||
(write `(DEBUG ,(cons expanded (cdr exp))))
|
|
||||||
(expand-body
|
(expand-body
|
||||||
result
|
result
|
||||||
(cons expanded (cdr exp))
|
(cons expanded (cdr exp))
|
||||||
|
|
Loading…
Add table
Reference in a new issue