From a822bc9e91dc1dc19a975ff33452b04ca2553b25 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 14 Sep 2016 17:36:53 -0400 Subject: [PATCH] Pass additional environments to er macro functions --- scheme/cyclone/macros.sld | 8 ++++---- scheme/cyclone/util.sld | 9 ++++++--- scheme/eval.sld | 8 ++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/scheme/cyclone/macros.sld b/scheme/cyclone/macros.sld index 07491673..3975063b 100644 --- a/scheme/cyclone/macros.sld +++ b/scheme/cyclone/macros.sld @@ -66,15 +66,15 @@ (compiled-macro? ((Cyc-get-cvar (cadr macro)) exp - (Cyc-er-rename mac-env) - Cyc-er-compare?)) + (Cyc-er-rename mac-env mac-env) ;; TODO: use-env + (Cyc-er-compare? mac-env))) ;; TODO: wrong env (?) (else (eval (list (Cyc-get-cvar (cadr macro)) (list 'quote exp) - (Cyc-er-rename mac-env) - Cyc-er-compare?) + (Cyc-er-rename mac-env mac-env) + (Cyc-er-compare? mac-env)) mac-env))))) ; TODO: get macro name, transformer diff --git a/scheme/cyclone/util.sld b/scheme/cyclone/util.sld index 400a8aa7..6fe7c1e4 100644 --- a/scheme/cyclone/util.sld +++ b/scheme/cyclone/util.sld @@ -423,7 +423,6 @@ ;;; Explicit renaming macros ;; ER macro rename function, based on code from Chibi scheme -(define (Cyc-er-rename mac-env) ; (lambda (sym) sym)) ; TODO: temporary placeholder, see below ;TODO: I think we're ready to cut back over to this now? @@ -465,8 +464,11 @@ ; a new lambda scope is introduced? ; - need to keep track of it for compiled macro expansion ; +(define (Cyc-er-rename use-env mac-env) ((lambda (renames) (lambda (identifier) +;(Cyc-write `(ER rename ,identifier) (current-output-port)) +;(Cyc-display "\n" (current-output-port)) ((lambda (cell) (if cell (cdr cell) @@ -508,10 +510,11 @@ (begin . begin) ;; TODO: just a quick-fix, not a long-term solution ))) -(define (Cyc-er-compare? a b) +(define (Cyc-er-compare? use-env) ;; TODO: this is not good enough, need to determine if these symbols ;; are the same identifier in their *environment of use* - (eq? a b)) + (lambda (a b) + (eq? a b))) ;; Name-mangling. diff --git a/scheme/eval.sld b/scheme/eval.sld index c8733858..8d9bf6b5 100644 --- a/scheme/eval.sld +++ b/scheme/eval.sld @@ -440,16 +440,16 @@ ;; Compiled macro, call directly (analyze (apply macro-op (list (cons (car exp) (operands exp)) - (Cyc-er-rename a-env) - Cyc-er-compare?)) + (Cyc-er-rename a-env a-env) + (Cyc-er-compare? a-env))) a-env) ;; Interpreted macro, build expression and eval (let ((expr (cons macro-op (list (cons 'quote (list (cons (car exp) (operands exp)))) - (Cyc-er-rename a-env) - Cyc-er-compare?)))) + (Cyc-er-rename a-env a-env) + (Cyc-er-compare? a-env))))) (analyze (eval expr a-env) ;; Expand macro a-env))))))