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.



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

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

Instance Attribute Details

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#block=(node) ⇒ Object



688
689
690
# File 'lib/rubinius/code/ast/control_flow.rb', line 688

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

#bytecode(g, force = false) ⇒ Object



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
718
719
# File 'lib/rubinius/code/ast/control_flow.rb', line 692

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_nil
  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



721
722
723
# File 'lib/rubinius/code/ast/control_flow.rb', line 721

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

#to_sexpObject



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

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