rubymirrors 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -0
- data/README.md +30 -0
- data/Rakefile +13 -0
- data/lib/abstract_reflection.rb +112 -0
- data/lib/abstract_reflection/class_mirror.rb +150 -0
- data/lib/abstract_reflection/compiler_mirror.rb +31 -0
- data/lib/abstract_reflection/field_mirror.rb +35 -0
- data/lib/abstract_reflection/gc_mirror.rb +19 -0
- data/lib/abstract_reflection/method_mirror.rb +253 -0
- data/lib/abstract_reflection/mirror.rb +108 -0
- data/lib/abstract_reflection/object_mirror.rb +48 -0
- data/lib/abstract_reflection/stack_frame_mirror.rb +61 -0
- data/lib/abstract_reflection/thread_mirror.rb +64 -0
- data/lib/maglev/reflection.rb +49 -0
- data/lib/maglev/reflection/class_mirror.rb +157 -0
- data/lib/maglev/reflection/core_ext/class_organizer.rb +20 -0
- data/lib/maglev/reflection/core_ext/maglev.rb +5 -0
- data/lib/maglev/reflection/core_ext/method.rb +154 -0
- data/lib/maglev/reflection/core_ext/module.rb +41 -0
- data/lib/maglev/reflection/core_ext/object.rb +4 -0
- data/lib/maglev/reflection/core_ext/thread.rb +226 -0
- data/lib/maglev/reflection/field_mirror.rb +39 -0
- data/lib/maglev/reflection/field_mirror/fixed_instance_variable_mirror.rb +25 -0
- data/lib/maglev/reflection/method_mirror.rb +149 -0
- data/lib/maglev/reflection/mirror.rb +6 -0
- data/lib/maglev/reflection/object_mirror.rb +18 -0
- data/lib/maglev/reflection/stack_frame_mirror.rb +104 -0
- data/lib/maglev/reflection/thread_mirror.rb +116 -0
- data/lib/rubinius/reflection.rb +6 -0
- data/lib/ruby/reflection.rb +74 -0
- data/lib/ruby/reflection/class_mirror.rb +89 -0
- data/lib/ruby/reflection/field_mirror.rb +32 -0
- data/lib/ruby/reflection/field_mirror/class_variable_mirror.rb +25 -0
- data/lib/ruby/reflection/field_mirror/constant_mirror.rb +36 -0
- data/lib/ruby/reflection/field_mirror/instance_variable_mirror.rb +25 -0
- data/lib/ruby/reflection/method_mirror.rb +122 -0
- data/lib/ruby/reflection/mirror.rb +12 -0
- data/lib/ruby/reflection/object_mirror.rb +25 -0
- data/lib/ruby/reflection/stack_frame_mirror.rb +49 -0
- data/lib/ruby/reflection/support/shift_reset.rb +29 -0
- data/lib/ruby/reflection/thread_mirror.rb +47 -0
- data/rubymirrors.gemspec +12 -0
- data/spec/class_spec.rb +92 -0
- data/spec/field_spec.rb +119 -0
- data/spec/fixtures/class_spec.rb +29 -0
- data/spec/fixtures/field_spec.rb +9 -0
- data/spec/fixtures/method_spec.rb +14 -0
- data/spec/fixtures/object_spec.rb +5 -0
- data/spec/fixtures/reflect_spec.rb +14 -0
- data/spec/fixtures/stack_frame_spec.rb +5 -0
- data/spec/fixtures/thread_spec.rb +5 -0
- data/spec/frame_spec.rb +80 -0
- data/spec/method_spec.rb +166 -0
- data/spec/object_spec.rb +18 -0
- data/spec/reflection_spec.rb +74 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/spec_helper/mspec_patch.rb +29 -0
- data/spec/spec_helper/multiple_reflections.rb +14 -0
- data/spec/thread_spec.rb +142 -0
- metadata +173 -0
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
## A mirror API for Ruby
|
2
|
+
|
3
|
+
In various [research][p1] [projects][p2] the advantages of having a [mirror
|
4
|
+
API][p3] to separate reflection from a language implementation have
|
5
|
+
been discussed, and "industry grade" implementations exist for
|
6
|
+
[Java][p4] and [C#][p5]. This project aims at providing a number of
|
7
|
+
specs and classes that document a mirror API for Ruby. The mirror
|
8
|
+
implementation that is part of this project will use only those
|
9
|
+
language facilities that are available across Ruby implementations.
|
10
|
+
The specs, however, will also test behavior that cannot be provided in
|
11
|
+
such a manner. The idea here is that in time, all implementations
|
12
|
+
provide their own implementation of the mirror API, and all
|
13
|
+
implementations collaborate on this one spec.
|
14
|
+
|
15
|
+
Why do this, you ask? Because Ruby needs tools, and those tools need
|
16
|
+
to be written in Ruby. If they are not, then people will be excluded from
|
17
|
+
tinkering with their tools, thus impeding innovation. You only have to
|
18
|
+
look at Emacs or Smalltalk to see what's possible when programmers can
|
19
|
+
extend their tools, all tools, in a language they feel comfortable
|
20
|
+
in. If we have a standard mirror API, all tools that are written **for**
|
21
|
+
Ruby, **in** Ruby, can be shared across implementations, while at the same time
|
22
|
+
allowing language implementers to use the facilities of their platform
|
23
|
+
to provide optimal reflective capabilities without tying them to
|
24
|
+
internals.
|
25
|
+
|
26
|
+
[p1]: http://www.cs.virginia.edu/~lorenz/papers/icse03/icse2003.pdf "Pluggable Reflection: Decoupling Meta-Interface and Implementation"
|
27
|
+
[p2]: http://bracha.org/newspeak-spec.pdf "Newspeak Programming Language Draft Specification, Version 0.06, pages 40 onward"
|
28
|
+
[p3]: http://www.hpi.uni-potsdam.de/hirschfeld/events/past/media/100105_Bracha_2010_LinguisticReflectionViaMirrors_HPI.mp4 "Linguistic Reflection Via Mirrors"
|
29
|
+
[p4]: http://bracha.org/mirrors.pdf "Mirrors: Design Principles for Meta-level Facilities of Object-Oriented Programming Languages"
|
30
|
+
[p5]: http://oreilly.com/catalog/progcsharp/chapter/ch18.html "See esp. 18-3, highlighting how C# reflection works on assembly rather than VM objects"
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
RUBY_ENGINE = 'ruby' unless defined? RUBY_ENGINE
|
5
|
+
|
6
|
+
desc "Run the specs on the given mirror api. Defaults to 'ruby'"
|
7
|
+
task :spec, :impl do |task, args|
|
8
|
+
args.with_defaults :impl => RUBY_ENGINE
|
9
|
+
sh "mspec -t #{args.impl} spec/*_spec.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
task :test => :spec
|
13
|
+
task :default => :spec
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module AbstractReflection
|
2
|
+
# A marker, raised when trying to run something
|
3
|
+
# that the reflective API doesn't support.
|
4
|
+
class CapabilitiesExceeded < StandardError; end
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
# A mirror has to reflect on something. file mirrors on files or
|
8
|
+
# directories, VM mirrors on the running VM or a remote instance and
|
9
|
+
# so on... This method allows you to query what kind of object you
|
10
|
+
# need to prepare to use it.
|
11
|
+
#
|
12
|
+
# @return [Array<Class>, Class] the class(es) that this reflective api can work on
|
13
|
+
def codebase
|
14
|
+
raise NotImplementedError, "#{self} should have implemented #codebase"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Creates a new instance of a Reflection
|
19
|
+
# @param [Object] the codebase to work on, e.g. a file or a VM
|
20
|
+
# @return [Reflection] a new reflection object
|
21
|
+
def initialize(object)
|
22
|
+
raise NotImplementedError, "#{self} should have implemented #initialize"
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.included(base)
|
26
|
+
base.extend(ClassMethods)
|
27
|
+
end
|
28
|
+
|
29
|
+
# This method can be used to query the system for known modules. It
|
30
|
+
# is not guaranteed that all possible modules are returned.
|
31
|
+
#
|
32
|
+
# @return [Array<ClassMirror>] a list of class mirrors
|
33
|
+
def modules
|
34
|
+
raise CapabilitiesExceeded
|
35
|
+
end
|
36
|
+
|
37
|
+
# This method can be used to query the system for known classes. It
|
38
|
+
# is not guaranteed that all possible classes are returned.
|
39
|
+
#
|
40
|
+
# @return [Array<ClassMirror>] a list of class mirrors
|
41
|
+
def classes
|
42
|
+
raise CapabilitiesExceeded
|
43
|
+
end
|
44
|
+
|
45
|
+
# Query the system for objects that are direct instances of the
|
46
|
+
# given class.
|
47
|
+
# @param [Class]
|
48
|
+
# @return [Array<ObjectMirror>] a list of appropriate mirrors for the requested objects
|
49
|
+
def instances_of(klass)
|
50
|
+
raise CapabilitiesExceeded
|
51
|
+
end
|
52
|
+
|
53
|
+
# Ask the system to find the object with the given object id
|
54
|
+
# @param [Numeric] object id
|
55
|
+
# @return [ObjectMirror, NilClass] the object mirror or nil
|
56
|
+
def object_by_id(id)
|
57
|
+
raise CapabilitiesExceeded
|
58
|
+
end
|
59
|
+
|
60
|
+
# Query the system for implementors of a particular message
|
61
|
+
# @param [String] the message name
|
62
|
+
# @return [Array<MethodMirror>] the implementing methods
|
63
|
+
def implementations_of(message)
|
64
|
+
raise CapabilitiesExceeded
|
65
|
+
end
|
66
|
+
|
67
|
+
# Query the system for senders of a particular message
|
68
|
+
# @param [String] the message name
|
69
|
+
# @return [Array<MethodMirror>] the sending methods
|
70
|
+
def senders_of(message)
|
71
|
+
raise CapabilitiesExceeded
|
72
|
+
end
|
73
|
+
|
74
|
+
# Return the currently active threads in the system
|
75
|
+
# @return [Array<ThreadMirror>] a list of thread mirrors
|
76
|
+
def threads
|
77
|
+
raise CapabilitiesExceeded
|
78
|
+
end
|
79
|
+
|
80
|
+
# @return [String] the platform the system is running on. usually RUBY_PLATFORM
|
81
|
+
def platform
|
82
|
+
raise CapabilitiesExceeded
|
83
|
+
end
|
84
|
+
|
85
|
+
# @return [String] the used implementation of Ruby
|
86
|
+
def engine
|
87
|
+
raise CapabilitiesExceeded
|
88
|
+
end
|
89
|
+
|
90
|
+
# @return [String] the version string describing the system
|
91
|
+
def version
|
92
|
+
raise CapabilitiesExceeded
|
93
|
+
end
|
94
|
+
|
95
|
+
# Create a mirror for a given object in the system under
|
96
|
+
# observation.
|
97
|
+
# @param [Object]
|
98
|
+
# @return [Mirror]
|
99
|
+
def reflect(o)
|
100
|
+
Mirror.reflect o, self
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
require 'abstract_reflection/mirror'
|
105
|
+
require 'abstract_reflection/object_mirror'
|
106
|
+
require 'abstract_reflection/field_mirror'
|
107
|
+
require 'abstract_reflection/class_mirror'
|
108
|
+
require 'abstract_reflection/method_mirror'
|
109
|
+
require 'abstract_reflection/thread_mirror'
|
110
|
+
require 'abstract_reflection/stack_frame_mirror'
|
111
|
+
require 'abstract_reflection/gc_mirror'
|
112
|
+
require 'abstract_reflection/compiler_mirror'
|
@@ -0,0 +1,150 @@
|
|
1
|
+
module AbstractReflection
|
2
|
+
# A specific mirror for a class, that includes all the capabilites
|
3
|
+
# and information we can gather about classes.
|
4
|
+
module ClassMirror
|
5
|
+
include ObjectMirror
|
6
|
+
|
7
|
+
# The known instance variables of this class. Ruby doesn't have a
|
8
|
+
# fixed number of instance variables, but static or runtime
|
9
|
+
# anlysis can give us a good idea what kind of variables we can
|
10
|
+
# expect.
|
11
|
+
#
|
12
|
+
# @return [FieldMirror]
|
13
|
+
def instance_variables
|
14
|
+
raise CapabilitiesExceeded
|
15
|
+
end
|
16
|
+
|
17
|
+
# The known class variables.
|
18
|
+
# @see #instance_variables
|
19
|
+
# @return [FieldMirror]
|
20
|
+
def class_variables
|
21
|
+
raise CapabilitiesExceeded
|
22
|
+
end
|
23
|
+
|
24
|
+
# The known class variables.
|
25
|
+
# @see #instance_variables
|
26
|
+
# @return [FieldMirror]
|
27
|
+
def class_instance_variables
|
28
|
+
raise CapabilitiesExceeded
|
29
|
+
end
|
30
|
+
|
31
|
+
# The source files this class is defined and/or extended in.
|
32
|
+
#
|
33
|
+
# @return [Array<String,File>]
|
34
|
+
def source_files
|
35
|
+
raise CapabilitiesExceeded
|
36
|
+
end
|
37
|
+
|
38
|
+
# The singleton class of this class
|
39
|
+
#
|
40
|
+
# @return [ClassMirror]
|
41
|
+
def singleton_class
|
42
|
+
raise CapabilitiesExceeded
|
43
|
+
end
|
44
|
+
|
45
|
+
# Predicate to determine whether the subject is a singleton class
|
46
|
+
#
|
47
|
+
# @return [true,false]
|
48
|
+
def singleton_class?
|
49
|
+
raise CapabilitiesExceeded
|
50
|
+
end
|
51
|
+
|
52
|
+
# The inverse of #singleton_class.
|
53
|
+
#
|
54
|
+
# @return [ClassMirror]
|
55
|
+
def singleton_instance
|
56
|
+
raise CapabilitiesExceeded
|
57
|
+
end
|
58
|
+
|
59
|
+
# The namespace of this class. Provides direct access to the
|
60
|
+
# enclosing namespace.
|
61
|
+
#
|
62
|
+
# @return [ClassMirror]
|
63
|
+
def namespace
|
64
|
+
raise CapabilitiesExceeded
|
65
|
+
end
|
66
|
+
|
67
|
+
# The full nesting.
|
68
|
+
#
|
69
|
+
# @return [Array<ClassMirror>]
|
70
|
+
def nesting
|
71
|
+
raise CapabilitiesExceeded
|
72
|
+
end
|
73
|
+
|
74
|
+
# The classes nested within the subject. Should _not_ trigger
|
75
|
+
# autloads!
|
76
|
+
#
|
77
|
+
# @return [Array<ClassMirror>]
|
78
|
+
def nested_classes
|
79
|
+
raise CapabilitiesExceeded
|
80
|
+
end
|
81
|
+
|
82
|
+
# The mixins included in the ancestors of this class.
|
83
|
+
#
|
84
|
+
# @return [Array<ClassMirror>]
|
85
|
+
def mixins
|
86
|
+
raise CapabilitiesExceeded
|
87
|
+
end
|
88
|
+
|
89
|
+
# The direct superclass
|
90
|
+
#
|
91
|
+
# @return [ClassMirror]
|
92
|
+
def superclass
|
93
|
+
raise CapabilitiesExceeded
|
94
|
+
end
|
95
|
+
|
96
|
+
# The known subclasses
|
97
|
+
#
|
98
|
+
# @return [Array<ClassMirror>]
|
99
|
+
def subclasses
|
100
|
+
raise CapabilitiesExceeded
|
101
|
+
end
|
102
|
+
|
103
|
+
# The list of ancestors
|
104
|
+
#
|
105
|
+
# @return [Array<ClassMirror>]
|
106
|
+
def ancestors
|
107
|
+
raise CapabilitiesExceeded
|
108
|
+
end
|
109
|
+
|
110
|
+
# The constants defined within this class. This includes nested
|
111
|
+
# classes and modules, but also all other kinds of constants.
|
112
|
+
# This should _not_ trigger autoloads!
|
113
|
+
#
|
114
|
+
# @return [Array<FieldMirror>]
|
115
|
+
def constants
|
116
|
+
raise CapabilitiesExceeded
|
117
|
+
end
|
118
|
+
|
119
|
+
# Searches for the named constant in the mirrored namespace. May
|
120
|
+
# include a colon (::) separated constant path. This _may_ trigger
|
121
|
+
# an autoload!
|
122
|
+
#
|
123
|
+
# @return [ClassMirror, nil] the requested constant, or nil
|
124
|
+
def constant(name)
|
125
|
+
raise CapabilitiesExceeded
|
126
|
+
end
|
127
|
+
|
128
|
+
# The instance methods of this class. To get to the class methods,
|
129
|
+
# ask the #singleton_class for its methods.
|
130
|
+
#
|
131
|
+
# @return [Array<MethodMirror>]
|
132
|
+
def methods
|
133
|
+
raise CapabilitiesExceeded
|
134
|
+
end
|
135
|
+
|
136
|
+
# The instance method of this class or any of its superclasses
|
137
|
+
# that has the specified selector
|
138
|
+
#
|
139
|
+
# @return [MethodMirror, nil] the method or nil, if none was found
|
140
|
+
def method(name)
|
141
|
+
raise CapabilitiesExceeded
|
142
|
+
end
|
143
|
+
|
144
|
+
# The method dictionary. Maps names to methods. Should ideally be
|
145
|
+
# writable.
|
146
|
+
def method_dictionary
|
147
|
+
raise CapabilitiesExceeded
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module AbstractReflection
|
2
|
+
# Reflecting on the compiler, both in a general sense (to just
|
3
|
+
# compile things) and in specific states. It should be possible to
|
4
|
+
# get a compiler instance and associated state from e.g. the
|
5
|
+
# execution of a thread.
|
6
|
+
#
|
7
|
+
# This class should also allow access to information about JIT,
|
8
|
+
# caches etc
|
9
|
+
module CompilerMirror
|
10
|
+
include Mirror
|
11
|
+
|
12
|
+
# Your Kernel#eval, but only compiles and returns
|
13
|
+
# the compiled method object.
|
14
|
+
#
|
15
|
+
# return [MethodMirror]
|
16
|
+
def compile(source)
|
17
|
+
raise CapabilitiesExceeded
|
18
|
+
end
|
19
|
+
|
20
|
+
# For a specific compiler state, this holds the current module
|
21
|
+
# definition stack. This should be a list of modules in which the
|
22
|
+
# Thread, that belongs to this compiler state, is currently
|
23
|
+
# nested. The first element is the module that would be target for
|
24
|
+
# the next method definition.
|
25
|
+
#
|
26
|
+
# return [Array<ClassMirror>]
|
27
|
+
def module_scope
|
28
|
+
raise CapabilitiesExceeded
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module AbstractReflection
|
2
|
+
# A class to reflect on instance, class, and class instance variables,
|
3
|
+
# as well as constants.
|
4
|
+
module FieldMirror
|
5
|
+
include Mirror
|
6
|
+
|
7
|
+
def value
|
8
|
+
raise CapabilitiesExceeded
|
9
|
+
end
|
10
|
+
|
11
|
+
def value= obj
|
12
|
+
raise CapabilitiesExceeded
|
13
|
+
end
|
14
|
+
|
15
|
+
def public?
|
16
|
+
raise CapabilitiesExceeded
|
17
|
+
end
|
18
|
+
|
19
|
+
def private?
|
20
|
+
raise CapabilitiesExceeded
|
21
|
+
end
|
22
|
+
|
23
|
+
def protected?
|
24
|
+
raise CapabilitiesExceeded
|
25
|
+
end
|
26
|
+
|
27
|
+
def writable?
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete
|
32
|
+
raise CapabilitiesExceeded
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module AbstractReflection
|
2
|
+
# Reflective access to the GC. This includes statistics, runtime
|
3
|
+
# behavior observation and triggering specific GC functionality.
|
4
|
+
module GCMirror
|
5
|
+
include Mirror
|
6
|
+
|
7
|
+
# Trigger a GC run
|
8
|
+
# @return stats about cleaned objects, freed memory, etc
|
9
|
+
def collect_garbage
|
10
|
+
raise CapabilitiesExceeded
|
11
|
+
end
|
12
|
+
|
13
|
+
# Run memory compaction
|
14
|
+
# @return info about freed memory, moved pages, etc
|
15
|
+
def compact_memory
|
16
|
+
raise CapabilitiesExceeded
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,253 @@
|
|
1
|
+
module AbstractReflection
|
2
|
+
# A MethodMirror should reflect on methods, but in a more general
|
3
|
+
# sense than the Method and UnboundMethod classes in Ruby are able
|
4
|
+
# to offer.
|
5
|
+
#
|
6
|
+
# In actual execution, a method is pretty much every chunk of code,
|
7
|
+
# even loading a file triggers a process not unlike compiling a
|
8
|
+
# method (if only for the side-effects). Method mirrors should allow
|
9
|
+
# access to the runtime objects, but also to their static
|
10
|
+
# representations (bytecode, source, ...), their debugging
|
11
|
+
# information and statistical information
|
12
|
+
module MethodMirror
|
13
|
+
include Mirror
|
14
|
+
|
15
|
+
# @return [ClassMirror] The class this method was originally defined in
|
16
|
+
def defining_class
|
17
|
+
raise CapabilitiesExceeded
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [String] The source code of this method
|
21
|
+
def source
|
22
|
+
raise CapabilitiesExceeded
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [Fixnum] The source line
|
26
|
+
def line
|
27
|
+
raise CapabilitiesExceeded
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String] The method name
|
31
|
+
def selector
|
32
|
+
raise CapabilitiesExceeded
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [String] The filename
|
36
|
+
def file
|
37
|
+
raise CapabilitiesExceeded
|
38
|
+
end
|
39
|
+
|
40
|
+
# Queries the method for it's arguments and returns a list of
|
41
|
+
# mirrors that hold name and value information.
|
42
|
+
#
|
43
|
+
# @return [Array<FieldMirror>]
|
44
|
+
def arguments
|
45
|
+
raise CapabilitiesExceeded
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns a field mirror with name and possibly value of the splat
|
49
|
+
# argument, or nil, if there is none to this method.
|
50
|
+
#
|
51
|
+
# @return [FieldMirror, nil]
|
52
|
+
def splat_argument
|
53
|
+
raise CapabilitiesExceeded
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns names and values of the optional arguments.
|
57
|
+
#
|
58
|
+
# @return [Array<FieldMirror>, nil]
|
59
|
+
def optional_arguments
|
60
|
+
raise CapabilitiesExceeded
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns the name and possibly values of the required arguments
|
64
|
+
# @return [Array<FieldMirror>, nil]
|
65
|
+
def required_arguments
|
66
|
+
raise CapabilitiesExceeded
|
67
|
+
end
|
68
|
+
|
69
|
+
# Return the value the block argument, or nil
|
70
|
+
#
|
71
|
+
# @return [FieldMirror, nil]
|
72
|
+
def block_argument
|
73
|
+
raise CapabilitiesExceeded
|
74
|
+
end
|
75
|
+
|
76
|
+
# Replace the sourcecode. This should be an in-place operation and
|
77
|
+
# immediately visible to the system.
|
78
|
+
def source= string
|
79
|
+
raise CapabilitiesExceeded
|
80
|
+
end
|
81
|
+
|
82
|
+
# Change the information about which file this method is stored
|
83
|
+
# in. Possibly moves the method into the new file.
|
84
|
+
def file= string
|
85
|
+
raise CapabilitiesExceeded
|
86
|
+
end
|
87
|
+
|
88
|
+
# Change the information about the line this method starts
|
89
|
+
# at. Possibly moves the method.
|
90
|
+
def line= string
|
91
|
+
raise CapabilitiesExceeded
|
92
|
+
end
|
93
|
+
|
94
|
+
# The offsets into the source code for method sends.
|
95
|
+
#
|
96
|
+
# @return [Hash<String, Fixnum>] a hash of selector-offset pairs
|
97
|
+
def send_offsets
|
98
|
+
raise CapabilitiesExceeded
|
99
|
+
end
|
100
|
+
|
101
|
+
# The offsets into the source code for stepping in a debugger
|
102
|
+
def step_offsets
|
103
|
+
raise CapabilitiesExceeded
|
104
|
+
end
|
105
|
+
|
106
|
+
# Allows setting a breakpoint in the method, optionally at an
|
107
|
+
# offset.
|
108
|
+
def break(step_offset = 1)
|
109
|
+
raise CapabilitiesExceeded
|
110
|
+
end
|
111
|
+
|
112
|
+
# Query the method for active breakpoints.
|
113
|
+
def breakpoints
|
114
|
+
raise CapabilitiesExceeded
|
115
|
+
end
|
116
|
+
|
117
|
+
# Predicate to determine whether this method was compiled for closure
|
118
|
+
#
|
119
|
+
# @return [true, false]
|
120
|
+
def is_closure?
|
121
|
+
raise CapabilitiesExceeded
|
122
|
+
end
|
123
|
+
|
124
|
+
# The binding of the method. May be nil.
|
125
|
+
#
|
126
|
+
# @return [Binding, NilClass]
|
127
|
+
def binding
|
128
|
+
raise CapabilitiesExceeded
|
129
|
+
end
|
130
|
+
|
131
|
+
# Predicate to determine whether this method is an alias.
|
132
|
+
#
|
133
|
+
# @return [true, false]
|
134
|
+
def is_alias?
|
135
|
+
raise CapabilitiesExceeded
|
136
|
+
end
|
137
|
+
|
138
|
+
# Returns the original method to an alias, a proc, or an unbound
|
139
|
+
# method object, or the method itself, if the previous options are
|
140
|
+
# not applicable.
|
141
|
+
#
|
142
|
+
# @return [MethodMirror]
|
143
|
+
def original_method
|
144
|
+
raise CapabilitiesExceeded
|
145
|
+
end
|
146
|
+
|
147
|
+
# Predicate to determine whether a given message is send within
|
148
|
+
# this method. This should at least report all direct sends, but
|
149
|
+
# might also report sends within #evals or through #send
|
150
|
+
#
|
151
|
+
# @return [true, false]
|
152
|
+
def sends_message?(string)
|
153
|
+
raise CapabilitiesExceeded
|
154
|
+
end
|
155
|
+
|
156
|
+
# Determine whether this method references the passed name. This
|
157
|
+
# should be in a state useable enough to allow e.g. dead local
|
158
|
+
# detection.
|
159
|
+
#
|
160
|
+
# @return [true, false]
|
161
|
+
def references_name?(string)
|
162
|
+
raise CapabilitiesExceeded
|
163
|
+
end
|
164
|
+
|
165
|
+
# Each method contributes a certain percentage to the runtime of
|
166
|
+
# the system. This method can be used to query the system for the
|
167
|
+
# percentage of the mirrored method (in the range 0 < p < 1). If
|
168
|
+
# the number is closer to one, that means that the system spends a
|
169
|
+
# considerable amount of time executing this method. This method
|
170
|
+
# does not consider how often a method is called, i.e. a high
|
171
|
+
# share doesn't tell you whether the method is slow or if it is
|
172
|
+
# just called very often.
|
173
|
+
#
|
174
|
+
# @return [Time]
|
175
|
+
def execution_time_share
|
176
|
+
raise CapabilitiesExceeded
|
177
|
+
end
|
178
|
+
|
179
|
+
# The absolute, total time this method was executed (on top of the
|
180
|
+
# stack)
|
181
|
+
#
|
182
|
+
# @return [Time]
|
183
|
+
def execution_time
|
184
|
+
raise CapabilitiesExceeded
|
185
|
+
end
|
186
|
+
|
187
|
+
# The average time each method invocation executes the method,
|
188
|
+
# before returning.
|
189
|
+
#
|
190
|
+
# @return [Time]
|
191
|
+
def execution_time_average
|
192
|
+
raise CapabilitiesExceeded
|
193
|
+
end
|
194
|
+
|
195
|
+
# The number of times this method has been called. Not
|
196
|
+
# neccessarily an exact number (to allow for optimizations), but
|
197
|
+
# should at least give an indication.
|
198
|
+
#
|
199
|
+
# @return [Fixnum]
|
200
|
+
def invocation_count
|
201
|
+
raise CapabilitiesExceeded
|
202
|
+
end
|
203
|
+
|
204
|
+
# If this method was JITed, this should return the native code
|
205
|
+
# location. nil, if this method was not jitted,
|
206
|
+
# CapabilitiesExceeded should be thrown for implementations that
|
207
|
+
# do not have a JIT.
|
208
|
+
def native_code
|
209
|
+
raise CapabilitiesExceeded
|
210
|
+
end
|
211
|
+
|
212
|
+
# If this method was compiled into a VM bytecode representation,
|
213
|
+
# return an object describing the bytecode. Like #native_code,
|
214
|
+
# this should raise a CapabilitiesExceeded only for implementations
|
215
|
+
# that do not have a bytecode representation.
|
216
|
+
def bytecode
|
217
|
+
raise CapabilitiesExceeded
|
218
|
+
end
|
219
|
+
|
220
|
+
# The AST representation of this method.
|
221
|
+
def ast
|
222
|
+
raise CapabilitiesExceeded
|
223
|
+
end
|
224
|
+
|
225
|
+
def public?
|
226
|
+
raise CapabilitiesExceeded
|
227
|
+
end
|
228
|
+
|
229
|
+
def public!
|
230
|
+
raise CapabilitiesExceeded
|
231
|
+
end
|
232
|
+
|
233
|
+
def private?
|
234
|
+
raise CapabilitiesExceeded
|
235
|
+
end
|
236
|
+
|
237
|
+
def private!
|
238
|
+
raise CapabilitiesExceeded
|
239
|
+
end
|
240
|
+
|
241
|
+
def protected?
|
242
|
+
raise CapabilitiesExceeded
|
243
|
+
end
|
244
|
+
|
245
|
+
def protected!
|
246
|
+
raise CapabilitiesExceeded
|
247
|
+
end
|
248
|
+
|
249
|
+
def delete
|
250
|
+
raise CapabilitiesExceeded
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|