public
Description: Rubinius, the Ruby VM
Homepage: http://rubini.us
Clone URL: git://github.com/evanphx/rubinius.git
Search Repo:
rubinius / kernel / core / block_environment.rb
100644 125 lines (99 sloc) 2.427 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
##
# Describes the environment a block was created in. BlockEnvironment is used
# to create a BlockContext.
 
class BlockEnvironment
  ivar_as_index :__ivars__ => 0, :home => 1, :initial_ip => 2, :last_ip => 3,
    :post_send => 4, :home_block => 5, :local_count => 6, :metadata_container => 7, :method => 8
  def __ivars__ ; @__ivars__ ; end
  def home ; @home ; end
  def initial_ip ; @initial_ip ; end
  def last_ip ; @last_ip ; end
  def post_send ; @post_send ; end
  def home_block ; @home_block ; end
  def local_count ; @local_count ; end
  def method ; @method ; end
 
  attr_accessor :proc_environment
  def from_proc?
    @proc_environment
  end
 
  def home_block=(block)
    @home_block = block
  end
 
  def initial_ip=(ip)
    @initial_ip = ip
  end
 
  def last_ip=(ip)
    @last_ip = ip
  end
 
  def metadata_container
    @metadata_container
  end
 
  def under_context(context, cmethod)
    if context.__kind_of__ BlockContext
      home = context.home
    else
      home = context
    end
 
    @home = home
    @home_block = context
    @method = cmethod
    @local_count = cmethod.local_count
 
    @initial_ip = 0
    @last_ip = 0x10000000 # 2**28
    @post_send = 0
    return self
  end
 
  ##
  # Holds a Tuple of additional metadata.
  # First field of the tuple holds a boolean indicating if the context is from
  # eval
  def metadata_container=(tup)
    @metadata_container = tup
  end
 
  def from_eval?
    @metadata_container and @metadata_container[0]
  end
 
  def from_eval!
    @metadata_container = Tuple.new(1) unless @metadata_container
    @metadata_container[0] = true
  end
 
  ##
  # The CompiledMethod object that we were called from
 
  def method=(tup)
    @method = tup
  end
 
  def home=(home)
    @home = home
  end
 
  def scope=(tup)
    @scope = tup
  end
 
  def make_independent
    @home = @home.dup
    @home_block = @home_block.dup
    @method = @method.dup
  end
 
  def redirect_to(obj)
    env = dup
    env.make_independent
    env.home.receiver = obj
    return env
  end
 
  def call_on_instance(obj, *args)
    obj = redirect_to(obj)
    obj.call(*args)
  end
 
  def disable_long_return!
    @post_send = nil
  end
 
  def arity
    method.required
  end
 
  # Static scope for constant lookup
  def constant_scope=(scope)
    @constant_scope = scope
  end
 
  def constant_scope
    @constant_scope ||= @method.staticscope
  end
end