Last active
February 23, 2018 23:14
-
-
Save tenderlove/3132221 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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