2012-07-26 19:25:23 +02:00
|
|
|
module Mutant
|
2012-11-21 20:31:01 +01:00
|
|
|
# Base class for code loaders
|
2012-07-26 19:25:23 +02:00
|
|
|
class Loader
|
2012-11-26 11:30:00 +01:00
|
|
|
include AbstractType
|
2012-08-16 04:10:54 +02:00
|
|
|
extend MethodObject
|
2012-07-26 19:25:23 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2012-11-21 20:31:01 +01:00
|
|
|
# Run the loader
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
abstract_method :run
|
|
|
|
|
2012-07-26 19:25:23 +02:00
|
|
|
# Initialize and insert mutation into vm
|
|
|
|
#
|
|
|
|
# @param [Rubinius::AST::Script] root
|
2013-01-04 22:16:03 +01:00
|
|
|
# @param [Subject] subject
|
2012-07-26 19:25:23 +02:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-01-04 22:16:03 +01:00
|
|
|
def initialize(root, subject)
|
|
|
|
@root, @subject = root, subject
|
2012-11-21 20:31:01 +01:00
|
|
|
run
|
2012-08-20 05:01:26 +02:00
|
|
|
end
|
|
|
|
|
2012-11-21 20:31:01 +01:00
|
|
|
# Eval based loader
|
|
|
|
class Eval < self
|
2013-01-04 20:07:41 +01:00
|
|
|
|
|
|
|
private
|
2012-07-26 19:25:23 +02:00
|
|
|
|
2012-11-21 20:31:01 +01:00
|
|
|
# Run loader
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def run
|
2013-01-04 22:16:03 +01:00
|
|
|
Kernel.eval(source, TOPLEVEL_BINDING, @subject.source_path, @subject.source_line)
|
2012-11-21 20:31:01 +01:00
|
|
|
end
|
2012-08-19 21:25:11 +02:00
|
|
|
|
2012-11-21 20:31:01 +01:00
|
|
|
# Return source
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def source
|
|
|
|
ToSource.to_source(@root)
|
|
|
|
end
|
2012-07-26 19:25:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|