[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 25/36: eval-when

From: Christopher Allan Webber
Subject: [Guile-commits] 25/36: eval-when
Date: Fri, 25 Mar 2016 20:04:01 +0000

cwebber pushed a commit to branch wip-elisp
in repository guile.

commit d9284d3bcde1cd3bdc69e99751427d65bd8463b0
Author: Robin Templeton <address@hidden>
Date:   Mon Aug 4 23:16:09 2014 -0400

    (Best-ability ChangeLog annotation added by Christopher Allan Webber.)
    * module/language/elisp/compile-tree-il.scm (progn): Use compile-expr-1
      instead of compile-expr.
      (toplevel?, compile-time-too?): New fluids.
      (eval-when): New special form.
      (compile-expr, compile-expr-1): compile-expr is renamed to
      compile-expr-1, and compile-expr  is now a procedure which, if
      fulid-ref of toplevel? is true, will call compile-expr-1 with
      toplevel? fulid bound to #f.  Otherwise, continue with compile-expr-1.
      (compile-tree-il): Set toplevel? and compile-time-too? fluids to #t
      during evaluation.
 module/language/elisp/compile-tree-il.scm |   45 ++++++++++++++++++++++++++--
 1 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/module/language/elisp/compile-tree-il.scm 
index 87ee486..66247a4 100644
--- a/module/language/elisp/compile-tree-il.scm
+++ b/module/language/elisp/compile-tree-il.scm
@@ -459,11 +459,40 @@
   (list->seq loc
              (if (null? args)
                  (list (nil-value loc))
-                 (map compile-expr args))))
+                 (map compile-expr-1 args))))
 (defspecial eval-when-compile (loc args)
   (make-const loc (compile `(progn ,@args) #:from 'elisp #:to 'value)))
+(define toplevel? (make-fluid))
+(define compile-time-too? (make-fluid))
+(defspecial eval-when (loc args)
+  (pmatch args
+    ((,situations . ,forms)
+     (let ((compile? (memq ':compile-toplevel situations))
+           (load? (memq ':load-toplevel situations))
+           (execute? (memq ':execute situations)))
+       (cond
+        ((not (fluid-ref toplevel?))
+         (if execute?
+             (compile-expr `(progn ,@forms))
+             (make-const loc #nil)))
+        (load?
+         (with-fluids ((compile-time-too?
+                        (cond (compile? #t)
+                              (execute? (fluid-ref compile-time-too?))
+                              (else #f))))
+           (when (fluid-ref compile-time-too?)
+             (eval-elisp `(progn ,@forms)))
+           (compile-expr-1 `(progn ,@forms))))
+        ((or compile? (and execute? (fluid-ref compile-time-too?)))
+         (eval-elisp `(progn ,@forms))
+         (make-const loc #nil))
+        (else
+         (make-const loc #nil)))))))
 (defspecial if (loc args)
   (pmatch args
     ((,cond ,then . ,else)
@@ -820,7 +849,7 @@
 ;;; Compile a single expression to TreeIL.
-(define (compile-expr expr)
+(define (compile-expr-1 expr)
   (let ((loc (location expr)))
      ((symbol? expr)
@@ -829,9 +858,17 @@
       (compile-pair loc expr))
      (else (make-const loc expr)))))
+(define (compile-expr expr)
+  (if (fluid-ref toplevel?)
+      (with-fluids ((toplevel? #f))
+        (compile-expr-1 expr))
+      (compile-expr-1 expr)))
 (define (compile-tree-il expr env opts)
-   (with-fluids ((bindings-data (make-bindings)))
-     (compile-expr expr))
+   (with-fluids ((bindings-data (make-bindings))
+                 (toplevel? #t)
+                 (compile-time-too? #f))
+     (compile-expr-1 expr))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]