Skip to content

Instantly share code, notes, and snippets.

@betawaffle
Created April 2, 2012 12:11
Show Gist options
  • Save betawaffle/2283066 to your computer and use it in GitHub Desktop.
Save betawaffle/2283066 to your computer and use it in GitHub Desktop.
module ::RubyVM::Helpers
class << self
def compile_option name
line = __LINE__ + 2
code = <<-RUBY
def #{name}
::RubyVM::InstructionSequence.compile_option[:#{name}]
end
def #{name}= bool
::RubyVM::InstructionSequence.compile_option[:#{name}] = bool
end
def #{name}?
::RubyVM::InstructionSequence.compile_option[:#{name}]
end
def disable_#{name}
::RubyVM::InstructionSequence.compile_option[:#{name}] = false
end
def enable_#{name}
::RubyVM::InstructionSequence.compile_option[:#{name}] = true
end
def with_#{name}
orig = ::RubyVM::InstructionSequence.compile_option[:#{name}]
::RubyVM::InstructionSequence.compile_option[:#{name}] = true
begin
yield
ensure
::RubyVM::InstructionSequence.compile_option[:#{name}] = orig
end
end
def without_#{name} &block
orig = ::RubyVM::InstructionSequence.compile_option[:#{name}]
::RubyVM::InstructionSequence.compile_option[:#{name}] = false
begin
yield
ensure
::RubyVM::InstructionSequence.compile_option[:#{name}] = orig
end
end
RUBY
module_eval code, __FILE__, line
end
end
def with_compile_options options
original = ::RubyVM::InstructionSequence.compile_option
::RubyVM::InstructionSequence.compile_option = original.merge(options)
begin
yield
ensure
::RubyVM::InstructionSequence.compile_option = original
end
end
compile_option :inline_const_cache
compile_option :peephole_optimization
compile_option :tailcall_optimization
compile_option :specialized_instruction
compile_option :operands_unification
compile_option :instructions_unification
compile_option :stack_caching
compile_option :trace_instruction
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment