Class: Maglev::Reflection::MethodMirror

Inherits:
Mirror show all
Includes:
AbstractReflection::MethodMirror
Defined in:
lib/maglev/reflection/method_mirror.rb

Instance Attribute Summary

Attributes included from AbstractReflection::Mirror

#reflection

Instance Method Summary collapse

Methods included from AbstractReflection::MethodMirror

#ast, #binding, #bytecode, #execution_time, #execution_time_average, #execution_time_share, #invocation_count, #is_alias?, #is_closure?, #native_code, #original_method, #private!, #private?, #protected!, #protected?, #public!, #public?, #references_name?, #sends_message?

Methods included from AbstractReflection::Mirror

#mirrors?, #name, #reflectee

Methods included from AbstractReflection::Mirror::ClassMethods

#included, #mirror_class, #new, #reflect, #reflect!, #reflects?, #register_mirror

Constructor Details

#initialize(obj) ⇒ MethodMirror

Adding support for on-demand wrapping of GsNMethods



10
11
12
13
14
15
# File 'lib/maglev/reflection/method_mirror.rb', line 10

def initialize(obj)
  super
  if @subject.kind_of? GsNMethod
    @subject = wrap_gsmeth(@subject)
  end
end

Instance Method Details

#argumentsObject



62
63
64
# File 'lib/maglev/reflection/method_mirror.rb', line 62

def arguments
  gsmeth.__args_and_temps.to_a[0...gsmeth.__num_args].collect(&:to_s)
end

#block_argumentObject



66
67
68
69
# File 'lib/maglev/reflection/method_mirror.rb', line 66

def block_argument
  return nil unless gsmeth.__selector.to_s[-1] == ?&
  arguments.last
end

#break(source_offset = 1) ⇒ Object



120
121
122
123
124
125
126
127
# File 'lib/maglev/reflection/method_mirror.rb', line 120

def break(source_offset = 1)
  step_point = find_step_point_just_before(source_offset)
  if gsmeth.__is_method_for_block
    gsmeth.__set_break_at_step_point(step_point)
  else
    @subject.__nonbridge_meth.__set_break_at_step_point(step_point)
  end
end

#breakpointsObject



116
117
118
# File 'lib/maglev/reflection/method_mirror.rb', line 116

def breakpoints
  gsmeth.__all_breakpoints_source_offsets
end

#bytecodesObject



107
108
109
# File 'lib/maglev/reflection/method_mirror.rb', line 107

def bytecodes
  gsmeth.__ip_steps.to_a.collect {|ip| gsmeth.__opcode_info_at(ip) }
end

#clear_break(source_offset) ⇒ Object



129
130
131
# File 'lib/maglev/reflection/method_mirror.rb', line 129

def clear_break(source_offset)
  gsmeth.__clear_break_at(find_step_point_just_before(source_offset))
end

#defining_classObject



58
59
60
# File 'lib/maglev/reflection/method_mirror.rb', line 58

def defining_class
  reflection.reflect gsmeth.__in_class
end

#deleteObject



111
112
113
114
# File 'lib/maglev/reflection/method_mirror.rb', line 111

def delete
  raise CapabilitiesExceeded unless regular_method?
  gsmeth.__in_class.remove_method(selector)
end

#fileObject



17
18
19
# File 'lib/maglev/reflection/method_mirror.rb', line 17

def file
  (@subject.source_location || [])[0]
end

#file=(string) ⇒ Object



21
22
23
24
25
26
# File 'lib/maglev/reflection/method_mirror.rb', line 21

def file=(string)
  raise CapabilitiesExceeded unless regular_method?
  reload_after do
    defining_class.reflectee.class_eval(source, string, line)
  end
end

#lineObject



28
29
30
# File 'lib/maglev/reflection/method_mirror.rb', line 28

def line
  (@subject.source_location || [])[1]
end

#line=(num) ⇒ Object



32
33
34
35
36
37
# File 'lib/maglev/reflection/method_mirror.rb', line 32

def line=(num)
  raise CapabilitiesExceeded unless regular_method?
  reload_after do
    defining_class.reflectee.class_eval(source, file, num)
  end
end

#optional_argumentsObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/maglev/reflection/method_mirror.rb', line 71

def optional_arguments
  opt_arg_offset = gsmeth.__ruby_opt_args_bits.to_s(2).reverse.index(?1)
  argsize = gsmeth.__num_args
  unless opt_arg_offset
    if block_argument && splat_argument
      opt_arg_offset = argsize - 2
    elsif block_argument || splat_argument
      opt_arg_offset = argsize - 1
    else
      opt_arg_offset = -2
    end
  end
  arguments[opt_arg_offset..-1]
end

#required_argumentsObject



86
87
88
# File 'lib/maglev/reflection/method_mirror.rb', line 86

def required_arguments
  arguments - optional_arguments
end

#selectorObject



54
55
56
# File 'lib/maglev/reflection/method_mirror.rb', line 54

def selector
  @subject.name.to_s
end

#send_offsetsObject



99
100
101
102
103
104
105
# File 'lib/maglev/reflection/method_mirror.rb', line 99

def send_offsets
  offs = gsmeth.__source_offsets_of_sends.to_a
  offs = offs.each_slice(2).collect do |offset, selector|
    [prefix_if_ruby_selector(selector), offset]
  end
  Hash[*offs.flatten]
end

#sourceObject



39
40
41
# File 'lib/maglev/reflection/method_mirror.rb', line 39

def source
  gsmeth.__source_string
end

#source=(str) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/maglev/reflection/method_mirror.rb', line 43

def source=(str)
  raise CapabilitiesExceeded unless regular_method?
  reload_after do
    if file.nil? && line.nil? # Smalltalk method
      defining_class.reflectee.__compile_method_category_environment_id(str, '*maglev-dynamic-compile-unclassified', 1)
    else # Ruby method
      defining_class.reflectee.class_eval(str, file, line)
    end
  end
end

#splat_argumentObject



90
91
92
93
# File 'lib/maglev/reflection/method_mirror.rb', line 90

def splat_argument
  return nil unless gsmeth.__selector.to_s[-2] == ?*
  block_argument ? arguments[-2] : arguments[-1]
end

#step_offsetsObject



95
96
97
# File 'lib/maglev/reflection/method_mirror.rb', line 95

def step_offsets
  gsmeth.__source_offsets
end