Slide 78
Slide 78 text
Access Instruction From Ruby
def add
5 + 3
end
iseq =
RubyVM::InstructionSequence.of(method(:add))
pp iseq.to_a
$ ruby -rpp test.rb
["YARVInstructionSequence/SimpleDataFormat",
3,
1,
1,
{:arg_size=>0,
:local_size=>0,
:stack_max=>2,
:node_id=>7,
:code_location=>[1, 0, 3, 3],
:node_ids=>[3, 4, 6, -1]},
"add",
"test.rb",
"/Users/aaron/git/presentations/2021/RubyConf/test.rb",
1,
:method,
[],
{},
[],
[2,
:RUBY_EVENT_LINE,
:RUBY_EVENT_CALL,
[:putobject, 5],
[:putobject, 3],
[:opt_plus, {:mid=>:+, :flag=>16, :orig_argc=>1}],
3,
:RUBY_EVENT_RETURN,
[:leave]]]