Use macro env instead of *defined-macros* list

This commit is contained in:
Justin Ethier 2015-08-31 23:21:15 -04:00
parent dadabcaa80
commit a01086e904
2 changed files with 24 additions and 22 deletions

View file

@ -29,7 +29,9 @@
(define (macro:load-env! defined-macros)
(set! *macro:env* (env:extend-environment
(map car defined-macros)
(map cdr defined-macros)
(map (lambda (v)
(list 'macro (cdr v)))
defined-macros)
env:the-empty-environment)))
(define (macro:get-env) *macro:env*)
@ -47,8 +49,8 @@
; TODO: probably want to look at contents of defined-macros and figure out
; exactly how the env needs to represent macros (compiled and eval'd)
;
(define (macro:expand _macro-val exp mac-env defined-macros)
(let* ((macro (assoc (car exp) defined-macros))
(define (macro:expand macro exp mac-env _defined-macros)
(let* (;(macro (assoc (car exp) defined-macros))
(compiled-macro? (or (macro? (Cyc-get-cvar macro))
(procedure? macro))))
;; Invoke ER macro
@ -62,19 +64,19 @@
Cyc-er-compare?))
(else
;; Assume evaluated macro
(let* ((env-vars (map car defined-macros))
(env-vals (map (lambda (v)
(list 'macro (cdr v)))
defined-macros))
;; Pass defined macros so nested macros can be expanded
(env (create-environment env-vars env-vals)))
;(let* ((env-vars (map car defined-macros))
; (env-vals (map (lambda (v)
; (list 'macro (cdr v)))
; defined-macros))
; ;; Pass defined macros so nested macros can be expanded
; (env (create-environment env-vars env-vals)))
(eval
(list
(cdr macro)
(list 'quote exp)
(Cyc-er-rename mac-env)
Cyc-er-compare?)
mac-env))))))
mac-env)))));)
; TODO: get macro name, transformer
; TODO: let-syntax forms

View file

@ -789,20 +789,20 @@
`(define ,name ,(expand body env))))
; Newer macro expansion code, but not ready yet
; ((symbol? (car exp))
; (let ((val (env:lookup (car exp) env #f)))
; (if val
; (macro:expand val exp env)
; (map
; (lambda (expr) (expand expr env))
; exp))))
((symbol? (car exp))
(let ((val (env:lookup (car exp) env #f)))
(if val
(macro:expand val exp env)
(map
(lambda (expr) (expand expr env))
exp))))
;; Older *define-macro* code:
((macro:macro? exp *defined-macros*)
;(trace:info (list 'expanding exp))
(expand ;; Could expand into another macro
(macro:expand 'TODO-val exp 'TODO-env *defined-macros*)
env))
;((macro:macro? exp *defined-macros*)
; ;(trace:info (list 'expanding exp))
; (expand ;; Could expand into another macro
; (macro:expand 'TODO-val exp env *defined-macros*)
; env))
(else
(map