[前][次][番号順一覧][スレッド一覧]

ruby-changes:4995

From: ko1@a...
Date: Tue, 20 May 2008 12:14:07 +0900 (JST)
Subject: [ruby-changes:4995] nobu - Ruby:r16488 (trunk): * ruby.c (proc_options, process_options): --dump option.

nobu	2008-05-20 12:13:52 +0900 (Tue, 20 May 2008)

  New Revision: 16488

  Modified files:
    trunk/ChangeLog
    trunk/ruby.c

  Log:
    * ruby.c (proc_options, process_options): --dump option.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ruby.c?r1=16488&r2=16487&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16488&r2=16487&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 16487)
+++ ChangeLog	(revision 16488)
@@ -1,3 +1,7 @@
+Tue May 20 12:13:50 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* ruby.c (proc_options, process_options): --dump option.
+
 Tue May 20 11:36:06 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* include/ruby/ruby.h (PRI[diouxX]VALUE): printf format for VALUE.
Index: ruby.c
===================================================================
--- ruby.c	(revision 16487)
+++ ruby.c	(revision 16488)
@@ -72,6 +72,11 @@
     disable_rubyopt,
 };
 
+#define DUMP_BIT(bit) (1U << dump_##bit)
+enum dump_flag_bits {
+    dump_insns,
+};
+
 struct cmdline_options {
     int sflag, xflag;
     int do_loop, do_print;
@@ -83,6 +88,7 @@
     unsigned int disable;
     int verbose;
     int yydebug;
+    unsigned int dump;
     char *script;
     VALUE script_name;
     VALUE e_script;
@@ -587,6 +593,14 @@
     rb_warn("unknown argument for --disable: `%.*s'", len, str);
 }
 
+static void
+dump_option(const char *str, int len, void *arg)
+{
+#define SET_WHEN_DUMP(bit) SET_WHEN(#bit, DUMP_BIT(bit), str, len)
+    SET_WHEN_DUMP(insns);
+    rb_warn("don't know how to dump `%.*s', (insns)", len, str);
+}
+
 static int
 proc_options(int argc, char **argv, struct cmdline_options *opt)
 {
@@ -874,6 +888,10 @@
 	    }
 	    else if (strcmp("yydebug", s) == 0)
 		opt->yydebug = 1;
+	    else if (strncmp("dump", s, n = 4) == 0 && (!s[n] || s[n] == '=')) {
+		if (!(s += n + 1)[-1] && (!--argc || !(s = *++argv)) && *s != '-') break;
+		ruby_each_words(s, dump_option, &opt->dump);
+	    }
 	    else if (strcmp("help", s) == 0) {
 		usage(origarg.argv[0]);
 		rb_exit(EXIT_SUCCESS);
@@ -949,6 +967,7 @@
     char **argv = argp->argv;
     NODE *tree = 0;
     VALUE parser;
+    VALUE iseq;
     rb_encoding *enc, *lenc;
     const char *s;
     char fbuf[MAXPATHLEN];
@@ -1121,8 +1140,14 @@
 	tree = rb_parser_while_loop(parser, tree, opt->do_line, opt->do_split);
     }
 
-    return rb_iseq_new(tree, rb_str_new2("<main>"),
+    iseq = rb_iseq_new(tree, rb_str_new2("<main>"),
 		       opt->script_name, Qfalse, ISEQ_TYPE_TOP);
+    if (opt->dump & DUMP_BIT(insns)) {
+	rb_io_write(rb_stdout, ruby_iseq_disasm(iseq));
+	rb_io_flush(rb_stdout);
+    }
+
+    return iseq;
 }
 
 static NODE *

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]