RubyVM::InstructionSequence.compile_option must be set before
compilation of the target program, so you need eval, load, etc.
RubyVM::InstructionSequence.compile_option={:tailcall_optimization=>true,:trace_instruction=>false}eval(<<EOF)
def run_forever(current, final)
if current < final
run_forever(current+1, final)
else
nil
end
end
run_forever(1, Float::INFINITY)
EOF
RubyVM::InstructionSequence.compile_option must be set before
compilation of the target program, so you need eval, load, etc.
RubyVM::InstructionSequence.compile_option={:tailcall_optimization=>true,:trace_instruction=>false}eval(<<EOF)
def run_forever(current, final)
if current < final
run_forever(current+1, final)
else
nil
end
end
run_forever(1, Float::INFINITY)
EOF
I have tried with eval but seems still getting stack level too deep error.
I have also tried below and still get SystemStackError:
RubyVM::InstructionSequence.compile_option={:tailcall_optimization=>true,:trace_instruction=>false}RubyVM::InstructionSequence.new(<<-EOF).eval
def run_forever(current, final)
if current < final
run_forever(current+1, final)
else
nil
end
end
EOFrun_forever(1,Float::INFINITY)
However, if we alter the conditional order, it will work as expected:
RubyVM::InstructionSequence.compile_option={:tailcall_optimization=>true,:trace_instruction=>false}RubyVM::InstructionSequence.new(<<-EOF).eval
def run_forever(current, final)
if current >= final
nil
else
run_forever(current+1, final)
end
end
EOFrun_forever(1,Float::INFINITY)