Class: Rubinius::ToolSet.current::TS::AST::IterArguments

Inherits:
Node
  • Object
show all
Defined in:
lib/rubinius/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, arguments) ⇒ IterArguments

Returns a new instance of IterArguments.



632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
# File 'lib/rubinius/ast/sends.rb', line 632

def initialize(line, arguments)
  @line = line
  @optional = 0
  @arguments = nil

  @splat_index = -1
  @block_index = nil
  @required_args = 0
  @splat = nil
  @block = nil
  @prelude = nil

  case arguments
  when Fixnum
    @splat_index = nil
    @arity = 0
    @prelude = nil
  when MultipleAssignment
    arguments.iter_arguments

    if arguments.splat
      case arguments.splat
      when EmptySplat
        @splat_index = -2
        arguments.splat = nil
        @prelude = :empty
      else
        @splat = arguments.splat = arguments.splat.value
      end

      @optional = 1
      if arguments.left
        @prelude = :multi
        size = arguments.left.body.size
        @arity = -(size + 1)
        @required_args = size
      else
        @prelude = :splat unless @prelude
        @arity = -1
      end
    elsif arguments.left
      size = arguments.left.body.size
      @prelude = :multi
      @arity = size
      @required_args = size

      # distinguish { |a, | ... } from { |a| ... }
      @splat_index = nil unless size == 1
    else
      @splat_index = 0
      @prelude = :multi
      @arity = -1
    end

    @block = arguments.block

    @arguments = arguments
  when nil
    @arity = -1
    @splat_index = -2 # -2 means accept the splat, but don't store it anywhere
    @prelude = nil
  when BlockPass
    @arity = -1
    @splat_index = -2
    @prelude = nil
    @block = arguments
  else # Assignment
    @splat_index = nil
    @arguments = arguments
    @arity = 1
    @required_args = 1
    @prelude = :single
  end
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



629
630
631
# File 'lib/rubinius/ast/sends.rb', line 629

def arguments
  @arguments
end

#arityObject

Returns the value of attribute arity.



629
630
631
# File 'lib/rubinius/ast/sends.rb', line 629

def arity
  @arity
end

#block_indexObject

Returns the value of attribute block_index.



629
630
631
# File 'lib/rubinius/ast/sends.rb', line 629

def block_index
  @block_index
end

#optionalObject

Returns the value of attribute optional.



629
630
631
# File 'lib/rubinius/ast/sends.rb', line 629

def optional
  @optional
end

#preludeObject

Returns the value of attribute prelude.



629
630
631
# File 'lib/rubinius/ast/sends.rb', line 629

def prelude
  @prelude
end

#required_argsObject Also known as: total_args

Returns the value of attribute required_args.



630
631
632
# File 'lib/rubinius/ast/sends.rb', line 630

def required_args
  @required_args
end

#splat_indexObject

Returns the value of attribute splat_index.



629
630
631
# File 'lib/rubinius/ast/sends.rb', line 629

def splat_index
  @splat_index
end

Instance Method Details

#arguments_bytecode(g, is_array = false) ⇒ Object



734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
# File 'lib/rubinius/ast/sends.rb', line 734

def arguments_bytecode(g, is_array=false)
  g.state.push_masgn

  if @arguments.kind_of? MultipleAssignment
    @arguments.bytecode(g, is_array)
  else
    @arguments.bytecode(g) if @arguments
  end

  g.state.pop_masgn

  if @splat
    @splat_index = @splat.variable.slot
  end
end

#bytecode(g) ⇒ Object



750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
# File 'lib/rubinius/ast/sends.rb', line 750

def bytecode(g)
  case @prelude
  when :single
    g.cast_for_single_block_arg
    arguments_bytecode(g)
    g.pop
  when :multi
    g.cast_for_multi_block_arg
    arguments_bytecode(g, true)
    g.pop
  when :splat
    g.cast_for_splat_block_arg
    arguments_bytecode(g)
    g.pop
  when :empty
    g.cast_for_splat_block_arg
    g.pop
  end

  if @block
    @block.assignment_bytecode(g)
  end
end

#namesObject



713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
# File 'lib/rubinius/ast/sends.rb', line 713

def names
  case @arguments
  when MultipleAssignment
    if arguments = @arguments.left.body
      array = arguments.map { |x| x.name }
    else
      array = []
    end

    if @arguments.splat.kind_of? SplatAssignment
      array << @arguments.splat.name
    end

    array
  when nil
    []
  else
    [@arguments.name]
  end
end

#post_argsObject



709
710
711
# File 'lib/rubinius/ast/sends.rb', line 709

def post_args
  0
end

#to_sexpObject



774
775
776
777
778
779
780
781
782
# File 'lib/rubinius/ast/sends.rb', line 774

def to_sexp
  if @arguments
    @arguments.to_sexp
  elsif @arity == 0
    0
  else
    nil
  end
end