~ chicken-core (chicken-5) 171771fd7123530fbdfcc7e6a3f3c7625d2d0908


commit 171771fd7123530fbdfcc7e6a3f3c7625d2d0908
Author:     Peter Bex <peter@more-magic.net>
AuthorDate: Sun Apr 29 13:57:21 2018 +0200
Commit:     Kooda <kooda@upyum.com>
CommitDate: Tue May 1 18:57:51 2018 +0200

    Simplify eval/meta a bit and drop ##sys#active-eval-environment
    
    In practice, the active-eval-environment will always be set to the
    parameter ##sys#current-environment (_not_ its value!), and there
    is no way to override it (anymore?).
    
    Instead of manually doing a dynamic-wind for all the parameters and
    manually set/restore it to the correct values (which is error-prone)
    we'll just use parameterize.  Only the meta environments will be
    manually reset to the current value of their corresponding
    environments one level down in the phasing tower (which is the only
    depth currently supported by CHICKEN).
    
    If we ever implement infinite phasing support, I think we can change
    this to use a stack, instead.
    
    Signed-off-by: Kooda <kooda@upyum.com>

diff --git a/eval.scm b/eval.scm
index 1ae1f9d0..a615fa72 100644
--- a/eval.scm
+++ b/eval.scm
@@ -712,18 +712,11 @@
 
 ;;; evaluate in the macro-expansion/compile-time environment
 (define (##sys#eval/meta form)
-  (let ((oldcm (##sys#current-module))
-	(oldme (##sys#macro-environment))
-	(oldce (##sys#current-environment))
-	(mme (##sys#meta-macro-environment))
-	(cme (##sys#current-meta-environment))
-	(aee (##sys#active-eval-environment)))
+  (parameterize ((##sys#current-module #f)
+		 (##sys#macro-environment (##sys#meta-macro-environment))
+		 (##sys#current-environment (##sys#current-meta-environment)))
     (dynamic-wind
-	(lambda () 
-	  (##sys#current-module #f)
-	  (##sys#macro-environment mme)
-	  (##sys#current-environment cme)
-	  (##sys#active-eval-environment ##sys#current-meta-environment))
+	void
 	(lambda ()
 	  ((compile-to-closure
 	    form
@@ -732,12 +725,13 @@
 	    #t)				; toplevel.
 	   '()) )
 	(lambda ()
-	  (##sys#active-eval-environment aee)
-	  (##sys#current-module oldcm)
+	  ;; Just before restoring the parameters, update "meta"
+	  ;; environments to receive a copy of the current
+	  ;; environments one level "down".  We don't support more
+	  ;; than two evaluation phase levels currently.  XXX: Should
+	  ;; we change this to a "stack" of environments?
 	  (##sys#current-meta-environment (##sys#current-environment))
-	  (##sys#current-environment oldce)
-	  (##sys#meta-macro-environment (##sys#macro-environment))
-	  (##sys#macro-environment oldme)))))
+	  (##sys#meta-macro-environment (##sys#macro-environment))))))
 
 (define eval-handler
   (make-parameter
diff --git a/expand.scm b/expand.scm
index d0a7aca6..b2f97d4b 100644
--- a/expand.scm
+++ b/expand.scm
@@ -88,9 +88,6 @@
 (define ##sys#current-environment (make-parameter '()))
 (define ##sys#current-meta-environment (make-parameter '()))
 
-;;XXX should this be in eval.scm?
-(define ##sys#active-eval-environment (make-parameter ##sys#current-environment))
-
 (define (lookup id se)
   (cond ((##core#inline "C_u_i_assq" id se) => cdr)
 	((getp id '##core#macro-alias))
diff --git a/modules.scm b/modules.scm
index bd2ba1e2..f0bf4a3d 100644
--- a/modules.scm
+++ b/modules.scm
@@ -764,7 +764,7 @@
 	  (else sym)))
   (cond ((##sys#qualified-symbol? sym) sym)
 	((namespaced-symbol? sym) sym)
-	((assq sym ((##sys#active-eval-environment))) =>
+	((assq sym (##sys#current-environment)) =>
 	 (lambda (a)
 	   (let ((sym2 (cdr a)))
 	     (dm "(ALIAS) in current environment " sym " -> " sym2)
Trap