class CodeTools::AST::If

Attributes

body[RW]
condition[RW]
else[RW]

Public Class Methods

new(line, condition, body, else_body) click to toggle source
# File lib/rubinius/code/ast/control_flow.rb, line 308
def initialize(line, condition, body, else_body)
  @line = line
  @condition = condition
  @body = body || NilLiteral.new(line)
  @else = else_body || NilLiteral.new(line)
end

Public Instance Methods

bytecode(g) click to toggle source
# File lib/rubinius/code/ast/control_flow.rb, line 315
def bytecode(g)
  pos(g)

  done = g.new_label
  else_label = g.new_label

  @condition.bytecode(g)
  g.goto_if_false else_label

  @body.bytecode(g)
  g.goto done

  else_label.set!
  @else.bytecode(g)

  # Use line 0 to indicate "compiler generated code"
  # so that debuggers and such don't get confused by
  # thinking the then branch jumps into the else branch.
  g.set_line 0
  done.set!
end
defined(g) click to toggle source
# File lib/rubinius/code/ast/control_flow.rb, line 337
def defined(g)
  g.push_literal "expression"
end
to_sexp() click to toggle source
# File lib/rubinius/code/ast/control_flow.rb, line 341
def to_sexp
  else_sexp = @else.kind_of?(NilLiteral) ? nil : @else.to_sexp
  [:if, @condition.to_sexp, @body.to_sexp, else_sexp]
end