Skip to content

Instantly share code, notes, and snippets.

@benolee
Created January 21, 2011 01:18
Show Gist options
  • Save benolee/789085 to your computer and use it in GitHub Desktop.
Save benolee/789085 to your computer and use it in GitHub Desktop.
irb(main):009:0> puts RubyVM::InstructionSequence.new("class Person;def to_s;'bob';end;end;person=Person.new;person.to_s").disassemble
== disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>==========
local table (size: 2, argc: 0 [opts: 0, rest: -1, post: 0, block: -1] s1)
[ 2] person
0000 trace 1 ( 1)
0002 putspecialobject 3
0004 putnil
0005 defineclass :Person, <class:Person>, 0
0009 pop
0010 trace 1
0012 getinlinecache 19, <ic:0>
0015 getconstant :Person
0017 setinlinecache <ic:0>
0019 send :new, 0, nil, 0, <ic:1>
0025 setlocal person
0027 trace 1
0029 getlocal person
0031 send :to_s, 0, nil, 0, <ic:2>
0037 leave
== disasm: <RubyVM::InstructionSequence:<class:Person>@<compiled>>======
0000 trace 2 ( 1)
0002 trace 1
0004 putspecialobject 1
0006 putspecialobject 2
0008 putobject :to_s
0010 putiseq to_s
0012 send :"core#define_method", 3, nil, 0, <ic:0>
0018 trace 4
0020 leave
== disasm: <RubyVM::InstructionSequence:to_s@<compiled>>================
0000 trace 8 ( 1)
0002 trace 1
0004 putstring "bob"
0006 trace 16
0008 leave
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment