Created
April 2, 2012 12:11
-
-
Save betawaffle/2283066 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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