[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
eval-when
(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
b/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)))
(cond
((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)
(values
- (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))
env
env))
- [Guile-commits] 13/36: constant-interning fix, (continued)
- [Guile-commits] 13/36: constant-interning fix, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 15/36: restore special operator handling, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 17/36: fix `nil?' type inference, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 18/36: compile-elisp fn, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 19/36: elisp @@ macro, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 20/36: defconst, defvar: proclaim special at compile-time, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 21/36: compiler macros, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 22/36: defsubst, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 23/36: use defsubst, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 24/36: fset macro, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 25/36: eval-when,
Christopher Allan Webber <=
- [Guile-commits] 26/36: degenerate let forms, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 27/36: only evaluate top-level macro definitions, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 28/36: top level fixes, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 29/36: execute top level require forms, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 31/36: use guile eval for elisp tree-il, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 30/36: deprecated eval-when situations, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 32/36: guile-backtrace function, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 33/36: use standard evaluator, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 34/36: update cross-compilation test, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 36/36: temporarily disable elisp exception tests, Christopher Allan Webber, 2016/03/25