Skip to content

Instantly share code, notes, and snippets.

@franckverrot
Forked from tenderlove/load_iseq.rb
Created February 23, 2018 23:14
Show Gist options
  • Save franckverrot/b6e4fb24d4115c69051424f34da68cef to your computer and use it in GitHub Desktop.
Save franckverrot/b6e4fb24d4115c69051424f34da68cef to your computer and use it in GitHub Desktop.
require 'fiddle'
require 'minitest/autorun'
class RubyVM
class InstructionSequence
address = Fiddle::Handle::DEFAULT['rb_iseq_load']
func = Fiddle::Function.new(address, [Fiddle::TYPE_VOIDP] * 3, Fiddle::TYPE_VOIDP)
define_singleton_method(:load) do |data, parent = nil, opt = nil|
func.call(Fiddle.dlwrap(data), parent, opt).to_value
end
end
end
class TestISeq < MiniTest::Test
def test_load
ins = RubyVM::InstructionSequence.new '5 + 10'
other = RubyVM::InstructionSequence.load ins.to_a
assert_equal ins.eval, other.eval
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment