[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 23/36: eval-when
From: |
Christopher Allan Webber |
Subject: |
[Guile-commits] 23/36: eval-when |
Date: |
Tue, 19 Oct 2021 18:11:28 -0400 (EDT) |
cwebber pushed a commit to branch wip-elisp-rebased
in repository guile.
commit cd630c1f38b40427065801b7a6c135147d6d3bc5
Author: Robin Templeton <robin@terpri.org>
AuthorDate: Mon Aug 4 23:16:09 2014 -0400
eval-when
(Best-ability ChangeLog annotation added by Christine Lemmer-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 file changed, 41 insertions(+), 4 deletions(-)
diff --git a/module/language/elisp/compile-tree-il.scm
b/module/language/elisp/compile-tree-il.scm
index 24d6cc4..9533e91 100644
--- a/module/language/elisp/compile-tree-il.scm
+++ b/module/language/elisp/compile-tree-il.scm
@@ -461,13 +461,42 @@
(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 (with-native-target
(lambda ()
(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)
@@ -826,7 +855,7 @@
;;; Compile a single expression to TreeIL.
-(define (compile-expr expr)
+(define (compile-expr-1 expr)
(let ((loc (location expr)))
(cond
((symbol? expr)
@@ -835,9 +864,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] 11/36: defvar affects default value, (continued)
- [Guile-commits] 11/36: defvar affects default value, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 12/36: constant-interning fix, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 14/36: restore special operator handling, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 08/36: elisp updates, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 13/36: define-module for elisp special modules, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 16/36: compile-elisp fn, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 15/36: fix symbol-function, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 18/36: defconst, defvar: proclaim special at compile-time, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 19/36: compiler macros, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 21/36: use defsubst, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 23/36: eval-when,
Christopher Allan Webber <=
- [Guile-commits] 26/36: top level fixes, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 17/36: elisp @@ macro, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 36/36: elisp: boot: Replace removed FRAME-PROCEDURE with FRAME-PROCEDURE-NAME., Christopher Allan Webber, 2021/10/19
- [Guile-commits] 20/36: defsubst, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 29/36: use guile eval for elisp tree-il, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 31/36: use standard evaluator, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 22/36: fset macro, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 28/36: deprecated eval-when situations, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 30/36: guile-backtrace function, Christopher Allan Webber, 2021/10/19
- [Guile-commits] 35/36: loader: Handle interned constants as well as plain bytevectors., Christopher Allan Webber, 2021/10/19