Class: CodeTools::AST::ClosedScope
- Inherits:
-
Node
- Object
- Node
- CodeTools::AST::ClosedScope
show all
- Includes:
- Compiler::LocalVariables
- Defined in:
- lib/rubinius/code/ast/definitions.rb
Instance Attribute Summary collapse
Attributes inherited from Node
#line
Instance Method Summary
collapse
Methods inherited from Node
#ascii_graph, #attributes, #bytecode, #children, #defined, #initialize, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, #or_bytecode, #pos, #set_child, #transform, transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
109
110
111
|
# File 'lib/rubinius/code/ast/definitions.rb', line 109
def body
@body
end
|
Instance Method Details
#assign_local_reference(var) ⇒ Object
There is no place above us that may contain a local variable. Set the local in our local variables hash if not set. Set the local variable node attribute to a reference to the local variable.
130
131
132
133
134
135
136
|
# File 'lib/rubinius/code/ast/definitions.rb', line 130
def assign_local_reference(var)
unless variable = variables[var.name]
variable = new_local var.name
end
var.variable = variable.reference
end
|
#attach_and_call(g, arg_name, scoped = false, pass_block = false) ⇒ Object
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/rubinius/code/ast/definitions.rb', line 146
def attach_and_call(g, arg_name, scoped=false, pass_block=false)
name = @name || arg_name
meth = new_generator(g, name)
meth.push_state self
meth.for_module_body = true
if scoped
meth.push_self
meth.add_scope
end
meth.state.push_name name
@body.bytecode meth
meth.state.pop_name
meth.ret
meth.close
meth.local_count = local_count
meth.local_names = local_names
meth.pop_state
g.create_block meth
g.swap
g.push_scope
g.push_true
g.send :call_under, 3
return meth
end
|
#module? ⇒ Boolean
142
143
144
|
# File 'lib/rubinius/code/ast/definitions.rb', line 142
def module?
false
end
|
#nest_scope(scope) ⇒ Object
138
139
140
|
# File 'lib/rubinius/code/ast/definitions.rb', line 138
def nest_scope(scope)
scope.parent = self
end
|
#new_local(name) ⇒ Object
119
120
121
|
# File 'lib/rubinius/code/ast/definitions.rb', line 119
def new_local(name)
variables[name] ||= Compiler::LocalVariable.new allocate_slot
end
|
#new_nested_local(name) ⇒ Object
123
124
125
|
# File 'lib/rubinius/code/ast/definitions.rb', line 123
def new_nested_local(name)
new_local(name).nested_reference
end
|
#search_local(name) ⇒ Object
A nested scope is looking up a local variable. If the variable exists in our local variables hash, return a nested reference to it.
113
114
115
116
117
|
# File 'lib/rubinius/code/ast/definitions.rb', line 113
def search_local(name)
if variable = variables[name]
variable.nested_reference
end
end
|
#to_sexp ⇒ Object
181
182
183
184
185
|
# File 'lib/rubinius/code/ast/definitions.rb', line 181
def to_sexp
sexp = [:scope]
sexp << @body.to_sexp if @body
sexp
end
|