Class: CodeTools::AST::Arguments

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, arguments = nil) ⇒ Arguments

Returns a new instance of Arguments.



491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
# File 'lib/rubinius/code/ast/sends.rb', line 491

def initialize(line, arguments=nil)
  @line = line
  @splat = nil

  case arguments
  when SplatValue
    @splat = arguments
    @array = []
  when ConcatArgs
    case arguments.array
    when ArrayLiteral
      @array = arguments.array.body
      @splat = SplatValue.new line, arguments.rest
    when PushArgs
      @array = []
      node = SplatValue.new line, arguments.rest
      @splat = CollectSplat.new line, arguments.array, node
    else
      @array = []
      @splat = CollectSplat.new line, arguments.array, arguments.rest
    end
  when PushArgs
    if arguments.arguments.kind_of? ConcatArgs
      if ary = arguments.arguments.peel_lhs
        @array = ary
      else
        @array = []
      end
    else
      @array = []
    end

    node = ArrayLiteral.new line, [arguments.value]
    @splat = CollectSplat.new line, arguments.arguments, node
  when ArrayLiteral
    @array = arguments.body
  when nil
    @array = []
  else
    @array = [arguments]
  end
end

Instance Attribute Details

#arrayObject

Returns the value of attribute array.



489
490
491
# File 'lib/rubinius/code/ast/sends.rb', line 489

def array
  @array
end

#splatObject

Returns the value of attribute splat.



489
490
491
# File 'lib/rubinius/code/ast/sends.rb', line 489

def splat
  @splat
end

Instance Method Details

#bytecode(g) ⇒ Object



556
557
558
559
# File 'lib/rubinius/code/ast/sends.rb', line 556

def bytecode(g)
  @array.each { |x| x.bytecode(g) }
  @splat.bytecode(g) if @splat
end

#masgn_bytecode(g) ⇒ Object



548
549
550
551
552
553
554
# File 'lib/rubinius/code/ast/sends.rb', line 548

def masgn_bytecode(g)
  @array.each do |x|
    x.bytecode(g)
    g.swap
  end
  # TODO: splat
end

#sizeObject



534
535
536
# File 'lib/rubinius/code/ast/sends.rb', line 534

def size
  @array.size
end

#splat?Boolean

Returns:

  • (Boolean)


544
545
546
# File 'lib/rubinius/code/ast/sends.rb', line 544

def splat?
  not @splat.nil?
end

#stack_sizeObject



538
539
540
541
542
# File 'lib/rubinius/code/ast/sends.rb', line 538

def stack_size
  size = @array.size
  size += 1 if splat?
  size
end

#to_sexpObject



561
562
563
564
565
# File 'lib/rubinius/code/ast/sends.rb', line 561

def to_sexp
  sexp = @array.map { |x| x.to_sexp }
  sexp << @splat.to_sexp if @splat
  sexp
end