Class: Rubinius::AST::Iter
- Includes:
- Compiler::LocalVariables
- Defined in:
- lib/compiler/ast/sends.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#body ⇒ Object
Returns the value of attribute body.
-
#parent ⇒ Object
Returns the value of attribute parent.
Attributes inherited from Node
Instance Method Summary collapse
-
#assign_local_reference(var) ⇒ Object
If the local variable exists in this scope, set the local variable node attribute to a reference to the local variable.
-
#block_local?(name) ⇒ Boolean
1.8 doesn’t support declared Iter locals.
-
#initialize(line, arguments, body) ⇒ Iter
constructor
A new instance of Iter.
- #module? ⇒ Boolean
- #nest_scope(scope) ⇒ Object
- #new_local(name) ⇒ Object
- #new_nested_local(name) ⇒ Object
-
#search_local(name) ⇒ Object
A nested scope is looking up a local variable.
- #sexp_name ⇒ Object
- #to_sexp ⇒ Object
Methods included from Compiler::LocalVariables
#allocate_slot, #local_count, #local_names, #variables
Methods inherited from Node
#ascii_graph, #attributes, #children, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, node_name, #pos, #set_child, transform, #transform, transform_comment, transform_kind, transform_kind=, transform_name, #visit, #walk
Constructor Details
#initialize(line, arguments, body) ⇒ Iter
267 268 269 270 271 |
# File 'lib/compiler/ast/sends.rb', line 267 def initialize(line, arguments, body) @line = line @arguments = IterArguments.new line, arguments @body = body || NilLiteral.new(line) end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
265 266 267 |
# File 'lib/compiler/ast/sends.rb', line 265 def arguments @arguments end |
#body ⇒ Object
Returns the value of attribute body.
265 266 267 |
# File 'lib/compiler/ast/sends.rb', line 265 def body @body end |
#parent ⇒ Object
Returns the value of attribute parent.
265 266 267 |
# File 'lib/compiler/ast/sends.rb', line 265 def parent @parent end |
Instance Method Details
#assign_local_reference(var) ⇒ Object
If the local variable exists in this scope, set the local variable node attribute to a reference to the local variable. If the variable exists in an enclosing scope, set the local variable node attribute to a nested reference to the local variable. Otherwise, create a local variable in this scope and set the local variable node attribute.
317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/compiler/ast/sends.rb', line 317 def assign_local_reference(var) if variable = variables[var.name] var.variable = variable.reference elsif block_local?(var.name) variable = new_local var.name var.variable = variable.reference elsif reference = @parent.search_local(var.name) reference.depth += 1 var.variable = reference else variable = new_local var.name var.variable = variable.reference end end |
#block_local?(name) ⇒ Boolean
1.8 doesn’t support declared Iter locals
274 275 276 |
# File 'lib/compiler/ast/sends.rb', line 274 def block_local?(name) false end |
#module? ⇒ Boolean
278 279 280 |
# File 'lib/compiler/ast/sends.rb', line 278 def module? false end |
#nest_scope(scope) ⇒ Object
282 283 284 |
# File 'lib/compiler/ast/sends.rb', line 282 def nest_scope(scope) scope.parent = self end |
#new_local(name) ⇒ Object
303 304 305 306 |
# File 'lib/compiler/ast/sends.rb', line 303 def new_local(name) variable = Compiler::LocalVariable.new allocate_slot variables[name] = variable end |
#new_nested_local(name) ⇒ Object
308 309 310 |
# File 'lib/compiler/ast/sends.rb', line 308 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. If it exists in an enclosing scope, increment the depth of the reference when it passes through this nested scope (i.e. the depth of a reference is a function of the nested scopes it passes through from the scope it is defined in to the scope it is used in).
292 293 294 295 296 297 298 299 300 301 |
# File 'lib/compiler/ast/sends.rb', line 292 def search_local(name) if variable = variables[name] variable.nested_reference elsif block_local?(name) new_local name elsif reference = @parent.search_local(name) reference.depth += 1 reference end end |
#sexp_name ⇒ Object
332 333 334 |
# File 'lib/compiler/ast/sends.rb', line 332 def sexp_name :iter end |
#to_sexp ⇒ Object
336 337 338 |
# File 'lib/compiler/ast/sends.rb', line 336 def to_sexp [sexp_name, @arguments.to_sexp, @body.to_sexp] end |