Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Last active February 23, 2018 23:14
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tenderlove/3132221 to your computer and use it in GitHub Desktop.
Save tenderlove/3132221 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