From 125baac85e912aaa45cd250d9254ab5f890f7058 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 28 Nov 2007 13:57:06 +0100 Subject: Add run-time module with fewer bindings; add `--compat' command-line option. * doc/user/Makefile.am (skrflags): New. Use `--compat=skribe' for now. * src/guile/Makefile.am (moduledir): New. (dist_guilemodule_DATA): Renamed to... (dist_module_DATA): This, for consistency. * src/guile/skribilo.scm (skribilo-options): Add `--compat'. (doskribe): New COMPAT argument. (skribilo): Honor `--compat'. * src/guile/skribilo/module.scm (%skribilo-user-imports): New. (make-run-time-module): Renamed to `make-skribe-user-module'. (make-skribilo-user-module): New. (make-user-module, user-module-flavor): New. (*skribilo-user-module*): Default to a `skribilo' module flavor. * src/guile/skribilo/package/diff.scm (make-diff-document-from-files): Use "(make-user-module 'skribilo)". --- doc/user/Makefile.am | 5 ++- src/guile/Makefile.am | 4 +- src/guile/skribilo.scm | 18 +++++--- src/guile/skribilo/module.scm | 85 +++++++++++++++++++++++++++++-------- src/guile/skribilo/package/diff.scm | 8 ++-- 5 files changed, 89 insertions(+), 31 deletions(-) diff --git a/doc/user/Makefile.am b/doc/user/Makefile.am index 0501ff6..11dad13 100644 --- a/doc/user/Makefile.am +++ b/doc/user/Makefile.am @@ -12,12 +12,13 @@ BUILT_SOURCES = doc-config.scm html_DATA = user.html skribilo = $(top_builddir)/src/pre-inst-skribilo +skrflags = -I ../ -P ../img --compat=skribe load_path = $(top_srcdir)/src/guile:$(top_srcdir)/src/guile/skribilo/package:$(top_builddir)/src/guile:$(top_srcdir)/doc/modules %.html: %.skb GUILE_LOAD_PATH=$(load_path):$$GUILE_LOAD_PATH \ - $(skribilo) --target html -I ../ -P ../img -o $@ $< + $(skribilo) $(skrflags) --target html -o $@ $< if HAVE_LOUT @@ -25,7 +26,7 @@ ps_DATA = user.ps %.lout: %.skb GUILE_LOAD_PATH=$(load_path):$$GUILE_LOAD_PATH \ - $(skribilo) --target lout -I ../ -P ../img -o $@ $< + $(skribilo) $(skrflags) --target lout -o $@ $< %.ps: %.lout $(LOUT) -c $(<:%.lout=%) -o $@ $< diff --git a/src/guile/Makefile.am b/src/guile/Makefile.am index 70194c1..227231b 100644 --- a/src/guile/Makefile.am +++ b/src/guile/Makefile.am @@ -1,4 +1,6 @@ SUBDIRS = skribilo -dist_guilemodule_DATA = skribilo.scm diff.scm +moduledir = $(guilemoduledir) +dist_module_DATA = skribilo.scm diff.scm + EXTRA_DIST = README diff --git a/src/guile/skribilo.scm b/src/guile/skribilo.scm index 8559de3..670587d 100644 --- a/src/guile/skribilo.scm +++ b/src/guile/skribilo.scm @@ -6,8 +6,8 @@ exec ${GUILE-guile} --debug -l $0 -c "(apply $main (cdr (command-line)))" "$@" ;;; skribilo.scm -- The Skribilo document processor. ;;; +;;; Copyright 2005, 2006, 2007 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 @@ -36,7 +36,7 @@ exec ${GUILE-guile} --debug -l $0 -c "(apply $main (cdr (command-line)))" "$@" (define-module (skribilo) - :autoload (skribilo module) (make-run-time-module *skribilo-user-module*) + :autoload (skribilo module) (make-user-module *skribilo-user-module*) :autoload (skribilo engine) (*current-engine*) :autoload (skribilo reader) (*document-reader*) :use-module (skribilo utils syntax)) @@ -83,6 +83,8 @@ specifications." (define-options skribilo-options (("reader" :alternate "R" :arg reader (nothing))) + (("compat" :arg compat + :help "use the COMPAT compatibility mode, e.g., `skribe'")) (("target" :alternate "t" :arg target :help "sets the output format to ") (set! engine (string->symbol target))) @@ -200,6 +202,7 @@ Processes a Skribilo/Skribe source file and produces its output. --reader=READER Use READER to parse the input file (by default, the `skribe' reader is used) --target=ENGINE Use ENGINE as the underlying engine + --compat=COMPAT Use COMPAT as the compatibility layer, e.g., \"skribe\" --help Give this help list --version Print program version @@ -359,7 +362,7 @@ Processes a Skribilo/Skribe source file and produces its output. (define *skribilo-output-port* (make-parameter (current-output-port))) -(define (doskribe) +(define (doskribe compat) (let ((output-port (current-output-port)) (user-module (current-module))) (dynamic-wind @@ -367,7 +370,7 @@ Processes a Skribilo/Skribe source file and produces its output. ;; FIXME: Using this technique, anything written to `stderr' will ;; also end up in the output file (e.g. Guile warnings). (set-current-output-port (*skribilo-output-port*)) - (let ((user (make-run-time-module))) + (let ((user (make-user-module (string->symbol compat)))) (set-current-module user) (*skribilo-user-module* user))) (lambda () @@ -400,6 +403,7 @@ Processes a Skribilo/Skribe source file and produces its output. (bib-path (option-ref options 'bib-path ".")) (source-path (option-ref options 'source-path ".")) (image-path (option-ref options 'image-path ".")) + (compat (option-ref options 'compat "skribilo")) (preload '()) (variants '()) @@ -465,8 +469,10 @@ Processes a Skribilo/Skribe source file and produces its output. (setvbuf (*skribilo-output-port*) _IOFBF 16384) (if source-file - (with-input-from-file source-file doskribe) - (doskribe)) + (with-input-from-file source-file + (lambda () + (doskribe compat))) + (doskribe compat)) ;; Make sure the output port is flushed before we leave. (force-output (*skribilo-output-port*)))))))) diff --git a/src/guile/skribilo/module.scm b/src/guile/skribilo/module.scm index 6511bb9..4655309 100644 --- a/src/guile/skribilo/module.scm +++ b/src/guile/skribilo/module.scm @@ -1,4 +1,4 @@ -;;; module.scm -- Integration of Skribe code as Guile modules. +;;; module.scm -- Execution environment for Skribilo documents. ;;; ;;; Copyright 2005, 2006, 2007 Ludovic Courtès ;;; @@ -22,7 +22,8 @@ :use-module (srfi srfi-1) :use-module (srfi srfi-39) :use-module (skribilo utils syntax) - :export (make-run-time-module *skribilo-user-module*)) + :export (make-user-module user-module-flavor + *skribilo-user-module*)) (fluid-set! current-reader %skribilo-module-reader) @@ -30,16 +31,22 @@ ;;; ;;; Commentary: ;;; -;;; This (fake) module defines a macro called `define-skribe-module' which -;;; allows to package Skribe code (which uses Skribe built-ins and most -;;; importantly a Skribe syntax) as a Guile module. This module -;;; automatically exports the macro as a core binding so that future -;;; `use-modules' referring to Skribe modules will work as expected. +;;; This module provides facilities to create run-time modules in which +;;; Skribilo documents (or legacy Skribe documents) are to be executed. ;;; ;;; Code: (define %skribilo-user-imports - ;; List of modules that should be imported by any good Skribilo module. + ;; List of modules needed by Skribilo modules. The list is much shorter + ;; than in the Skribe case, as we want to only provide the minimal set of + ;; bindings that documents need. In particular, only the `base' package is + ;; imported by default. + '((skribilo ast) + (skribilo config) + (skribilo package base))) + +(define %skribe-user-imports + ;; List of modules imported by legacy Skribe documents. '((srfi srfi-1) ;; lists (srfi srfi-13) ;; strings (ice-9 optargs) ;; `define*' @@ -63,8 +70,8 @@ (skribilo location) )) -(define %skribilo-user-autoloads - ;; List of auxiliary modules that may be lazily autoloaded. +(define %skribe-user-autoloads + ;; List of auxiliary modules be lazily autoloaded by legacy Skribe documents. '(((skribilo engine lout) . (!lout lout-illustration)) ((skribilo engine latex) . (!latex LaTeX TeX)) ((skribilo engine html) . (html-markup-class html-class @@ -88,27 +95,69 @@ ;;; -;;; MAKE-RUN-TIME-MODULE +;;; Run-time document modules. ;;; -(define (make-run-time-module) + +(define (make-skribe-user-module) "Return a new module that imports all the necessary bindings required for -execution of Skribilo/Skribe code." +execution of legacy Skribe code/documents." (let* ((the-module (make-module)) (autoloads (map (lambda (name+bindings) (make-autoload-interface the-module (car name+bindings) (cdr name+bindings))) - %skribilo-user-autoloads))) - (set-module-name! the-module '(skribilo-user)) + %skribe-user-autoloads))) + (set-module-name! the-module '(skribe-user)) (module-use-interfaces! the-module - (cons the-root-module + (cons the-scm-module (append (map resolve-interface - %skribilo-user-imports) + %skribe-user-imports) autoloads))) the-module)) +(define (make-skribilo-user-module) + "Return a new module that imports all the necessary bindings required for +Skribilo documents." + (let* ((the-module (make-module))) + (set-module-name! the-module '(skribilo-user)) + (module-use-interfaces! the-module + (cons the-scm-module + (map resolve-interface + %skribilo-user-imports))) + the-module)) + + +;;; +;;; Public interface. +;;; + +(define (make-user-module flavor . args) + "Return a new user module of type @var{flavor}, for use as an execution +environment for Skribilo document. @var{flavor} should be a symbol, e.g., +@code{skribilo} for the default execution environment or @code{skribe} for +a Skribe-compatible environment." + (case flavor + ((skribe skribe-1.2) + (make-skribe-user-module)) + ((skribilo) + (make-skribilo-user-module)) + (else + (error "unrecognized user module type" flavor)))) + +(define (user-module-flavor . args) + "Return a symbol denoting the kind of user module that is passed, e.g., +@code{'skribilo}." + (let ((module (if (null? args) + (*skribilo-user-module*) + (car args)))) + (case (module-name module) + ((skribe-user) 'skribe) + ((skribilo-user) 'skribilo) + (else #f)))) + ;; The current module in which the document is evaluated. -(define *skribilo-user-module* (make-parameter (make-run-time-module))) +(define *skribilo-user-module* + (make-parameter (make-user-module 'skribilo))) ;;; module.scm ends here diff --git a/src/guile/skribilo/package/diff.scm b/src/guile/skribilo/package/diff.scm index 2d634ec..95842aa 100644 --- a/src/guile/skribilo/package/diff.scm +++ b/src/guile/skribilo/package/diff.scm @@ -1,6 +1,6 @@ ;;; diff.scm -- A document difference highlighting package. ;;; -;;; Copyright 2007 Ludovic Courtès +;;; Copyright 2007 Ludovic Courtès ;;; ;;; ;;; This program is free software; you can redistribute it and/or modify @@ -31,7 +31,7 @@ :use-module (skribilo writer) :autoload (skribilo output) (output) :autoload (skribilo reader) (*document-reader*) - :autoload (skribilo module) (make-run-time-module) + :autoload (skribilo module) (make-user-module) :autoload (skribilo resolve) (resolve!) :autoload (skribilo evaluator) (evaluate-ast-from-port) :autoload (skribilo biblio) (*bib-table* make-bib-table) @@ -387,13 +387,13 @@ (skribe-message "diff: loading first document~%") (evaluate-ast-from-port (open-input-file old-file) :reader reader - :module (make-run-time-module)))) + :module (make-user-module 'skribilo)))) (ast2 (parameterize ((*bib-table* (make-bib-table 'doc-2))) (skribe-message "diff: loading second document~%") (evaluate-ast-from-port (open-input-file new-file) :reader reader - :module (make-run-time-module))))) + :module (make-user-module 'skribilo))))) (resolve! ast1 engine env) (resolve! ast2 engine env) -- cgit v1.2.3