Class: CodeTools::AST::CollectSplat

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, *parts) ⇒ CollectSplat

Returns a new instance of CollectSplat.



443
444
445
446
447
448
# File 'lib/rubinius/code/ast/sends.rb', line 443

def initialize(line, *parts)
  @line = line
  @splat = parts.shift
  @last = parts.pop
  @array = parts
end

Instance Attribute Details

#arrayObject

Returns the value of attribute array.



441
442
443
# File 'lib/rubinius/code/ast/sends.rb', line 441

def array
  @array
end

#lastObject

Returns the value of attribute last.



441
442
443
# File 'lib/rubinius/code/ast/sends.rb', line 441

def last
  @last
end

#splatObject

Returns the value of attribute splat.



441
442
443
# File 'lib/rubinius/code/ast/sends.rb', line 441

def splat
  @splat
end

Instance Method Details

#bytecode(g) ⇒ Object



450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/rubinius/code/ast/sends.rb', line 450

def bytecode(g)
  @splat.bytecode(g)

  @array.each do |x|
    x.bytecode(g)
    g.cast_array
    g.send :+, 1
  end

  return unless @last

  not_hash = g.new_label
  done = g.new_label

  @last.bytecode(g)

  g.dup
  g.push_cpath_top
  g.find_const :Hash
  g.swap
  g.kind_of
  g.goto_if_false not_hash

  g.make_array 1
  g.goto done

  not_hash.set!
  g.cast_array

  done.set!
  g.send :+, 1
end

#to_sexpObject



483
484
485
# File 'lib/rubinius/code/ast/sends.rb', line 483

def to_sexp
  [:collect_splat] + @array.map { |x| x.to_sexp }
end