class CodeTools::AST::IterArguments

Attributes

arguments[RW]
arity[RW]
block_index[RW]
keywords[RW]
kwrest_index[RW]
optional[RW]
prelude[RW]
required_args[RW]
splat_index[RW]
total_args[RW]

Public Class Methods

new(line, arguments) click to toggle source
# File lib/rubinius/code/ast/sends.rb, line 705
def initialize(line, arguments)
  @line = line
  @optional = 0
  @arguments = nil

  @splat_index = -1
  @block_index = nil
  @kwrest_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

Public Instance Methods

arguments_bytecode(g, is_array=false) click to toggle source
# File lib/rubinius/code/ast/sends.rb, line 808
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) click to toggle source
# File lib/rubinius/code/ast/sends.rb, line 824
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
names() click to toggle source
# File lib/rubinius/code/ast/sends.rb, line 787
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_args() click to toggle source
# File lib/rubinius/code/ast/sends.rb, line 783
def post_args
  0
end
to_sexp() click to toggle source
# File lib/rubinius/code/ast/sends.rb, line 848
def to_sexp
  if @arguments
    @arguments.to_sexp
  elsif @arity == 0
    0
  else
    nil
  end
end