本帖最后由 taroxd 于 2014-11-16 08:37 编辑
# Ruby Version >= 1.9 def a print 1 + 1 end puts RubyVM::InstructionSequence.disasm method(:a) output = <<EOF == disasm: <RubyVM::InstructionSequence:a@F:/Documents/test.rb>========= 0000 trace 8 ( 4) 0002 trace 1 ( 5) 0004 putself 0005 putobject_OP_INT2FIX_O_1_C_ 0006 putobject_OP_INT2FIX_O_1_C_ 0007 opt_plus <callinfo!mid:+, argc:1, ARGS_SKIP> 0009 opt_send_simple <callinfo!mid:print, argc:1, FCALL|ARGS_SKIP> 0011 trace 16 ( 6) 0013 leave ( 5) EOF
# Ruby Version >= 1.9
def a
print 1 + 1
end
puts RubyVM::InstructionSequence.disasm method(:a)
output = <<EOF
== disasm: <RubyVM::InstructionSequence:a@F:/Documents/test.rb>=========
0000 trace 8 ( 4)
0002 trace 1 ( 5)
0004 putself
0005 putobject_OP_INT2FIX_O_1_C_
0006 putobject_OP_INT2FIX_O_1_C_
0007 opt_plus <callinfo!mid:+, argc:1, ARGS_SKIP>
0009 opt_send_simple <callinfo!mid:print, argc:1, FCALL|ARGS_SKIP>
0011 trace 16 ( 6)
0013 leave ( 5)
EOF
不过 C 函数的话,我就没辙了
就算能搞出 C 函数,应该也是汇编代码了吧。 |