Class: Rubinius::ToolSet.current::TS::AST::ToplevelConstant

Inherits:
Node
  • Object
show all
Defined in:
lib/rubinius/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, name) ⇒ ToplevelConstant

Returns a new instance of ToplevelConstant.



115
116
117
118
# File 'lib/rubinius/ast/constants.rb', line 115

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



113
114
115
# File 'lib/rubinius/ast/constants.rb', line 113

def name
  @name
end

Instance Method Details

#assign_bytecode(g, value) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/rubinius/ast/constants.rb', line 127

def assign_bytecode(g, value)
  pos(g)

  g.push_cpath_top
  g.push_literal @name
  value.bytecode(g)
end

#bytecode(g) ⇒ Object



120
121
122
123
124
125
# File 'lib/rubinius/ast/constants.rb', line 120

def bytecode(g)
  pos(g)

  g.push_cpath_top
  g.find_const @name
end

#defined(g) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/rubinius/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 :nil

  done.set!
end

#masgn_bytecode(g) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/rubinius/ast/constants.rb', line 135

def masgn_bytecode(g)
  pos(g)

  g.push_cpath_top
  g.swap
  g.push_literal @name
end

#to_sexpObject Also known as: assign_sexp



187
188
189
# File 'lib/rubinius/ast/constants.rb', line 187

def to_sexp
  [:colon3, @name]
end

#value_defined(g, f) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/rubinius/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_cpath_top
  g.push_literal @name
  g.push :false
  g.invoke_primitive :vm_const_defined_under, 3

  g.pop_unwind
  g.goto ok

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

  ok.set!
end