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

ruby-changes:49947

From: k0kubun <ko1@a...>
Date: Sat, 27 Jan 2018 11:14:23 +0900 (JST)
Subject: [ruby-changes:49947] k0kubun:r62065 (trunk): insns2vm.rb: make #generate_parser private

k0kubun	2018-01-27 11:14:20 +0900 (Sat, 27 Jan 2018)

  New Revision: 62065

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62065

  Log:
    insns2vm.rb: make #generate_parser private
    
    which is only used by #router.
    
    To make it private, we need to stop defining them on top-level.

  Modified files:
    trunk/tool/insns2vm.rb
    trunk/tool/ruby_vm/scripts/insns2vm.rb
Index: tool/ruby_vm/scripts/insns2vm.rb
===================================================================
--- tool/ruby_vm/scripts/insns2vm.rb	(revision 62064)
+++ tool/ruby_vm/scripts/insns2vm.rb	(revision 62065)
@@ -13,78 +13,81 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/scripts/insns2vm.rb#L13
 require 'optparse'
 require_relative '../controllers/application_controller.rb'
 
-def router argv
-  options = { destdir: Dir.getwd }
-  targets = generate_parser(options).parse argv
-  return targets.map do |i|
-    next ApplicationController.new.generate i, options[:destdir]
-  end
-end
-
-def generate_parser(options)
-  OptionParser.new do |this|
-    this.on "-I", "--srcdir=DIR", <<-'end'
-      Historically this option has been passed to the script.  This is
-      supposedly because at the beginning the script was placed
-      outside of the ruby source tree.  Decades passed since the merge
-      of YARV, now I can safely assume this feature is obsolescent.
-      Just ignore the passed value here.
-    end
-
-    this.on "-L", "--vpath=SPEC", <<-'end'
-      Likewise, this option is no longer supported.
-    end
-
-    this.on "--path-separator=SEP", /\A(?:\W\z|\.(\W).+)/, <<-'end'
-      Old script says this option is a "separator for vpath".  I am
-      confident we no longer need this option.
-    end
-
-    this.on "-Dname", "--enable=name[,name...]", Array, <<-'end'
-      This option used to override VM option that is defined in
-      vm_opts.h. Now it is officially unsupported because vm_opts.h to
-      remain mismatched with this option must break things.  Just edit
-      vm_opts.h directly.
-    end
-
-    this.on "-Uname", "--disable=name[,name...]", Array, <<-'end'
-      This option used to override VM option that is defined in
-      vm_opts.h. Now it is officially unsupported because vm_opts.h to
-      remain mismatched with this option must break things.  Just edit
-      vm_opts.h directly.
-    end
-
-    this.on "-i", "--insnsdef=FILE", "--instructions-def", <<-'end'
-      This option used to specify alternative path to insns.def.  For
-      the same reason to ignore -I, we no longer support this.
-    end
-
-    this.on "-o", "--opt-operanddef=FILE", "--opt-operand-def", <<-'end'
-      This option used to specify alternative path to opt_operand.def.
-      For the same reason to ignore -I, we no longer support this.
-    end
-
-    this.on "-u", "--opt-insnunifdef=FILE", "--opt-insn-unif-def", <<-'end'
-      This option used to specify alternative path to
-      opt_insn_unif.def.  For the same reason to ignore -I, we no
-      longer support this.
-    end
-
-    this.on "-C", "--[no-]use-const", <<-'end'
-      We use const whenever possible now so this option is ignored.
-      The author believes that C compilers can constant-fold.
-    end
-
-    this.on "-d", "--destdir", "--output-directory=DIR", <<-'begin' do |dir|
-      THIS IS THE ONLY OPTION THAT WORKS today.  Change destination
-      directory from the current working directory to the given path.
-    begin
-      raise "directory was not found in '#{dir}'" unless Dir.eixst?(dir)
-      options[:destdir] = dir
+module RubyVM::Insns2VM
+  def self.router argv
+    options = { destdir: Dir.getwd }
+    targets = generate_parser(options).parse argv
+    return targets.map do |i|
+      next ApplicationController.new.generate i, options[:destdir]
     end
+  end
 
-    this.on "-V", "--[no-]verbose", <<-'end'
-      Please let us ignore this and be modest.
+  def self.generate_parser(options)
+    OptionParser.new do |this|
+      this.on "-I", "--srcdir=DIR", <<-'end'
+        Historically this option has been passed to the script.  This is
+        supposedly because at the beginning the script was placed
+        outside of the ruby source tree.  Decades passed since the merge
+        of YARV, now I can safely assume this feature is obsolescent.
+        Just ignore the passed value here.
+      end
+
+      this.on "-L", "--vpath=SPEC", <<-'end'
+        Likewise, this option is no longer supported.
+      end
+
+      this.on "--path-separator=SEP", /\A(?:\W\z|\.(\W).+)/, <<-'end'
+        Old script says this option is a "separator for vpath".  I am
+        confident we no longer need this option.
+      end
+
+      this.on "-Dname", "--enable=name[,name...]", Array, <<-'end'
+        This option used to override VM option that is defined in
+        vm_opts.h. Now it is officially unsupported because vm_opts.h to
+        remain mismatched with this option must break things.  Just edit
+        vm_opts.h directly.
+      end
+
+      this.on "-Uname", "--disable=name[,name...]", Array, <<-'end'
+        This option used to override VM option that is defined in
+        vm_opts.h. Now it is officially unsupported because vm_opts.h to
+        remain mismatched with this option must break things.  Just edit
+        vm_opts.h directly.
+      end
+
+      this.on "-i", "--insnsdef=FILE", "--instructions-def", <<-'end'
+        This option used to specify alternative path to insns.def.  For
+        the same reason to ignore -I, we no longer support this.
+      end
+
+      this.on "-o", "--opt-operanddef=FILE", "--opt-operand-def", <<-'end'
+        This option used to specify alternative path to opt_operand.def.
+        For the same reason to ignore -I, we no longer support this.
+      end
+
+      this.on "-u", "--opt-insnunifdef=FILE", "--opt-insn-unif-def", <<-'end'
+        This option used to specify alternative path to
+        opt_insn_unif.def.  For the same reason to ignore -I, we no
+        longer support this.
+      end
+
+      this.on "-C", "--[no-]use-const", <<-'end'
+        We use const whenever possible now so this option is ignored.
+        The author believes that C compilers can constant-fold.
+      end
+
+      this.on "-d", "--destdir", "--output-directory=DIR", <<-'begin' do |dir|
+        THIS IS THE ONLY OPTION THAT WORKS today.  Change destination
+        directory from the current working directory to the given path.
+      begin
+        raise "directory was not found in '#{dir}'" unless Dir.eixst?(dir)
+        options[:destdir] = dir
+      end
+
+      this.on "-V", "--[no-]verbose", <<-'end'
+        Please let us ignore this and be modest.
+      end
     end
   end
+  private_class_method :generate_parser
 end
Index: tool/insns2vm.rb
===================================================================
--- tool/insns2vm.rb	(revision 62064)
+++ tool/insns2vm.rb	(revision 62065)
@@ -6,7 +6,7 @@ https://github.com/ruby/ruby/blob/trunk/tool/insns2vm.rb#L6
 require_relative 'ruby_vm/scripts/insns2vm'
 
 if $0 == __FILE__
-  router(ARGV).each do |(path, generator)|
+  RubyVM::Insns2VM.router(ARGV).each do |(path, generator)|
     str = generator.generate path
     path.open 'wb:utf-8' do |fp|
       fp.write str

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

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