Skip to content

Instantly share code, notes, and snippets.

@steveklabnik
Created September 11, 2015 19:11
Show Gist options
  • Select an option

  • Save steveklabnik/f0938202b01176ae37c4 to your computer and use it in GitHub Desktop.

Select an option

Save steveklabnik/f0938202b01176ae37c4 to your computer and use it in GitHub Desktop.
x = RubyVM::InstructionSequence.new(%q{
class Foo
def hello
"hello"
end
end
f = Foo.new
f.hello()
})
puts x.disasm
== disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>==========
local table (size: 2, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, keyword: 0@3] s1)
[ 2] f
0000 trace 1 ( 2)
0002 putspecialobject 3
0004 putnil
0005 defineclass :Foo, <class:Foo>, 0
0009 pop
0010 trace 1 ( 8)
0012 getinlinecache 19, <is:0>
0015 getconstant :Foo
0017 setinlinecache <is:0>
0019 opt_send_simple <callinfo!mid:new, argc:0, ARGS_SKIP>
0021 setlocal_OP__WC__0 2
0023 trace 1 ( 9)
0025 getlocal_OP__WC__0 2
0027 opt_send_simple <callinfo!mid:hello, argc:0, ARGS_SKIP>
0029 leave
== disasm: <RubyVM::InstructionSequence:<class:Foo>@<compiled>>=========
0000 trace 2 ( 2)
0002 trace 1 ( 3)
0004 putspecialobject 1
0006 putspecialobject 2
0008 putobject :hello
0010 putiseq hello
0012 opt_send_simple <callinfo!mid:core#define_method, argc:3, ARGS_SKIP>
0014 trace 4 ( 6)
0016 leave ( 3)
== disasm: <RubyVM::InstructionSequence:hello@<compiled>>===============
0000 trace 8 ( 3)
0002 trace 1 ( 4)
0004 putstring "hello"
0006 trace 16 ( 5)
0008 leave ( 4)
class Foo
def hello
"hello"
end
end
f = Foo.new
f.hello()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment