本文簡要介紹ruby語言中 RubyVM::InstructionSequence.disasm
的用法。
用法
disasm(body) → str
disassemble(body) → str
接受 body
、 Method
或 Proc
對象,並返回 String
以及 body
的人類可讀指令。
對於 Method
對象:
# /tmp/method.rb
def hello
puts "hello, world"
end
puts RubyVM::InstructionSequence.disasm(method(:hello))
產生:
== disasm: <RubyVM::InstructionSequence:hello@/tmp/method.rb>============ 0000 trace 8 ( 1) 0002 trace 1 ( 2) 0004 putself 0005 putstring "hello, world" 0007 send :puts, 1, nil, 8, <ic:0> 0013 trace 16 ( 3) 0015 leave ( 2)
對於一個過程:
# /tmp/proc.rb
p = proc { num = 1 + 2 }
puts RubyVM::InstructionSequence.disasm(p)
產生:
== disasm: <RubyVM::InstructionSequence:block in <main>@/tmp/proc.rb>=== == catch table | catch type: redo st: 0000 ed: 0012 sp: 0000 cont: 0000 | catch type: next st: 0000 ed: 0012 sp: 0000 cont: 0012 |------------------------------------------------------------------------ local table (size: 2, argc: 0 [opts: 0, rest: -1, post: 0, block: -1] s1) [ 2] num 0000 trace 1 ( 1) 0002 putobject 1 0004 putobject 2 0006 opt_plus <ic:1> 0008 dup 0009 setlocal num, 0 0012 leave
相關用法
- Ruby InstructionSequence.disassemble用法及代碼示例
- Ruby InstructionSequence.base_label用法及代碼示例
- Ruby InstructionSequence.first_lineno用法及代碼示例
- Ruby InstructionSequence.of用法及代碼示例
- Ruby InstructionSequence.path用法及代碼示例
- Ruby InstructionSequence.compile用法及代碼示例
- Ruby InstructionSequence.compile_file用法及代碼示例
- Ruby InstructionSequence.label用法及代碼示例
- Ruby InstructionSequence.absolute_path用法及代碼示例
- Ruby InstructionSequence.eval用法及代碼示例
- Ruby Installer.install用法及代碼示例
- Ruby Installer.shebang用法及代碼示例
- Ruby Inspector.def_inspector用法及代碼示例
- Ruby Inspector類用法及代碼示例
- Ruby Integer.nobits?用法及代碼示例
- Ruby Integer lcm()用法及代碼示例
- Ruby Integer.self >=用法及代碼示例
- Ruby Integer.self >>用法及代碼示例
- Ruby Integer.next用法及代碼示例
- Ruby Integer.self ** numeric用法及代碼示例
- Ruby Integer integer?用法及代碼示例
- Ruby Integer.truncate用法及代碼示例
- Ruby Integer digits用法及代碼示例
- Ruby Integer divmod()用法及代碼示例
- Ruby Inflate.inflate用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 InstructionSequence.disasm。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。