mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-29 15:05:04 +02:00
WIP
This commit is contained in:
parent
18c14799c1
commit
e2a455ca3f
1 changed files with 26 additions and 3 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue