Class: CodeTools::AST::Break

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

Direct Known Subclasses

Next, Redo, Retry

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) ⇒ Break

Returns a new instance of Break.



543
544
545
546
# File 'lib/rubinius/code/ast/control_flow.rb', line 543

def initialize(line, expr)
  @line = line
  @value = expr || NilLiteral.new(line)
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



541
542
543
# File 'lib/rubinius/code/ast/control_flow.rb', line 541

def value
  @value
end

Instance Method Details

#block=(node) ⇒ Object



548
549
550
# File 'lib/rubinius/code/ast/control_flow.rb', line 548

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

#bytecode(g) ⇒ Object



558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
# File 'lib/rubinius/code/ast/control_flow.rb', line 558

def bytecode(g)
  pos(g)

  g.pop if g.state.top_level_ensure?

  @value.bytecode(g)

  if g.break
    g.goto g.break
  elsif g.state.block?
    g.raise_break
  else
    g.pop
    jump_error g, :break
  end

  g.push_nil if g.state.top_level_ensure?
end

#defined(g) ⇒ Object



577
578
579
# File 'lib/rubinius/code/ast/control_flow.rb', line 577

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

#jump_error(g, name) ⇒ Object



552
553
554
555
556
# File 'lib/rubinius/code/ast/control_flow.rb', line 552

def jump_error(g, name)
  g.push_rubinius
  g.push_literal name
  g.send :jump_error, 1
end

#sexp_nameObject



581
582
583
# File 'lib/rubinius/code/ast/control_flow.rb', line 581

def sexp_name
  :break
end

#to_sexpObject



585
586
587
588
589
# File 'lib/rubinius/code/ast/control_flow.rb', line 585

def to_sexp
  sexp = [sexp_name]
  sexp << @value.to_sexp if @value
  sexp
end