free_mutant/lib/mutant/loader.rb
Markus Schirp e7ea0bbde7 Fix Mutant::Loader to use correct constant scope
* Do not load the compiled code before CompiledCode#create_script
  was called.
* Add a test case that illustrates the issue.
2012-08-19 21:27:25 +02:00

63 lines
1.4 KiB
Ruby

module Mutant
# A method object for inserting an AST into the Rubinius VM
#
# The idea is to split the steps for a mutation into documented
# methods. Also subclasses can override the steps. Also passing
# around the root node is not needed with a method object.
#
# As the initializer does the work there is no need for the
# instances of this class to be used outside of this class, hence
# the Loader.new method is private and the Loader.run method
# returns self.
#
class Loader
extend MethodObject
private
# Initialize and insert mutation into vm
#
# @param [Rubinius::AST::Script] root
#
# @return [undefined]
#
# @api private
#
def initialize(root)
@root = Helper.deep_clone(root)
Rubinius.run_script(script.compiled_code)
end
# Return code script
#
# @return [Rubinisu::CompiledCode::Script]
#
# @api private
#
def script
compiled_code.create_script
end
# Return compiled code for node
#
# @return [Rubinius::CompiledCode]
#
# @api private
#
def compiled_code
compiler.run
end
# Return compiler loaded with mutated ast
#
# @return [Rubinius::Compiler]
#
# @api private
#
def compiler
Rubinius::Compiler.new(:bytecode, :compiled_method).tap do |compiler|
compiler.generator.input(@root)
end
end
end
end