mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 12:35:05 +02:00
WIP
This commit is contained in:
parent
fc5eebfcb8
commit
18c14799c1
1 changed files with 29 additions and 4 deletions
|
@ -30,6 +30,29 @@
|
||||||
(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
|
||||||
|
;; 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))
|
||||||
|
((begin? (car exp))
|
||||||
|
(let* ((expr (car exp))
|
||||||
|
(begin-exprs (begin->exps expr))
|
||||||
|
(expanded-exprs (map (lambda (expr) (my-expand expr env)) begin-exprs)))
|
||||||
|
(expand-body
|
||||||
|
(append result (reverse expanded-exprs))
|
||||||
|
(cdr exp)
|
||||||
|
env)))
|
||||||
|
(else
|
||||||
|
(expand-body
|
||||||
|
(cons
|
||||||
|
(my-expand (car exp) env)
|
||||||
|
result)
|
||||||
|
(cdr exp)
|
||||||
|
env))))
|
||||||
|
|
||||||
(define (my-expand exp env)
|
(define (my-expand exp env)
|
||||||
(cond
|
(cond
|
||||||
((const? exp) exp)
|
((const? exp) exp)
|
||||||
|
@ -39,10 +62,12 @@
|
||||||
;; TODO: need a way of taking a begin here and splicing its contents
|
;; TODO: need a way of taking a begin here and splicing its contents
|
||||||
;; into the body
|
;; into the body
|
||||||
((lambda? exp) `(lambda ,(lambda->formals exp)
|
((lambda? exp) `(lambda ,(lambda->formals exp)
|
||||||
,@(map
|
,@(expand-body '() (lambda->exp exp) env)
|
||||||
;; TODO: use extend env here?
|
;,@(map
|
||||||
(lambda (expr) (my-expand expr env))
|
; ;; TODO: use extend env here?
|
||||||
(lambda->exp exp))))
|
; (lambda (expr) (my-expand expr env))
|
||||||
|
; (lambda->exp exp))
|
||||||
|
))
|
||||||
((define? exp) (if (define-lambda? exp)
|
((define? exp) (if (define-lambda? exp)
|
||||||
(my-expand (define->lambda exp) env)
|
(my-expand (define->lambda exp) env)
|
||||||
`(define ,(my-expand (define->var exp) env)
|
`(define ,(my-expand (define->var exp) env)
|
||||||
|
|
Loading…
Add table
Reference in a new issue