class CodeTools::AST::ToplevelConstant

Attributes

name[RW]

Public Class Methods

new(line, name) click to toggle source
# File lib/rubinius/code/ast/constants.rb, line 115
def initialize(line, name)
  @line = line
  @name = name
end

Public Instance Methods

assign_bytecode(g, value) click to toggle source
# File lib/rubinius/code/ast/constants.rb, line 127
def assign_bytecode(g, value)
  pos(g)

  g.push_cpath_top
  g.push_literal @name
  value.bytecode(g)
end
assign_sexp()
Alias for: to_sexp
bytecode(g) click to toggle source
# File lib/rubinius/code/ast/constants.rb, line 120
def bytecode(g)
  pos(g)

  g.push_cpath_top
  g.find_const @name
end
defined(g) click to toggle source
# File lib/rubinius/code/ast/constants.rb, line 143
def defined(g)
  f = g.new_label
  done = g.new_label

  value_defined(g, f)

  g.pop
  g.push_literal "constant"
  g.goto done

  f.set!
  g.push_tagged_nil 0

  done.set!
end
masgn_bytecode(g) click to toggle source
# File lib/rubinius/code/ast/constants.rb, line 135
def masgn_bytecode(g)
  pos(g)

  g.push_cpath_top
  g.swap
  g.push_literal @name
end
to_sexp() click to toggle source
# File lib/rubinius/code/ast/constants.rb, line 188
def to_sexp
  [:colon3, @name]
end
Also aliased as: assign_sexp
value_defined(g, f) click to toggle source
# File lib/rubinius/code/ast/constants.rb, line 159
def value_defined(g, f)
  # Save the current exception into a stack local
  g.push_exception_state
  outer_exc_state = g.new_stack_local
  g.set_stack_local outer_exc_state
  g.pop

  ex = g.new_label
  ok = g.new_label
  g.setup_unwind ex, RescueType

  g.push_type
  g.push_cpath_top
  g.push_literal @name
  g.send :constant_path_defined?, 2
  g.dup
  g.goto_if_not_undefined ok
  g.pop
  g.goto f

  ex.set!
  g.clear_exception
  g.push_stack_local outer_exc_state
  g.restore_exception_state
  g.goto f

  ok.set!
end