[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: eval
From: |
Dirk Herrmann |
Subject: |
Re: eval |
Date: |
Thu, 1 Feb 2001 17:58:00 +0100 (MET) |
On Thu, 1 Feb 2001, Dirk Herrmann wrote:
> SOLUTION:
> ---------
>
> Instead of having only one global variable 'the-module', we have
> 'the-module' and 'the-interaction-module'. Only 'the-module' is restored
> after the execution of 'eval, while 'the-interaction-module' remains
> changed after 'eval has finished. The value of 'the-interaction-module'
> is reported by (interaction-environment).
A patch that shows how this would look like is below. It looks more
complicated as it actually is, because I also brought some code pieces into a
more logical order. Unfortunately I was not able to tell diff to produce an
output as with:
===========
@@ <line info>
code before
-----------
code after
@@ ... next hunk
Hints how to produce such a diff are welcome :-)
Moreover, the patch is quite 'conservative': it keeps the-module and
the-interaction-module always in sync. The only exception is in scm_eval.
Probably the-interaction-module would not have to be changed in most of these
places.
Best regards,
Dirk
Index: ice-9/boot-9.scm
===================================================================
RCS file: /cvs/guile/guile-core/ice-9/boot-9.scm,v
retrieving revision 1.223
diff -u -r1.223 boot-9.scm
--- ice-9/boot-9.scm 2001/01/26 16:58:48 1.223
+++ ice-9/boot-9.scm 2001/02/01 16:52:50
@@ -727,7 +727,7 @@
(read-hash-extend #\' (lambda (c port)
(read port)))
(read-hash-extend #\. (lambda (c port)
- (eval (read port) (interaction-environment))))
+ (eval (read port) (current-environment))))
;;; {Command Line Options}
@@ -1333,9 +1333,11 @@
;;
(define the-module (make-fluid))
-;; scm:eval-transformer
+;; current-module
;;
-;;(define scm:eval-transformer (make-fluid)) ; initialized in eval.c.
+;; return the current module as viewed by the normalizer.
+;;
+(define (current-module) (fluid-ref the-module))
;; set-current-module module
;;
@@ -1354,27 +1356,47 @@
(fluid-set! *top-level-lookup-closure* #f)))
-;; current-module
+;; the-interaction-module
;;
-;; return the current module as viewed by the normalizer.
+;; This is the module used for interactive evaluation of code, which is
+;; reported by (interactive-environment).
;;
-(define (current-module) (fluid-ref the-module))
+;; NOTE: This binding is used in libguile/modules.c.
+;;
+(define the-interaction-module (make-fluid))
+
+(define (set-interaction-module m)
+ (fluid-set! the-interaction-module m))
+
+
+;; scm:eval-transformer
+;;
+;;(define scm:eval-transformer (make-fluid)) ; initialized in eval.c.
+
;;; {Module-based Loading}
;;;
(define (save-module-excursion thunk)
(let ((inner-module (current-module))
- (outer-module #f))
+ (inner-interaction-module (interaction-environment))
+ (outer-module #f)
+ (outer-interaction-module #f))
(dynamic-wind (lambda ()
(set! outer-module (current-module))
+ (set! outer-interaction-module (interaction-environment))
(set-current-module inner-module)
- (set! inner-module #f))
+ (set-interaction-module inner-interaction-module)
+ (set! inner-module #f)
+ (set! inner-interaction-module #f))
thunk
(lambda ()
(set! inner-module (current-module))
+ (set! inner-interaction-module (interaction-environment))
(set-current-module outer-module)
- (set! outer-module #f)))))
+ (set-interaction-module outer-interaction-module)
+ (set! outer-module #f)
+ (set! outer-interaction-module #f)))))
(define basic-load load)
@@ -1547,6 +1569,7 @@
(for-each set-system-module! (list the-root-module the-scm-module) '(#t #t))
(set-current-module the-root-module)
+(set-interaction-module the-root-module)
(define app (make-module 31))
(local-define '(app modules) (make-module 31))
@@ -1821,6 +1844,7 @@
(save-module-excursion
(lambda ()
(set-current-module mod)
+ (set-interaction-module mod)
(set-module-public-interface! mod mod)
(dynamic-call (cadr modinfo) (caddr modinfo))
))
@@ -2516,8 +2540,10 @@
(defmacro define-module args
`(let* ((process-define-module process-define-module)
(set-current-module set-current-module)
+ (set-interaction-module set-interaction-module)
(module (process-define-module ',args)))
(set-current-module module)
+ (set-interaction-module module)
module))
;; the guts of the use-modules macro. add the interfaces of the named
@@ -2573,7 +2599,7 @@
;; suggests we use eval here to accomodate Hobbit; it lets
;; the interpreter handle the define-private form, which
;; Hobbit can't digest.
- (eval '(define-private ,@ args) (interaction-environment)))))))
+ (eval '(define-private ,@ args) (current-module)))))))
Index: ice-9/emacs.scm
===================================================================
RCS file: /cvs/guile/guile-core/ice-9/emacs.scm,v
retrieving revision 1.22
diff -u -r1.22 emacs.scm
--- ice-9/emacs.scm 2000/12/08 15:39:10 1.22
+++ ice-9/emacs.scm 2001/02/01 16:52:50
@@ -137,7 +137,9 @@
(save-module-excursion
(lambda ()
(if module
- (set-current-module (resolve-module module #f)))
+ (let* ((m (resolve-module module #f)))
+ (set-current-module m)
+ (set-interaction-module m)))
(let ((result
(start-stack read-and-eval!
(read-and-eval! %%load-port))))
Index: ice-9/slib.scm
===================================================================
RCS file: /cvs/guile/guile-core/ice-9/slib.scm,v
retrieving revision 1.31
diff -u -r1.31 slib.scm
--- ice-9/slib.scm 2000/11/28 13:40:40 1.31
+++ ice-9/slib.scm 2001/02/01 16:52:50
@@ -142,6 +142,7 @@
(save-module-excursion
(lambda ()
(set-current-module slib-module)
+ (set-interaction-module slib-module)
(let ((errinfo (catch 'system-error
(lambda ()
(load-from-path name)
Index: libguile/modules.c
===================================================================
RCS file: /cvs/guile/guile-core/libguile/modules.c,v
retrieving revision 1.17
diff -u -r1.17 modules.c
--- libguile/modules.c 2000/12/08 17:32:56 1.17
+++ libguile/modules.c 2001/02/01 16:52:50
@@ -70,6 +70,8 @@
return SCM_CDR (the_root_module);
}
+
+/* This is the module selected during loading of code. */
static SCM the_module;
SCM
@@ -78,12 +80,8 @@
return scm_fluid_ref (SCM_CDR (the_module));
}
-static SCM set_current_module;
-/* This is the module selected during loading of code. Currently,
- * this is the same as (interaction-environment), but need not be in
- * the future.
- */
+static SCM set_current_module;
SCM
scm_select_module (SCM module)
@@ -93,6 +91,10 @@
return old;
}
+
+/* This is the module used for interactive execution of code. */
+static SCM the_interaction_module;
+
SCM_DEFINE (scm_interaction_environment, "interaction-environment", 0, 0, 0,
(),
"This procedure returns a specifier for the environment that
contains\n"
@@ -102,10 +104,11 @@
"dynamically typed by the user.")
#define FUNC_NAME s_scm_interaction_environment
{
- return scm_selected_module ();
+ return scm_fluid_ref (SCM_CDR (the_interaction_module));
}
#undef FUNC_NAME
+
SCM_SYMBOL (scm_sym_app, "app");
SCM_SYMBOL (scm_sym_modules, "modules");
static SCM module_prefix;
@@ -287,6 +290,7 @@
the_root_module = scm_intern0 ("the-root-module");
the_module = scm_intern0 ("the-module");
set_current_module = scm_intern0 ("set-current-module");
+ the_interaction_module = scm_intern0 ("the-interaction-module");
module_prefix = scm_permanent_object (SCM_LIST2 (scm_sym_app,
scm_sym_modules));
make_modules_in = scm_intern0 ("make-modules-in");
- eval, Dirk Herrmann, 2001/02/01
- Re: eval,
Dirk Herrmann <=
- Re: eval, Neil Jerram, 2001/02/01
- Re: eval, Dirk Herrmann, 2001/02/02
- Re: eval, Neil Jerram, 2001/02/02
- Re: eval, Dirk Herrmann, 2001/02/03
- Re: eval, Neil Jerram, 2001/02/04
- Re: eval, Dirk Herrmann, 2001/02/04
- Re: eval, Neil Jerram, 2001/02/05
- Re: eval, Dirk Herrmann, 2001/02/06
- Re: eval, Dirk Herrmann, 2001/02/04