Class: CodeTools::AST::ScopedConstant

Inherits:
Node
  • Object
show all
Defined in:
lib/rubinius/code/ast/constants.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, #visit, #walk

Constructor Details

#initialize(line, parent, name) ⇒ ScopedConstant

Returns a new instance of ScopedConstant.



31
32
33
34
35
# File 'lib/rubinius/code/ast/constants.rb', line 31

def initialize(line, parent, name)
  @line = line
  @parent = parent
  @name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



29
30
31
# File 'lib/rubinius/code/ast/constants.rb', line 29

def name
  @name
end

#parentObject

Returns the value of attribute parent.



29
30
31
# File 'lib/rubinius/code/ast/constants.rb', line 29

def parent
  @parent
end

Instance Method Details

#assign_bytecode(g, value) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/rubinius/code/ast/constants.rb', line 44

def assign_bytecode(g, value)
  pos(g)

  value.bytecode(g)
  g.push_literal @name
  @parent.bytecode(g)
  g.rotate 3
end

#bytecode(g) ⇒ Object



37
38
39
40
41
42
# File 'lib/rubinius/code/ast/constants.rb', line 37

def bytecode(g)
  pos(g)

  @parent.bytecode(g)
  g.find_const @name
end

#defined(g) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rubinius/code/ast/constants.rb', line 61

def defined(g)
  f = g.new_label
  done = g.new_label

  value_defined(g, f, false)

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

  f.set!
  g.push_tagged_nil 0

  done.set!
end

#masgn_bytecode(g) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/rubinius/code/ast/constants.rb', line 53

def masgn_bytecode(g)
  pos(g)

  @parent.bytecode(g)
  g.swap
  g.push_literal @name
end

#to_sexpObject Also known as: assign_sexp



106
107
108
# File 'lib/rubinius/code/ast/constants.rb', line 106

def to_sexp
  [:colon2, @parent.to_sexp, @name]
end

#value_defined(g, f, const_missing = true) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/rubinius/code/ast/constants.rb', line 77

def value_defined(g, f, const_missing=true)
  # 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
  @parent.bytecode(g)
  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