2012-07-26 13:25:23 -04:00
|
|
|
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
|
2012-07-30 22:10:37 -04:00
|
|
|
# methods. Also subclasses can override the steps. Also passing
|
2012-07-26 13:25:23 -04:00
|
|
|
# around the root node is not needed with a method object.
|
|
|
|
#
|
2012-07-30 22:10:37 -04:00
|
|
|
# As the initializer does the work there is no need for the
|
2012-07-26 13:25:23 -04:00
|
|
|
# instances of this class to be used outside of this class, hence
|
2012-07-30 22:10:37 -04:00
|
|
|
# the Loader.new method is private and the Loader.run method
|
2012-07-26 13:25:23 -04:00
|
|
|
# returns self.
|
|
|
|
#
|
|
|
|
class Loader
|
2012-08-15 22:10:54 -04:00
|
|
|
extend MethodObject
|
2012-07-26 13:25:23 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Initialize and insert mutation into vm
|
|
|
|
#
|
|
|
|
# @param [Rubinius::AST::Script] root
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def initialize(root)
|
2012-08-16 16:59:25 -04:00
|
|
|
@root = Helper.deep_clone(root)
|
2012-08-19 15:25:11 -04:00
|
|
|
Rubinius.run_script(script.compiled_code)
|
2012-07-26 13:25:23 -04:00
|
|
|
end
|
|
|
|
|
2012-08-19 15:25:11 -04:00
|
|
|
# Return code script
|
|
|
|
#
|
|
|
|
# @return [Rubinisu::CompiledCode::Script]
|
|
|
|
#
|
|
|
|
# @api private
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
2012-08-19 15:25:11 -04:00
|
|
|
def script
|
|
|
|
compiled_code.create_script
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return compiled code for node
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
2012-08-19 15:25:11 -04:00
|
|
|
# @return [Rubinius::CompiledCode]
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
|
|
|
# @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
|