Class: CodeTools::AST::Yield

Inherits:
SendWithArguments show all
Defined in:
lib/rubinius/code/ast/sends.rb

Instance Attribute Summary collapse

Attributes inherited from SendWithArguments

#arguments

Attributes inherited from Send

#block, #name, #privately, #receiver, #variable, #vcall_style

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from SendWithArguments

#arguments_sexp

Methods inherited from Send

#arguments_sexp, #check_local_reference, #receiver_sexp, #sexp_name, #value_defined

Methods inherited from Node

#ascii_graph, #attributes, #children, 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, unwrap) ⇒ Yield

Returns a new instance of Yield.



985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
# File 'lib/rubinius/code/ast/sends.rb', line 985

def initialize(line, arguments, unwrap)
  @line = line

  if arguments.kind_of? ArrayLiteral and not unwrap
    arguments = ArrayLiteral.new line, [arguments]
  end

  @arguments = Arguments.new line, arguments
  @argument_count = @arguments.size
  @yield_splat = false

  if @arguments.splat?
    splat = @arguments.splat.value
    if (splat.kind_of? ArrayLiteral or splat.kind_of? EmptyArray) and not unwrap
      @argument_count += 1
    else
      @yield_splat = true
    end
  end
end

Instance Attribute Details

#flagsObject

Returns the value of attribute flags.



983
984
985
# File 'lib/rubinius/code/ast/sends.rb', line 983

def flags
  @flags
end

Instance Method Details

#bytecode(g) ⇒ Object



1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
# File 'lib/rubinius/code/ast/sends.rb', line 1006

def bytecode(g)
  pos(g)

  @arguments.bytecode(g)

  if @yield_splat
    g.yield_splat @argument_count
  else
    g.yield_stack @argument_count
  end
end

#defined(g) ⇒ Object



1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
# File 'lib/rubinius/code/ast/sends.rb', line 1018

def defined(g)
  t = g.new_label
  f = g.new_label

  g.push_block
  g.git t
  g.push :nil
  g.goto f

  t.set!
  g.push_literal "yield"

  f.set!
end

#to_sexpObject



1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
# File 'lib/rubinius/code/ast/sends.rb', line 1033

def to_sexp
  args = @arguments.to_sexp
  args << @block.to_sexp if @block
  if @argument_count == 1 and !@yield_splat and @arguments.splat.nil? and
     @arguments.array.first.kind_of? SplatValue
    [:yield, [:array] + args]
  else
    [:yield] + args
  end
end