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 23:01:26 -04:00
|
|
|
Rubinius.run_script(compiled_code)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return compiled code
|
|
|
|
#
|
|
|
|
# @return [Rubinius::CompiledCode]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
# FIXME: rbx on travis is older than on my devbox.
|
|
|
|
#
|
|
|
|
def compiled_code
|
|
|
|
_script = script
|
|
|
|
_script.respond_to?(:compiled_code) ? _script.compiled_code : _script.compiled_method
|
2012-07-26 13:25:23 -04:00
|
|
|
end
|
|
|
|
|
2012-08-19 15:25:11 -04:00
|
|
|
# Return code script
|
|
|
|
#
|
2012-08-19 23:01:26 -04:00
|
|
|
# @return [Rubinius::CompiledCode::Script]
|
2012-08-19 15:25:11 -04:00
|
|
|
#
|
|
|
|
# @api private
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
2012-08-19 15:25:11 -04:00
|
|
|
def script
|
2012-08-19 23:01:26 -04:00
|
|
|
compiled_code_raw.create_script
|
2012-08-19 15:25:11 -04:00
|
|
|
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
|
|
|
|
#
|
2012-08-19 23:01:26 -04:00
|
|
|
def compiled_code_raw
|
2012-07-26 13:25:23 -04:00
|
|
|
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
|