mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-15 08:47:35 +02:00
Use macro env instead of *defined-macros* list
This commit is contained in:
parent
dadabcaa80
commit
a01086e904
2 changed files with 24 additions and 22 deletions
|
@ -29,7 +29,9 @@
|
||||||
(define (macro:load-env! defined-macros)
|
(define (macro:load-env! defined-macros)
|
||||||
(set! *macro:env* (env:extend-environment
|
(set! *macro:env* (env:extend-environment
|
||||||
(map car defined-macros)
|
(map car defined-macros)
|
||||||
(map cdr defined-macros)
|
(map (lambda (v)
|
||||||
|
(list 'macro (cdr v)))
|
||||||
|
defined-macros)
|
||||||
env:the-empty-environment)))
|
env:the-empty-environment)))
|
||||||
|
|
||||||
(define (macro:get-env) *macro:env*)
|
(define (macro:get-env) *macro:env*)
|
||||||
|
@ -47,8 +49,8 @@
|
||||||
; TODO: probably want to look at contents of defined-macros and figure out
|
; 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)
|
; exactly how the env needs to represent macros (compiled and eval'd)
|
||||||
;
|
;
|
||||||
(define (macro:expand _macro-val exp mac-env defined-macros)
|
(define (macro:expand macro exp mac-env _defined-macros)
|
||||||
(let* ((macro (assoc (car exp) defined-macros))
|
(let* (;(macro (assoc (car exp) defined-macros))
|
||||||
(compiled-macro? (or (macro? (Cyc-get-cvar macro))
|
(compiled-macro? (or (macro? (Cyc-get-cvar macro))
|
||||||
(procedure? macro))))
|
(procedure? macro))))
|
||||||
;; Invoke ER macro
|
;; Invoke ER macro
|
||||||
|
@ -62,19 +64,19 @@
|
||||||
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)
|
(cdr macro)
|
||||||
(list 'quote exp)
|
(list 'quote exp)
|
||||||
(Cyc-er-rename mac-env)
|
(Cyc-er-rename mac-env)
|
||||||
Cyc-er-compare?)
|
Cyc-er-compare?)
|
||||||
mac-env))))))
|
mac-env)))));)
|
||||||
|
|
||||||
; TODO: get macro name, transformer
|
; TODO: get macro name, transformer
|
||||||
; TODO: let-syntax forms
|
; TODO: let-syntax forms
|
||||||
|
|
|
@ -789,20 +789,20 @@
|
||||||
`(define ,name ,(expand body env))))
|
`(define ,name ,(expand body env))))
|
||||||
|
|
||||||
; Newer macro expansion code, but not ready yet
|
; Newer macro expansion code, but not ready yet
|
||||||
; ((symbol? (car exp))
|
((symbol? (car exp))
|
||||||
; (let ((val (env:lookup (car exp) env #f)))
|
(let ((val (env:lookup (car exp) env #f)))
|
||||||
; (if val
|
(if val
|
||||||
; (macro:expand val exp env)
|
(macro:expand val exp env)
|
||||||
; (map
|
(map
|
||||||
; (lambda (expr) (expand expr env))
|
(lambda (expr) (expand expr env))
|
||||||
; exp))))
|
exp))))
|
||||||
|
|
||||||
;; Older *define-macro* code:
|
;; Older *define-macro* code:
|
||||||
((macro:macro? exp *defined-macros*)
|
;((macro:macro? exp *defined-macros*)
|
||||||
;(trace:info (list 'expanding exp))
|
; ;(trace:info (list 'expanding exp))
|
||||||
(expand ;; Could expand into another macro
|
; (expand ;; Could expand into another macro
|
||||||
(macro:expand 'TODO-val exp 'TODO-env *defined-macros*)
|
; (macro:expand 'TODO-val exp env *defined-macros*)
|
||||||
env))
|
; env))
|
||||||
|
|
||||||
(else
|
(else
|
||||||
(map
|
(map
|
||||||
|
|
Loading…
Add table
Reference in a new issue