summaryrefslogtreecommitdiff
path: root/geiser
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2009-02-21 00:59:57 +0100
committerJose Antonio Ortega Ruiz <jao@gnu.org>2009-02-21 00:59:57 +0100
commit8377f5e282cf318a2af9fa8864aaf15ff2fb22ef (patch)
treec3eca203ea6db784efd5eb7a56cfa9d86e307f86 /geiser
parent2ac3f911a36efe0589a6fa8b62305bd6985851ed (diff)
downloadgeiser-guile-8377f5e282cf318a2af9fa8864aaf15ff2fb22ef.tar.gz
geiser-guile-8377f5e282cf318a2af9fa8864aaf15ff2fb22ef.tar.bz2
Refactoring of the eval/compile procedures.
Diffstat (limited to 'geiser')
-rw-r--r--geiser/emacs.scm46
1 files changed, 20 insertions, 26 deletions
diff --git a/geiser/emacs.scm b/geiser/emacs.scm
index 3c66eb2..382958d 100644
--- a/geiser/emacs.scm
+++ b/geiser/emacs.scm
@@ -58,26 +58,34 @@
(cons 'msg (if msg (apply format (cons #f (cons msg margs))) '()))
(cons 'rest (or rest '())))))
-(define (ge:eval form module-name)
- "Evals @var{form} in the module designated by @var{module-name}.
-If @var{module-name} is @var{#f} or resolution fails, the current module is used instead.
-The result is a list of the form ((RESULT . <form-value>) (OUTPUT . <string>))
-if no evaluation error happens, or ((ERROR (KEY . <error-key>) <error-arg>...))
-in case of errors. Each error arg is a cons (NAME . VALUE), where NAME includes
-SUBR, MSG and REST."
+(define (evaluate form module evaluator)
(let ((module (or (and (list? module-name)
(resolve-module module-name))
(current-module))))
(catch #t
(lambda ()
(let ((result #f))
- (let ((output
- (with-output-to-string
- (lambda ()
- (set! result (eval form module))))))
+ (let ((output (with-output-to-string
+ (lambda ()
+ (set! result (evaluator form module))))))
(write-result result output))))
write-error)))
+(define (eval-compile form module)
+ (save-module-excursion
+ (lambda ()
+ (set-current-module module)
+ (compile form))))
+
+(define (ge:eval form module-name)
+ "Evals @var{form} in the module designated by @var{module-name}.
+If @var{module-name} is @var{#f} or resolution fails, the current module is used instead.
+The result is a list of the form ((RESULT . <form-value>) (OUTPUT . <string>))
+if no evaluation error happens, or ((ERROR (KEY . <error-key>) <error-arg>...))
+in case of errors. Each error arg is a cons (NAME . VALUE), where NAME includes
+SUBR, MSG and REST."
+ (evaluate form module-name eval))
+
(define (ge:compile form module-name)
"Compiles @var{form} in the module designated by @var{module-name}.
If @var{module-name} is @var{#f} or resolution fails, the current module is used instead.
@@ -85,21 +93,7 @@ The result is a list of the form ((RESULT . <form-value>) (OUTPUT . <string>))
if no evaluation error happens, or ((ERROR (KEY . <error-key>) <error-arg>...))
in case of errors. Each error arg is a cons (NAME . VALUE), where NAME includes
SUBR, MSG and REST."
- (let ((module (or (and (list? module-name)
- (resolve-module module-name))
- (current-module))))
- (catch #t
- (lambda ()
- (let ((result #f))
- (let ((output
- (with-output-to-string
- (lambda ()
- (save-module-excursion
- (lambda ()
- (set-current-module module)
- (set! result (compile form))))))))
- (write-result result output))))
- write-error)))
+ (evaluate form module-name eval-compile))
(define (ge:compile-file path)
"Compile and load file, given its full @var{path}."