class Sapphire::Command

Public Instance Methods

generates(*args) click to toggle source
# File lib/sapphire-exp-env.rb, line 14
def generates(*args)
  name = args.shift
  case name
  when /rvm/
    object = args.shift
    case object
    when /instructions/
      create_instruction_class
    else
    end
  end
end

Private Instance Methods

create_instruction_class() click to toggle source
# File lib/sapphire-exp-env.rb, line 29
def create_instruction_class
  url = 'https://raw.github.com/ruby/ruby/trunk/insns.def'
  file_name = url.split(/\//).last
  begin
    open(url) do |source|
      open(file_name, "w+b") do |output|
        output.print source.read
      end
    end
  rescue
    raise "retrieving error(insns.def)"
  end
  open("instructions.rb", "w+b") do |output|
    output.print put_instruction_class_header
    output.print put_instruction_class_insn file_name, output
    output.print put_instruction_class_footer    
  end
end
put_instruction_class_header() click to toggle source
# File lib/sapphire-exp-env.rb, line 48
    def put_instruction_class_header
      return <<-EOL2
class RubyVM
  class InstructionSequence
    class Instruction
      InsnID2NO = {
      EOL2
    end
put_instruction_class_insn(file_name, output) click to toggle source
# File lib/sapphire-exp-env.rb, line 57
    def put_instruction_class_insn(file_name, output)
      open(file_name) {|file|
        ino = -1 # initial instruction no
        while line = file.gets
          if /DEFINE_INSN/ =~ line
            iname = file.gets.chop
            if ino != -1
              output.print <<-"EOL1"
        :#{iname} => #{ino},
              EOL1
            end
            ino += 1
          end
        end
      }
    end