From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nala Ginrut Newsgroups: gmane.lisp.guile.devel Subject: Re: [FEATURE] List all available languages Date: Fri, 25 Jan 2013 18:43:52 +0800 Organization: HFG Message-ID: <1359110632.3676.30.camel@Renee-desktop.suse> References: <1358940518.3676.5.camel@Renee-desktop.suse> <1359107760.3676.28.camel@Renee-desktop.suse> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-zUte8DFvv2Af+MNBDiTo" X-Trace: ger.gmane.org 1359110648 13586 80.91.229.3 (25 Jan 2013 10:44:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 25 Jan 2013 10:44:08 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Jan 25 11:44:28 2013 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Tyglm-0000sq-S0 for guile-devel@m.gmane.org; Fri, 25 Jan 2013 11:44:27 +0100 Original-Received: from localhost ([::1]:37962 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyglV-00035z-Fo for guile-devel@m.gmane.org; Fri, 25 Jan 2013 05:44:09 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:44371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyglQ-00035i-GD for guile-devel@gnu.org; Fri, 25 Jan 2013 05:44:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TyglL-0000ep-OW for guile-devel@gnu.org; Fri, 25 Jan 2013 05:44:04 -0500 Original-Received: from mail-pb0-f46.google.com ([209.85.160.46]:35130) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyglL-0000eU-FH for guile-devel@gnu.org; Fri, 25 Jan 2013 05:43:59 -0500 Original-Received: by mail-pb0-f46.google.com with SMTP id uo15so145146pbc.33 for ; Fri, 25 Jan 2013 02:43:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:subject:from:to:date:in-reply-to:references :organization:content-type:x-mailer:mime-version; bh=qE6DjwntR7lVsBLKadvAnzjgQhe/3PesfvLUyVNQ8Ps=; b=Uy4kS/5W9GIC0kAWNmTllVY+EPbuNd4EwDy2T5GqYj/7wbtWucjJ/U9N4Y50TjwH4s Qmy+Dx8NnaVR843H1ZHNorVsjYbgabGz2vOCkg+++Y5DxAHS/SGaqQljRxHPLGfj3DJq wCBt0VrnFATdxZgozUZtJ44nEicc6JcpCLtPY8EcYCLvptATZAU20BYFb1nwrg4z8r8F GxLvUUld7ZmijTUsKtq0Xs+WjEX+aVJR5wpu3APX8Wj17HxiUFcarMaS8w1JMdpvsNDk W14G5rANg5BWRI9/ir1EqFOXmOrA6APEHrIKOFS1GyI3K6LhuxTpW1G8PsMKvHsCIEDq u+4w== X-Received: by 10.66.79.74 with SMTP id h10mr12486027pax.25.1359110637718; Fri, 25 Jan 2013 02:43:57 -0800 (PST) Original-Received: from [147.2.147.112] ([61.14.130.226]) by mx.google.com with ESMTPS id nw9sm462109pbb.42.2013.01.25.02.43.54 (version=SSLv3 cipher=RC4-SHA bits=128/128); Fri, 25 Jan 2013 02:43:56 -0800 (PST) In-Reply-To: <1359107760.3676.28.camel@Renee-desktop.suse> X-Mailer: Evolution 3.4.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.160.46 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:15589 Archived-At: --=-zUte8DFvv2Af+MNBDiTo Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Here is a patch to provide listing all languages for 'guile' and 'guild compile' command. Thanks! --=-zUte8DFvv2Af+MNBDiTo Content-Disposition: attachment; filename="0001-List-all-available-languages.patch" Content-Type: text/x-patch; name="0001-List-all-available-languages.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit >From f06fcd9e997e0bd6de9f85c22d75bd7a05545627 Mon Sep 17 00:00:00 2001 From: Nala Ginrut 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 | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/module/ice-9/command-line.scm b/module/ice-9/command-line.scm index 2aa50ec..57d93c7 100644 --- a/module/ice-9/command-line.scm +++ b/module/ice-9/command-line.scm @@ -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+* @@ -122,6 +125,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 +193,19 @@ 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 (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))))))) + (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)) + (get-all-available-languages)) + (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..7e74eb9 100644 --- a/module/scripts/compile.scm +++ b/module/scripts/compile.scm @@ -35,6 +35,8 @@ #:use-module (srfi srfi-1) #:use-module (srfi srfi-13) #:use-module (srfi srfi-37) + #:use-module (ice-9 regex) + #:use-module (ice-9 ftw) #:use-module (ice-9 format) #:export (compile)) @@ -45,6 +47,19 @@ (format (current-error-port) "error: ~{~a~}~%" messages) (exit 1)) +(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))))))) + (define %options ;; Specifications of the command-line options. (list (option '(#\h "help") #f #f @@ -80,6 +95,12 @@ (option '(#\O "optimize") #f #f (lambda (opt name arg result) (alist-cons 'optimize? #t result))) + (option '(#\l "list-languages") #f #f + (lambda (opt name arg result) + (for-each (lambda (l) + (format #t "~a~%" l)) + (get-all-available-languages)) + (exit 0))) (option '(#\f "from") #t #f (lambda (opt name arg result) (if (assoc-ref result 'from) @@ -157,6 +178,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 + -l, --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 --=-zUte8DFvv2Af+MNBDiTo--