Module: MimiCheck::TailCallOptimization

Included in:
Checker, Generator::SuchThat
Defined in:
lib/mimicheck/tail_call_optimization.rb

Instance Method Summary collapse

Instance Method Details

#tail_recursive(name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mimicheck/tail_call_optimization.rb', line 5

def tail_recursive(name)
  fn = instance_method(name)

  RubyVM::InstructionSequence.compile_option = {
    tailcall_optimization: true,
    trace_instruction: false
  }

  iseq = RubyVM::InstructionSequence.new(<<-EOS)
  class #{self}
    #{fn.source}
  end
  EOS

  iseq.eval
  iseq.disasm
end