From: Nala Ginrut <nalaginrut@gmail.com>
To: Andy Wingo <wingo@pobox.com>
Cc: guile-devel@gnu.org
Subject: Re: [FEATURE] List all available languages
Date: Sat, 26 Jan 2013 00:46:26 +0800 [thread overview]
Message-ID: <1359132386.3676.47.camel@Renee-desktop.suse> (raw)
In-Reply-To: <878v7hcyj6.fsf@pobox.com>
[-- Attachment #1: Type: text/plain, Size: 2790 bytes --]
On Fri, 2013-01-25 at 12:06 +0100, Andy Wingo wrote:
> On Fri 25 Jan 2013 11:43, Nala Ginrut <nalaginrut@gmail.com> writes:
>
> > @@ -33,6 +33,9 @@
> >
> > (define-module (ice-9 command-line)
> > #:autoload (system vm vm) (set-default-vm-engine! set-vm-engine! the-vm)
> > + #:use-module (srfi srfi-1)
> > + #:use-module (ice-9 regex)
> > + #:use-module (ice-9 ftw)
> > #:export (compile-shell-switches
> > version-etc
> > *GPLv3+*
>
> For the reason given in the comment above this block, we cannot load
> these modules at startup. (Too expensive.) I suggest you make a little
> trampoline that does a module-ref at runtime like eval-string/lang.
>
Fixed with @ ;-)
> > +(define (not-inner-lang? str)
> > + (not (string-match
> > + "glil|glil\\.scm|assembly|assembly\\.scm|bytecode|objcode\\.scm|objcode|tree-il|tree-il\\.scm|value|\\.\\.|\\."
> > + str)))
> > +
> > +(define (get-all-available-languages)
> > + (let lp((rest (map (lambda (x) (string-append x "/language")) %load-path)) (result '()))
> > + (cond
> > + ((null? rest) (apply lset-union string=? result))
> > + (else
> > + (let ((ll (scandir (car rest) not-inner-lang?)))
> > + (lp (cdr rest) (if ll (cons ll result) result)))))))
>
> This is pretty nasty :) First of all I would request that you have no
> tabs please and stick to the 80-char limit. But more substantially I
> would want a function that returns a list of symbols and calls
> lookup-language on them, recursively filtering out any language that is
> the target of another compiler.
>
Recursively filtering from compiler-tower? Wow, that's definitely an
excess way than mine ;-D
Are you sure that's worthy?
Users just need a way to know what languages could be specified to
--language option.
> > + ((string=? "--list-languages" arg) ; list all languages
> > + (for-each (lambda (l)
> > + (format #t "~a~%" l))
> > + (get-all-available-languages))
> > + (exit 0))
> > +
>
> Also this needs to respect the 80-character width, somehow.
>
> > +(define (valid-lang? str)
> > + (not (string-match
> > + "[A-Za-z0-9_ -]+\\.scm|\\.\\.|\\."
> > + str)))
> > +
> > +(define (get-all-available-languages)
> > + (let lp((rest (map (lambda (x) (string-append x "/language")) %load-path)) (result '()))
> > + (cond
> > + ((null? rest) (apply lset-union string=? result))
> > + (else
> > + (let ((ll (scandir (car rest) valid-lang?)))
> > + (lp (cdr rest) (if ll (cons ll result) result)))))))
> > +
>
> Why is this duplicated here?
>
> > + -l, --list-languages list all available languages
>
> Probably we don't need the short option.
>
All fixed.
Patch updated.
Thanks!
> Regards,
>
> Andy
[-- Attachment #2: 0001-List-all-available-languages.patch --]
[-- Type: text/x-patch, Size: 4223 bytes --]
From a6b321e51a19d3726620a68f8db4902877872460 Mon Sep 17 00:00:00 2001
From: Nala Ginrut <nalaginrut@gmail.com>
Date: Fri, 25 Jan 2013 18:38:22 +0800
Subject: [PATCH] List all available languages.
* ice-9/command-line.scm: list available languages for 'guile' cmd.
* scripts/compile.scm: list all available languages for 'guild compile' cmd.
* NOTE: 'guile --list-languages' won't list inner languages, but 'guild compile -l'
will do that.
---
module/ice-9/command-line.scm | 23 +++++++++++++++++++++++
module/scripts/compile.scm | 13 +++++++++++++
2 files changed, 36 insertions(+)
diff --git a/module/ice-9/command-line.scm b/module/ice-9/command-line.scm
index 2aa50ec..60a1eee 100644
--- a/module/ice-9/command-line.scm
+++ b/module/ice-9/command-line.scm
@@ -122,6 +122,7 @@ If FILE begins with `-' the -s switch is mandatory.
-e FUNCTION after reading script, apply FUNCTION to
command line arguments
--language=LANG change language; default: scheme
+ --list-languages list all available languages
-ds do -s script at this point
--debug start with the \"debugging\" VM engine
--no-debug start with the normal VM engine (backtraces but
@@ -189,6 +190,22 @@ If FILE begins with `-' the -s switch is mandatory.
((module-ref (resolve-module '(system base compile)) 'compile-file)
f #:to 'value))))
+(define (not-inner-lang? str)
+ (not ((@ (ice-9 regex) string-match)
+ (string-append
+ "glil|glil\\.scm|assembly|assembly\\.scm|bytecode|objcode\\.scm"
+ "|objcode|tree-il|tree-il\\.scm|value|\\.\\.|\\.")
+ str)))
+
+(define (list-languages select)
+ (let lp((rest (map (lambda (x) (string-append x "/language")) %load-path))
+ (result '()))
+ (cond
+ ((null? rest) (apply (@ (srfi srfi-1) lset-union) string=? result))
+ (else
+ (let ((ll ((@ (ice-9 ftw) scandir) (car rest) select)))
+ (lp (cdr rest) (if ll (cons ll result) result)))))))
+
(define* (compile-shell-switches args #:optional (usage-name "guile"))
(let ((arg0 "guile")
(script-cell #f)
@@ -306,6 +323,12 @@ If FILE begins with `-' the -s switch is mandatory.
(cons `(current-language ',(string->symbol (car args)))
out)))
+ ((string=? "--list-languages" arg) ; list all languages
+ (for-each (lambda (l)
+ (format #t "~a~%" l))
+ (list-languages not-inner-lang?))
+ (exit 0))
+
((string=? arg "-ds") ; do script here
;; We put a dummy "load" expression, and let the -s put the
;; filename in.
diff --git a/module/scripts/compile.scm b/module/scripts/compile.scm
index 20db944..2b94bf9 100644
--- a/module/scripts/compile.scm
+++ b/module/scripts/compile.scm
@@ -45,6 +45,11 @@
(format (current-error-port) "error: ~{~a~}~%" messages)
(exit 1))
+(define (valid-lang? str)
+ (not ((@ (ice-9 regex) string-match)
+ "[A-Za-z0-9_ -]+\\.scm|\\.\\.|\\."
+ str)))
+
(define %options
;; Specifications of the command-line options.
(list (option '(#\h "help") #f #f
@@ -80,6 +85,13 @@
(option '(#\O "optimize") #f #f
(lambda (opt name arg result)
(alist-cons 'optimize? #t result)))
+ (option '("list-languages") #f #f
+ (lambda (opt name arg result)
+ (for-each (lambda (l)
+ (format #t "~a~%" l))
+ ((@@ (ice-9 command-line) list-languages)
+ valid-lang?))
+ (exit 0)))
(option '(#\f "from") #t #f
(lambda (opt name arg result)
(if (assoc-ref result 'from)
@@ -157,6 +169,7 @@ Compile each Guile source file FILE into a Guile object.
-W, --warn=WARNING emit warnings of type WARNING; use `--warn=help'
for a list of available warnings
+ --list-languages list all available languages
-f, --from=LANG specify a source language other than `scheme'
-t, --to=LANG specify a target language other than `objcode'
-T, --target=TRIPLET produce bytecode for host TRIPLET
--
1.7.10.4
next prev parent reply other threads:[~2013-01-25 16:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-23 11:28 [FEATURE] List all available languages Nala Ginrut
2013-01-25 9:56 ` Nala Ginrut
2013-01-25 10:43 ` Nala Ginrut
2013-01-25 11:06 ` Andy Wingo
2013-01-25 16:46 ` Nala Ginrut [this message]
2013-01-31 10:32 ` Andy Wingo
2013-02-01 2:34 ` Nala Ginrut
2013-01-25 20:06 ` Mark H Weaver
2013-01-25 22:50 ` Mark H Weaver
2013-01-26 1:44 ` Nala Ginrut
2013-01-27 10:21 ` Andy Wingo
2013-01-27 15:31 ` Mark H Weaver
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=1359132386.3676.47.camel@Renee-desktop.suse \
--to=nalaginrut@gmail.com \
--cc=guile-devel@gnu.org \
--cc=wingo@pobox.com \
/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).