mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-20 06:09:17 +02:00
Build macro env on top of global env
This commit is contained in:
parent
1244ea5342
commit
9a3d370de4
3 changed files with 9 additions and 8 deletions
|
@ -5,6 +5,7 @@
|
||||||
;; This module contains a front-end for the compiler itself.
|
;; This module contains a front-end for the compiler itself.
|
||||||
;;
|
;;
|
||||||
(import (scheme base)
|
(import (scheme base)
|
||||||
|
(scheme eval)
|
||||||
(scheme file)
|
(scheme file)
|
||||||
(scheme read)
|
(scheme read)
|
||||||
(scheme write)
|
(scheme write)
|
||||||
|
@ -121,7 +122,7 @@
|
||||||
(append
|
(append
|
||||||
macros
|
macros
|
||||||
*defined-macros*)))
|
*defined-macros*)))
|
||||||
(macro:load-env! *defined-macros*)
|
(macro:load-env! *defined-macros* (create-environment '() '()))
|
||||||
;TODO: try this again, make sure macro is loaded:
|
;TODO: try this again, make sure macro is loaded:
|
||||||
(trace:info (list 'defined-macros *defined-macros*))
|
(trace:info (list 'defined-macros *defined-macros*))
|
||||||
(trace:info (list 'macro-env (macro:get-env)))
|
(trace:info (list 'macro-env (macro:get-env)))
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
(cons (cons name body) *macro:defined-macros*))
|
(cons (cons name body) *macro:defined-macros*))
|
||||||
#t)
|
#t)
|
||||||
|
|
||||||
(define (macro:load-env! defined-macros)
|
(define (macro:load-env! defined-macros base-env)
|
||||||
(set! *macro:env* (env:extend-environment
|
(set! *macro:env* (env:extend-environment
|
||||||
(map car defined-macros)
|
(map car defined-macros)
|
||||||
(map (lambda (v)
|
(map (lambda (v)
|
||||||
(list 'macro (cdr v)))
|
(list 'macro (cdr v)))
|
||||||
defined-macros)
|
defined-macros)
|
||||||
env:the-empty-environment)))
|
base-env)))
|
||||||
|
|
||||||
(define (macro:get-env) *macro:env*)
|
(define (macro:get-env) *macro:env*)
|
||||||
|
|
||||||
|
@ -54,10 +54,10 @@
|
||||||
(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 (cdr macro)))
|
||||||
(procedure? (cdr macro)))))
|
(procedure? (cdr macro)))))
|
||||||
(newline)
|
;(newline)
|
||||||
(display "/* ")
|
;(display "/* ")
|
||||||
(display (list 'macro:expand exp macro compiled-macro?))
|
;(display (list 'macro:expand exp macro compiled-macro?))
|
||||||
(display "*/ ")
|
;(display "*/ ")
|
||||||
;; Invoke ER macro
|
;; Invoke ER macro
|
||||||
(cond
|
(cond
|
||||||
((not macro)
|
((not macro)
|
||||||
|
|
|
@ -791,7 +791,7 @@
|
||||||
; 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 (tagged-list? 'macro val)
|
||||||
(expand ; Could expand into another macro
|
(expand ; Could expand into another macro
|
||||||
(macro:expand 'val exp env *defined-macros*)
|
(macro:expand 'val exp env *defined-macros*)
|
||||||
;(macro:expand2 exp val env)
|
;(macro:expand2 exp val env)
|
||||||
|
|
Loading…
Add table
Reference in a new issue