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-15 22:10:54 -04:00
|
|
|
@root = Mutant.deep_clone(root)
|
2012-07-27 07:32:57 -04:00
|
|
|
Rubinius.run_script(compiled_code)
|
2012-07-26 13:25:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Return compiled code for node
|
|
|
|
#
|
2012-07-30 22:10:37 -04:00
|
|
|
# This method actually returns a Rubnius::CompiledMethod
|
|
|
|
# instance. But it is named on the future name of CompiledMethod
|
2012-07-26 13:25:23 -04:00
|
|
|
# that will be renamed to Rubinius::CompiledCode.
|
|
|
|
#
|
|
|
|
# @return [Rubinius::CompiledMethod]
|
|
|
|
#
|
|
|
|
# @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
|