RubyVM::InstructionSequence is great, it's great that you can compile code
and disassemble. But for my current project (which is currently a toy, but
this may have other useful applications), what I'd really like is to feed
an instruction sequence constructed in Ruby into the iseq assembler. On the
C level, such a function exists and it works, namely, rb_iseq_load, but
it's not exposed on the Ruby level. Other people apparently found this
function useful too, because I found the following snippet online to
dynamically load it:

require "fiddle"
class RubyVM::InstructionSequence
  # Retrieve Ruby Core's C-ext `iseq_load' function address
  # I had to modify this line for my system
  load_fn_addr  =
Fiddle::Handle.new("x64-msvcrt-ruby240.dll")['rb_iseq_load']
  # Retrieve `iseq_load' C function representation
  load_fn       = Fiddle::Function.new(load_fn_addr,
                                       [Fiddle::TYPE_VOIDP] * 3,
                                       Fiddle::TYPE_VOIDP)

  # Make `iseq_load' accessible as `load' class method
  define_singleton_method(:load) do |data, parent = nil, opt = nil|
    load_fn.call(Fiddle.dlwrap(data), parent, opt).to_value
  end
end

The original hack was written for Linux, I think, so I had to manually find
the right DLL for my system and swap it in there. But it works, kinda, in a
hacky way.

Would you ever consider exposing rb_iseq_load as a singleton method of
RubyVM::InstructionSequence? The function already performs quite a few
checks on the validity of the input, and there is already an unsafe way to
load ISeqs via ::from_binary. And that would make it easier to do
interesting things with Ruby codegen.

-- 
- Simen
(supressed text/html)
Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>