Skip to content

Commit

Permalink
don't use RubyVM if it's not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
shugo committed Oct 23, 2012
1 parent b119344 commit 85a9520
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
16 changes: 10 additions & 6 deletions lib/immutable.rb
Expand Up @@ -2,11 +2,13 @@
module Immutable
end

old_compile_option = RubyVM::InstructionSequence.compile_option
RubyVM::InstructionSequence.compile_option = {
:tailcall_optimization => true,
:trace_instruction => false
}
if defined?(RubyVM)
old_compile_option = RubyVM::InstructionSequence.compile_option
RubyVM::InstructionSequence.compile_option = {
:tailcall_optimization => true,
:trace_instruction => false
}
end
begin
require_relative "immutable/list"
require_relative "immutable/map"
Expand All @@ -16,5 +18,7 @@ module Immutable
require_relative "immutable/output_restricted_deque"
require_relative "immutable/deque"
ensure
RubyVM::InstructionSequence.compile_option = old_compile_option
if defined?(RubyVM)
RubyVM::InstructionSequence.compile_option = old_compile_option
end
end
20 changes: 12 additions & 8 deletions test/test_helper.rb
Expand Up @@ -3,14 +3,18 @@
require "test/unit"

def with_tailcall_optimization
old_compile_option = RubyVM::InstructionSequence.compile_option
RubyVM::InstructionSequence.compile_option = {
:tailcall_optimization => true,
:trace_instruction => false
}
begin
if defined?(RubyVM)
old_compile_option = RubyVM::InstructionSequence.compile_option
RubyVM::InstructionSequence.compile_option = {
:tailcall_optimization => true,
:trace_instruction => false
}
begin
yield
ensure
RubyVM::InstructionSequence.compile_option = old_compile_option
end
else
yield
ensure
RubyVM::InstructionSequence.compile_option = old_compile_option
end
end

0 comments on commit 85a9520

Please sign in to comment.