Class: Rubinius::ToolSet.current::TS::AST::Iter
- Includes:
- Compiler::LocalVariables
- Defined in:
- lib/rubinius/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.
- #bytecode(g) ⇒ Object
-
#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 inherited from Node
#ascii_graph, #attributes, #children, #defined, 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
Constructor Details
#initialize(line, arguments, body) ⇒ Iter
Returns a new instance of Iter.
495 496 497 498 499 |
# File 'lib/rubinius/ast/sends.rb', line 495 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.
493 494 495 |
# File 'lib/rubinius/ast/sends.rb', line 493 def arguments @arguments end |
#body ⇒ Object
Returns the value of attribute body.
493 494 495 |
# File 'lib/rubinius/ast/sends.rb', line 493 def body @body end |
#parent ⇒ Object
Returns the value of attribute parent.
493 494 495 |
# File 'lib/rubinius/ast/sends.rb', line 493 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.
544 545 546 547 548 549 550 551 552 553 554 555 556 557 |
# File 'lib/rubinius/ast/sends.rb', line 544 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
502 503 504 |
# File 'lib/rubinius/ast/sends.rb', line 502 def block_local?(name) false end |
#bytecode(g) ⇒ Object
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
# File 'lib/rubinius/ast/sends.rb', line 559 def bytecode(g) pos(g) state = g.state state.scope.nest_scope self blk = new_block_generator g, @arguments blk.push_state self blk.definition_line @line blk.state.push_super state.super blk.state.push_eval state.eval blk.state.push_name blk.name # Push line info down. pos(blk) @arguments.bytecode(blk) blk.state.push_block blk.push_modifiers blk.break = nil blk.next = nil blk.redo = blk.new_label blk.redo.set! @body.bytecode(blk) blk.pop_modifiers blk.state.pop_block blk.ret blk.close blk.pop_state blk.splat_index = @arguments.splat_index blk.local_count = local_count blk.local_names = local_names g.create_block blk end |
#module? ⇒ Boolean
506 507 508 |
# File 'lib/rubinius/ast/sends.rb', line 506 def module? false end |
#nest_scope(scope) ⇒ Object
510 511 512 |
# File 'lib/rubinius/ast/sends.rb', line 510 def nest_scope(scope) scope.parent = self end |
#new_local(name) ⇒ Object
531 532 533 |
# File 'lib/rubinius/ast/sends.rb', line 531 def new_local(name) variables[name] ||= Compiler::LocalVariable.new allocate_slot end |
#new_nested_local(name) ⇒ Object
535 536 537 |
# File 'lib/rubinius/ast/sends.rb', line 535 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).
520 521 522 523 524 525 526 527 528 529 |
# File 'lib/rubinius/ast/sends.rb', line 520 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
601 602 603 |
# File 'lib/rubinius/ast/sends.rb', line 601 def sexp_name :iter end |
#to_sexp ⇒ Object
605 606 607 |
# File 'lib/rubinius/ast/sends.rb', line 605 def to_sexp [sexp_name, @arguments.to_sexp, @body.to_sexp] end |