Class: CodeTools::AST::Next

Inherits:
Break show all
Defined in:
lib/rubinius/code/ast/control_flow.rb

Instance Attribute Summary

Attributes inherited from Break

#value

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from Break

#block=, #defined, #jump_error, #to_sexp

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, #to_sexp, #transform, transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk

Constructor Details

#initialize(line, value) ⇒ Next

Returns a new instance of Next.



592
593
594
595
# File 'lib/rubinius/code/ast/control_flow.rb', line 592

def initialize(line, value)
  @line = line
  @value = value
end

Instance Method Details

#bytecode(g) ⇒ Object



597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
# File 'lib/rubinius/code/ast/control_flow.rb', line 597

def bytecode(g)
  pos(g)

  g.pop if g.state.top_level_ensure?

  # From "The Ruby Programming Lanuage"
  #  "When next is used in a loop, any values following the next
  #   are ignored"
  #
  # By ignored, it must mean evaluated and the value of the expression
  # is thrown away, because 1.8 evaluates them even though it doesn't
  # use them.
  if @value
    @value.bytecode(g)
  else
    g.push_tagged_nil 0
  end

  if g.state.loop?
    g.goto_past g.next
  elsif g.state.block?
    if g.next
      g.goto_past g.next
    else
      g.ret
    end
  else
    g.pop

    jump_error g, :next
  end

  g.push_tagged_nil 0 if g.state.top_level_ensure?
end

#sexp_nameObject



632
633
634
# File 'lib/rubinius/code/ast/control_flow.rb', line 632

def sexp_name
  :next
end