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.



850
851
852
853
854
855
856
857
858
859
# File 'lib/rubinius/code/ast/sends.rb', line 850

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
  @kwrest_index = nil
end

Instance Attribute Details

#assignmentsObject

Returns the value of attribute assignments.



847
848
849
# File 'lib/rubinius/code/ast/sends.rb', line 847

def assignments
  @assignments
end

#block_indexObject

Returns the value of attribute block_index.



847
848
849
# File 'lib/rubinius/code/ast/sends.rb', line 847

def block_index
  @block_index
end

#keywordsObject

Returns the value of attribute keywords.



847
848
849
# File 'lib/rubinius/code/ast/sends.rb', line 847

def keywords
  @keywords
end

#kwrest_indexObject

Returns the value of attribute kwrest_index.



847
848
849
# File 'lib/rubinius/code/ast/sends.rb', line 847

def kwrest_index
  @kwrest_index
end

#post_argsObject

Returns the value of attribute post_args.



847
848
849
# File 'lib/rubinius/code/ast/sends.rb', line 847

def post_args
  @post_args
end

#required_argsObject Also known as: total_args, arity

Returns the value of attribute required_args.



847
848
849
# File 'lib/rubinius/code/ast/sends.rb', line 847

def required_args
  @required_args
end

#splat_indexObject

Returns the value of attribute splat_index.



847
848
849
# File 'lib/rubinius/code/ast/sends.rb', line 847

def splat_index
  @splat_index
end

Instance Method Details

#bytecode(g) ⇒ Object



871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
# File 'lib/rubinius/code/ast/sends.rb', line 871

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



864
865
866
867
868
869
# File 'lib/rubinius/code/ast/sends.rb', line 864

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

#to_sexpObject



888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
# File 'lib/rubinius/code/ast/sends.rb', line 888

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