Ruby-1.9.1
1 >> puts RubyVM::InstructionSequence.new("puts 'Hello, world!'").disasm #=> nil 2 == disasm: <RubyVM::Instructio nSequence:<compiled>@<compiled>>========== 3 0000 trace 1 ( 1) 4 0002 putnil 5 0003 putstring "Hello, world!" 6 0005 send :puts, 1, nil, 8, <ic> 7 0011 leave
生成したInstractio
1 >> RubyVM::InstructionSequence.new("puts 'Hello, world!'").eval #=> nil 2 Hello, world!
さらに、to_aメソッドで個々のインストラクションに分解する事も出来ます。
1 >> RubyVM::InstructionSequence.new("puts 'Hello, world!'").to_a 2 ["YARVInstru ctionSeque nce/Simple DataFormat ", 1, 1, 1, {:arg_size=>0, :local_size =>1, :stack_max=>2}, "<compiled>", "<compiled>", :top, [], 0, [], [1, [:trace, 1], [:putnil], [:putstring, "Hello, world!"], [:send, :puts, 1, nil, 8, nil], [:leave]]]
posted by
genki
on Fri 20 Feb 2009
at 01:49