Skip to content

Instantly share code, notes, and snippets.

@kejadlen
Created February 4, 2014 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kejadlen/8813397 to your computer and use it in GitHub Desktop.
Save kejadlen/8813397 to your computer and use it in GitHub Desktop.
~/Dropbox/tmp
❯ head -n 20 test.rb
# encoding: utf-8
def foo(i)
!!i
end
def bar(i)
i ? true : false
end
def baz(i)
false | i
end
%i[ foo bar baz ].each do |meth|
puts RubyVM::InstructionSequence.disasm(method(meth))
end
__END__
~/Dropbox/tmp
❯ ruby test.rb
== disasm: <RubyVM::InstructionSequence:foo@test.rb>====================
local table (size: 2, argc: 1 [opts: 0, rest: -1, post: 0, block: -1, keyword: 0@3] s1)
[ 2] i<Arg>
0000 trace 8 ( 3)
0002 trace 1 ( 4)
0004 getlocal_OP__WC__0 2
0006 opt_not <callinfo!mid:!, argc:0, ARGS_SKIP>
0008 opt_not <callinfo!mid:!, argc:0, ARGS_SKIP>
0010 trace 16 ( 5)
0012 leave ( 4)
== disasm: <RubyVM::InstructionSequence:bar@test.rb>====================
local table (size: 2, argc: 1 [opts: 0, rest: -1, post: 0, block: -1, keyword: 0@3] s1)
[ 2] i<Arg>
0000 trace 8 ( 7)
0002 trace 1 ( 8)
0004 getlocal_OP__WC__0 2
0006 branchunless 12
0008 putobject true
0010 jump 16
0012 trace 1
0014 putobject false
0016 trace 16 ( 9)
0018 leave ( 8)
== disasm: <RubyVM::InstructionSequence:baz@test.rb>====================
local table (size: 2, argc: 1 [opts: 0, rest: -1, post: 0, block: -1, keyword: 0@3] s1)
[ 2] i<Arg>
0000 trace 8 ( 11)
0002 trace 1 ( 12)
0004 putobject false
0006 getlocal_OP__WC__0 2
0008 opt_send_simple <callinfo!mid:|, argc:1, ARGS_SKIP>
0010 trace 16 ( 13)
0012 leave ( 12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment