Class: CodeTools::AST::ForParameters

Inherits:
Node
  • Object
show all
Defined in:
lib/rubinius/code/ast/sends.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#line

Instance Method Summary collapse

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, assignments) ⇒ ForParameters

Returns a new instance of ForParameters.



844
845
846
847
848
849
850
851
852
# File 'lib/rubinius/code/ast/sends.rb', line 844

def initialize(line, assignments)
  @line = line
  @assignments = assignments
  @splat_index = assignments.kind_of?(MultipleAssignment) ? 0 : nil
  @required_args = @splat_index ? 0 : 1
  @post_args = 0
  @keywords = nil
  @block_index = nil
end

Instance Attribute Details

#assignmentsObject

Returns the value of attribute assignments.



841
842
843
# File 'lib/rubinius/code/ast/sends.rb', line 841

def assignments
  @assignments
end

#block_indexObject

Returns the value of attribute block_index.



841
842
843
# File 'lib/rubinius/code/ast/sends.rb', line 841

def block_index
  @block_index
end

#keywordsObject

Returns the value of attribute keywords.



841
842
843
# File 'lib/rubinius/code/ast/sends.rb', line 841

def keywords
  @keywords
end

#post_argsObject

Returns the value of attribute post_args.



841
842
843
# File 'lib/rubinius/code/ast/sends.rb', line 841

def post_args
  @post_args
end

#required_argsObject Also known as: total_args, arity

Returns the value of attribute required_args.



841
842
843
# File 'lib/rubinius/code/ast/sends.rb', line 841

def required_args
  @required_args
end

#splat_indexObject

Returns the value of attribute splat_index.



841
842
843
# File 'lib/rubinius/code/ast/sends.rb', line 841

def splat_index
  @splat_index
end

Instance Method Details

#bytecode(g) ⇒ Object



864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
# File 'lib/rubinius/code/ast/sends.rb', line 864

def bytecode(g)
  map_arguments(g.state.scope)

  if @splat_index
    g.push_rubinius
    g.find_const :Runtime
    g.push_local 0
    g.send :unwrap_block_arg, 1
  else
    g.push_local 0
  end

  g.state.push_masgn
  @assignments.bytecode(g)
  g.state.pop_masgn
end

#map_arguments(scope) ⇒ Object



857
858
859
860
861
862
# File 'lib/rubinius/code/ast/sends.rb', line 857

def map_arguments(scope)
  case @assignments
  when LocalVariable
    scope.assign_local_reference @assignments
  end
end

#to_sexpObject



881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
# File 'lib/rubinius/code/ast/sends.rb', line 881

def to_sexp
  sexp = [:args]

  case @assignments
  when ArrayLiteral
    @assignments.each do |a|
      case a
      when Symbol
        sexp << a
      when Node
        sexp << a.to_sexp
      end
    end
  else
    sexp << @assignments.to_sexp
  end

  sexp
end