Class: CodeTools::AST::Return

Inherits:
Node
  • Object
show all
Defined in:
lib/rubinius/code/ast/control_flow.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#line

Instance Method Summary collapse

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, expr) ⇒ Return

Returns a new instance of Return.



680
681
682
683
684
# File 'lib/rubinius/code/ast/control_flow.rb', line 680

def initialize(line, expr)
  @line = line
  @value = expr
  @splat = nil
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



678
679
680
# File 'lib/rubinius/code/ast/control_flow.rb', line 678

def value
  @value
end

Instance Method Details

#block=(node) ⇒ Object



686
687
688
# File 'lib/rubinius/code/ast/control_flow.rb', line 686

def block=(node)
  @value.block = node if @value
end

#bytecode(g, force = false) ⇒ Object



690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
# File 'lib/rubinius/code/ast/control_flow.rb', line 690

def bytecode(g, force=false)
  pos(g)

  # Literal ArrayList and a splat
  if @splat
    splat_node = @value.body.pop
    @value.bytecode(g)
    splat_node.call_bytecode(g)
    g.send :+, 1
  elsif @value
    @value.bytecode(g)
  else
    g.push_tagged_nil 0
  end

  if lcl = g.state.rescue?
    g.push_stack_local lcl
    g.restore_exception_state
  end

  if g.state.block?
    g.raise_return
  elsif !force and g.state.ensure?
    g.ensure_return
  else
    g.ret
  end
end

#defined(g) ⇒ Object



719
720
721
# File 'lib/rubinius/code/ast/control_flow.rb', line 719

def defined(g)
  g.push_literal "expression"
end

#to_sexpObject



723
724
725
726
727
728
# File 'lib/rubinius/code/ast/control_flow.rb', line 723

def to_sexp
  sexp = [:return]
  sexp << @value.to_sexp if @value
  sexp << @splat.to_sexp if @splat
  sexp
end