From 5c472e01c77418125580627c5ee572c148b19079 Mon Sep 17 00:00:00 2001 From: Ludovic Court`es Date: Thu, 8 Mar 2007 14:30:33 +0000 Subject: 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 --- src/guile/skribilo/evaluator.scm | 48 +++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'src') 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 -;;; Copyright 2005,2006 Ludovic Courtès +;;; Copyright 2003, 2004 Erick Gallesio - I3S-CNRS/ESSI +;;; Copyright 2005, 2006, 2007 Ludovic Courtès ;;; ;;; ;;; 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) () @@ -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))))) -- cgit v1.2.3