From: Andy Wingo <wingo@pobox.com>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: Running non-scheme scripts: some thoughts
Date: Tue, 22 Jan 2013 15:59:24 +0100 [thread overview]
Message-ID: <87d2wxtgab.fsf@pobox.com> (raw)
In-Reply-To: <87y5fmbjav.fsf@gnu.org> ("Ludovic Courtès"'s message of "Mon, 21 Jan 2013 17:19:20 +0100")
[-- Attachment #1: Type: text/plain, Size: 360 bytes --]
On Mon 21 Jan 2013 17:19, ludo@gnu.org (Ludovic Courtès) writes:
> Bikeshedding: I’d prefer --language.
Changed, and addressed your other comments. Attached.
> Perhaps we could have a couple of tests for -c, for instance, as shell
> scripts in test-suite/standalone?
That would be great. Would you be interested in doing this? :-)
Andy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-add-language-argument.patch --]
[-- Type: text/x-diff, Size: 9700 bytes --]
From 3197ffffa1d1b51ecafb1565e984e98fdd0059f6 Mon Sep 17 00:00:00 2001
From: Andy Wingo <wingo@pobox.com>
Date: Mon, 21 Jan 2013 12:28:22 +0100
Subject: [PATCH] add --language argument
* module/ice-9/command-line.scm (*usage*): Make usage of capitalization
and sentences consistent (lower-case and semicolons, as in ls
--help).
Be less specific about languages (Scheme is the default but not the
only language).
Document --language.
(load/lang, eval-string/lang): New helpers.
(compile-shell-switches): Parse a --language argument, and use it to
set (current-language).
---
module/ice-9/command-line.scm | 115 +++++++++++++++++++++++++++--------------
1 file changed, 75 insertions(+), 40 deletions(-)
diff --git a/module/ice-9/command-line.scm b/module/ice-9/command-line.scm
index d60a6e3..b1d591b 100644
--- a/module/ice-9/command-line.scm
+++ b/module/ice-9/command-line.scm
@@ -1,6 +1,6 @@
;;; Parsing Guile's command-line
-;;; Copyright (C) 1994-1998, 2000-2011, 2012 Free Software Foundation, Inc.
+;;; Copyright (C) 1994-1998, 2000-2011, 2012, 2013 Free Software Foundation, Inc.
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -106,10 +106,10 @@ There is NO WARRANTY, to the extent permitted by law."))
(_ "General help using GNU software: <http://www.gnu.org/gethelp/>\n")))
(define *usage*
- (_ "Evaluate Scheme code, interactively or from a script.
+ (_ "Evaluate code with Guile, interactively or from a script.
- [-s] FILE load Scheme source code from FILE, and exit
- -c EXPR evalute Scheme expression EXPR, and exit
+ [-s] FILE load source code from FILE, and exit
+ -c EXPR evalute expression EXPR, and exit
-- stop scanning arguments; run interactively
The above switches stop argument processing, and pass all
@@ -118,21 +118,22 @@ If FILE begins with `-' the -s switch is mandatory.
-L DIRECTORY add DIRECTORY to the front of the module load path
-x EXTENSION add EXTENSION to the front of the load extensions
- -l FILE load Scheme source code from FILE
+ -l FILE load source code from FILE
-e FUNCTION after reading script, apply FUNCTION to
command line arguments
+ --language=LANG change language; default: scheme
-ds do -s script at this point
--debug start with the \"debugging\" VM engine
- --no-debug start with the normal VM engine, which also supports debugging
- Default is to enable debugging for interactive
+ --no-debug start with the normal VM engine (backtraces but
+ no breakpoints); default is --debug for interactive
use, but not for `-s' and `-c'.
--auto-compile compile source files automatically
--fresh-auto-compile invalidate auto-compilation cache
- --no-auto-compile disable automatic source file compilation
- Default is to enable auto-compilation of source
+ --no-auto-compile disable automatic source file compilation;
+ default is to enable auto-compilation of source
files.
- --listen[=P] Listen on a local port or a path for REPL clients.
- If P is not given, the default is local port 37146.
+ --listen[=P] listen on a local port or a path for REPL clients;
+ if P is not given, the default is local port 37146
-q inhibit loading of user init file
--use-srfi=LS load SRFI modules for the SRFIs in LS,
which is a list of numbers like \"2,13,14\"
@@ -163,20 +164,34 @@ If FILE begins with `-' the -s switch is mandatory.
(if fatal?
(exit 1))))
-(define (eval-string str)
- (call-with-input-string
- str
- (lambda (port)
- (let lp ()
- (let ((exp (read port)))
- (if (not (eof-object? exp))
- (begin
- (eval exp (current-module))
- (lp))))))))
+;; Try to avoid loading (ice-9 eval-string) and (system base compile) if
+;; possible.
+(define (eval-string/lang str)
+ (case (current-language)
+ ((scheme)
+ (call-with-input-string
+ str
+ (lambda (port)
+ (let lp ()
+ (let ((exp (read port)))
+ (if (not (eof-object? exp))
+ (begin
+ (eval exp (current-module))
+ (lp))))))))
+ (else
+ ((module-ref (resolve-module '(ice-9 eval-string)) 'eval-string) str))))
+
+(define (load/lang f)
+ (case (current-language)
+ ((scheme)
+ (load f))
+ (else
+ ((module-ref (resolve-module '(system base compile)) 'compile-file)
+ f #:to 'value))))
(define* (compile-shell-switches args #:optional (usage-name "guile"))
(let ((arg0 "guile")
- (do-script '())
+ (script-cell #f)
(entry-point #f)
(user-load-path '())
(user-extensions '())
@@ -197,36 +212,39 @@ If FILE begins with `-' the -s switch is mandatory.
(args (cdr args)))
(cond
((not (string-prefix? "-" arg)) ; foo
- ;; If we specified the -ds option, do-script is the cdr of
- ;; an expression like (load #f). We replace the car (i.e.,
+ ;; If we specified the -ds option, script-cell is a pointer to
+ ;; an expression like (load #f). We replace the cadr (i.e.,
;; the #f) with the script name.
(set! arg0 arg)
(set! interactive? #f)
- (if (pair? do-script)
+ (if script-cell
(begin
- (set-car! do-script arg0)
+ (set-car! script-cell arg0)
(finish args out))
- (finish args (cons `(load ,arg0) out))))
+ (finish args
+ (cons `((@@ (ice-9 command-line) load/lang) ,arg0)
+ out))))
((string=? arg "-s") ; foo
(if (null? args)
(error "missing argument to `-s' switch"))
(set! arg0 (car args))
(set! interactive? #f)
- (if (pair? do-script)
+ (if script-cell
(begin
- (set-car! do-script arg0)
+ (set-car! script-cell arg0)
(finish (cdr args) out))
- (finish (cdr args) (cons `(load ,arg0) out))))
+ (finish (cdr args)
+ (cons `((@@ (ice-9 command-line) load/lang) ,arg0)
+ out))))
((string=? arg "-c") ; evaluate expr
(if (null? args)
(error "missing argument to `-c' switch"))
(set! interactive? #f)
(finish (cdr args)
- ;; Use our own eval-string to avoid loading (ice-9
- ;; eval-string), which loads the compiler.
- (cons `((@@ (ice-9 command-line) eval-string) ,(car args))
+ (cons `((@@ (ice-9 command-line) eval-string/lang)
+ ,(car args))
out)))
((string=? arg "--") ; end args go interactive
@@ -236,7 +254,8 @@ If FILE begins with `-' the -s switch is mandatory.
(if (null? args)
(error "missing argument to `-l' switch"))
(parse (cdr args)
- (cons `(load ,(car args)) out)))
+ (cons `((@@ (ice-9 command-line) load/lang) ,arg0)
+ out)))
((string=? arg "-L") ; add to %load-path
(if (null? args)
@@ -273,14 +292,30 @@ If FILE begins with `-' the -s switch is mandatory.
(parse (cdr args)
out))
+ ((string-prefix? "--language=" arg) ; language
+ (parse args
+ (cons `(current-language
+ ',(string->symbol
+ (substring arg (string-length "--language="))))
+ out)))
+
+ ((string=? "--language" arg) ; language
+ (when (null? args)
+ (error "missing argument to `--language' option"))
+ (parse (cdr args)
+ (cons `(current-language ',(string->symbol (car args)))
+ out)))
+
((string=? arg "-ds") ; do script here
;; We put a dummy "load" expression, and let the -s put the
;; filename in.
- (if (pair? do-script)
- (error "the -ds switch may only be specified once")
- (set! do-script (list #f)))
+ (when script-cell
+ (error "the -ds switch may only be specified once"))
+ (set! script-cell (list #f))
(parse args
- (cons `(load . ,do-script) out)))
+ (acons '(@@ (ice-9 command-line) load/lang)
+ script-cell
+ out)))
((string=? arg "--debug")
(set! turn-on-debugging? #t)
@@ -364,8 +399,8 @@ If FILE begins with `-' the -s switch is mandatory.
(define (finish args out)
;; Check to make sure the -ds got a -s.
- (if (and (pair? do-script) (not (car do-script)))
- (error "the `-ds' switch requires the use of `-s' as well"))
+ (when (and script-cell (not (car script-cell)))
+ (error "the `-ds' switch requires the use of `-s' as well"))
;; Make any remaining arguments available to the
;; script/command/whatever.
--
1.7.10.4
[-- Attachment #3: Type: text/plain, Size: 26 bytes --]
--
http://wingolog.org/
next prev parent reply other threads:[~2013-01-22 14:59 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-11 15:31 Running non-scheme scripts: some thoughts Ian Price
2012-07-11 15:37 ` Andrew Gwozdziewycz
2012-07-11 22:15 ` Krister Svanlund
2012-07-12 3:12 ` nalaginrut
2012-07-12 3:27 ` William ML Leslie
2012-07-12 7:40 ` Neil Jerram
2012-08-26 21:16 ` Ludovic Courtès
2013-01-21 11:33 ` Andy Wingo
2013-01-21 16:19 ` Ludovic Courtès
2013-01-22 14:59 ` Andy Wingo [this message]
2013-01-22 21:45 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87d2wxtgab.fsf@pobox.com \
--to=wingo@pobox.com \
--cc=guile-devel@gnu.org \
--cc=ludo@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).