mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-08 05:27:33 +02:00
Switch transforms over to use env's for expand
This commit is contained in:
parent
0f7772fa90
commit
c170b253a7
2 changed files with 30 additions and 23 deletions
|
@ -41,34 +41,34 @@
|
||||||
(tagged-list? 'define-syntax exp))
|
(tagged-list? 'define-syntax exp))
|
||||||
|
|
||||||
(define (macro:macro? exp defined-macros) (assoc (car exp) defined-macros))
|
(define (macro:macro? exp defined-macros) (assoc (car exp) defined-macros))
|
||||||
(define (macro:expand exp defined-macros)
|
(define (macro:expand macro-val exp mac-env)
|
||||||
(let* ((macro (assoc (car exp) defined-macros))
|
(let* ( ;(macro (assoc (car exp) defined-macros))
|
||||||
(compiled-macro? (or (macro? (Cyc-get-cvar (cdr macro)))
|
(compiled-macro? (or (macro? (Cyc-get-cvar macro-val))
|
||||||
(procedure? (cdr macro)))))
|
(procedure? macro-val))))
|
||||||
;; Invoke ER macro
|
;; Invoke ER macro
|
||||||
(cond
|
(cond
|
||||||
((not macro)
|
((not macro-val)
|
||||||
(error "macro not found" exp))
|
(error "macro not found" exp))
|
||||||
(compiled-macro?
|
(compiled-macro?
|
||||||
((Cyc-get-cvar (cdr macro))
|
((Cyc-get-cvar macro-val)
|
||||||
exp
|
exp
|
||||||
(Cyc-er-rename 'todo-mac-env)
|
(Cyc-er-rename mac-env)
|
||||||
Cyc-er-compare?))
|
Cyc-er-compare?))
|
||||||
(else
|
(else
|
||||||
;; Assume evaluated macro
|
;; Assume evaluated macro
|
||||||
(let* ((env-vars (map car defined-macros))
|
;(let* ((env-vars (map car defined-macros))
|
||||||
(env-vals (map (lambda (v)
|
; (env-vals (map (lambda (v)
|
||||||
(list 'macro (cdr v)))
|
; (list 'macro (cdr v)))
|
||||||
defined-macros))
|
; defined-macros))
|
||||||
;; Pass defined macros so nested macros can be expanded
|
; ;; Pass defined macros so nested macros can be expanded
|
||||||
(env (create-environment env-vars env-vals)))
|
; (env (create-environment env-vars env-vals)))
|
||||||
(eval
|
(eval
|
||||||
(list
|
(list
|
||||||
(cdr macro)
|
macro-val
|
||||||
(list 'quote exp)
|
(list 'quote exp)
|
||||||
(Cyc-er-rename 'todo-mac-env)
|
(Cyc-er-rename mac-env)
|
||||||
Cyc-er-compare?)
|
Cyc-er-compare?)
|
||||||
env))))))
|
mac-env)))));)
|
||||||
|
|
||||||
; TODO: get macro name, transformer
|
; TODO: get macro name, transformer
|
||||||
; TODO: let-syntax forms
|
; TODO: let-syntax forms
|
||||||
|
|
|
@ -775,7 +775,7 @@
|
||||||
;; Previous list should eventually go away once macros are
|
;; Previous list should eventually go away once macros are
|
||||||
;; moved from that static list to libraries
|
;; moved from that static list to libraries
|
||||||
(macro:add! name body)
|
(macro:add! name body)
|
||||||
TODO: add macro to env
|
(env:define-variable! name (list 'macro body) env)
|
||||||
;; Keep as a 'define' form so available at runtime
|
;; Keep as a 'define' form so available at runtime
|
||||||
;; TODO: may run into issues with expanding now, before some
|
;; TODO: may run into issues with expanding now, before some
|
||||||
;; of the macros are defined. may need to make a special pass
|
;; of the macros are defined. may need to make a special pass
|
||||||
|
@ -788,12 +788,19 @@ TODO: add macro to env
|
||||||
;;
|
;;
|
||||||
`(define ,name ,(expand body env))))
|
`(define ,name ,(expand body env))))
|
||||||
|
|
||||||
TODO: need to change below to use the env, and corresponding changes to macros module to set renames
|
((symbol? (car exp))
|
||||||
((macro:macro? exp *defined-macros*)
|
(let ((val (env:lookup (car exp) env #f)))
|
||||||
;(trace:info (list 'expanding exp))
|
(if val
|
||||||
(expand ;; Could expand into another macro
|
(macro:expand val exp env)
|
||||||
(macro:expand exp *defined-macros*)
|
(map
|
||||||
env))
|
(lambda (expr) (expand expr env))
|
||||||
|
exp))))
|
||||||
|
;((macro:macro? exp *defined-macros*)
|
||||||
|
; ;(trace:info (list 'expanding exp))
|
||||||
|
; (expand ;; Could expand into another macro
|
||||||
|
; (macro:expand exp *defined-macros*)
|
||||||
|
; env))
|
||||||
|
|
||||||
(else
|
(else
|
||||||
(map
|
(map
|
||||||
(lambda (expr) (expand expr env))
|
(lambda (expr) (expand expr env))
|
||||||
|
|
Loading…
Add table
Reference in a new issue