aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Court`es2007-03-08 14:30:33 +0000
committerLudovic Court`es2007-03-08 14:30:33 +0000
commit5c472e01c77418125580627c5ee572c148b19079 (patch)
treea05584db63c50b3455028a7cd1db1451c68903fa
parent66b815af3d3d79a7f5a6da0f5aa882c56b9cc232 (diff)
downloadskribilo-5c472e01c77418125580627c5ee572c148b19079.tar.gz
skribilo-5c472e01c77418125580627c5ee572c148b19079.tar.lz
skribilo-5c472e01c77418125580627c5ee572c148b19079.zip
evaluator: Modularized the evaluation process.
* src/guile/skribilo/evaluator.scm (evaluate-ast-from-port): New. Based on code formerly in `evaluate-document-from-port'. Pass `(current-module)' instead of `module' when invoking `%evaluate'. (evaluate-document-from-port): Use it. git-archimport-id: lcourtes@laas.fr--2006-libre/skribilo--devo--1.2--patch-20
-rw-r--r--src/guile/skribilo/evaluator.scm48
1 files changed, 30 insertions, 18 deletions
diff --git a/src/guile/skribilo/evaluator.scm b/src/guile/skribilo/evaluator.scm
index 5067b59..0598c86 100644
--- a/src/guile/skribilo/evaluator.scm
+++ b/src/guile/skribilo/evaluator.scm
@@ -1,7 +1,7 @@
;;; eval.scm -- Skribilo evaluator.
;;;
-;;; Copyright 2003-2004 Erick Gallesio - I3S-CNRS/ESSI <eg@essi.fr>
-;;; Copyright 2005,2006 Ludovic Courtès <ludovic.courtes@laas.fr>
+;;; Copyright 2003, 2004 Erick Gallesio - I3S-CNRS/ESSI <eg@essi.fr>
+;;; Copyright 2005, 2006, 2007 Ludovic Courtès <ludovic.courtes@laas.fr>
;;;
;;;
;;; This program is free software; you can redistribute it and/or modify
@@ -21,7 +21,8 @@
(define-module (skribilo evaluator)
- :export (evaluate-document evaluate-document-from-port
+ :export (evaluate-ast-from-port
+ evaluate-document evaluate-document-from-port
load-document include-document *load-options*)
:autoload (skribilo parameters) (*verbose* *document-path*)
:autoload (skribilo location) (<location>)
@@ -73,7 +74,29 @@
result))
+;;;
+;;; EVALUATE-AST-FROM-PORT
+;;;
+(define* (evaluate-ast-from-port port :key (reader (*document-reader*))
+ (module (*skribilo-user-module*)))
+ ;; Evaluate code from PORT in MODULE, reading it with READER, and return an
+ ;; AST (resulting from the last form evaluated). The returned AST is
+ ;; unresolved and unverified.
+ (save-module-excursion
+ (lambda ()
+ (with-debug 10 'evaluate-ast-from-port
+
+ (set-current-module module)
+
+ (let loop ((exp (reader port))
+ (result #f))
+ (debug-item "exp=" exp)
+ (if (eof-object? exp)
+ result
+ (loop (reader port)
+ (%evaluate exp (current-module)))))))))
+
;;;
;;; EVALUATE-DOCUMENT
;;;
@@ -103,20 +126,9 @@
(debug-item "e=" e)
(if (not (engine? e))
(skribe-error 'evaluate-document-from-port "cannot find engine" engine)
- (save-module-excursion
- (lambda ()
- (with-debug 10 'evaluate-document-from-port
- (debug-item "exp=" exp))
- (set-current-module (*skribilo-user-module*))
-
- (let loop ((exp (reader port)))
- (if (eof-object? exp)
- (evaluate-document (%evaluate exp module)
- e :env env)
- (begin
- (evaluate-document (%evaluate exp module)
- e :env env)
- (loop (reader port)))))))))))
+ (let ((ast (evaluate-ast-from-port port :reader reader
+ :module module)))
+ (evaluate-document ast engine :env env))))))
@@ -186,7 +198,7 @@
;;;
(define* (include-document file :key (path (*document-path*))
(reader (*document-reader*))
- (module (*skribilo-user-module*)))
+ (module (current-module)))
(unless (every string? path)
(raise (condition (&invalid-argument-error (proc-name 'include-document)
(argument path)))))