Class: CodeTools::AST::ConstantAccess

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, name, top_level = false) ⇒ ConstantAccess

Returns a new instance of ConstantAccess.



199
200
201
202
203
# File 'lib/rubinius/code/ast/constants.rb', line 199

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



197
198
199
# File 'lib/rubinius/code/ast/constants.rb', line 197

def name
  @name
end

Instance Method Details

#assign_bytecode(g, value) ⇒ Object



224
225
226
227
228
229
230
# File 'lib/rubinius/code/ast/constants.rb', line 224

def assign_bytecode(g, value)
  pos(g)

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

#assign_sexpObject



285
286
287
# File 'lib/rubinius/code/ast/constants.rb', line 285

def assign_sexp
  @name
end

#bytecode(g) ⇒ Object



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/rubinius/code/ast/constants.rb', line 205

def bytecode(g)
  pos(g)

  if g.state.op_asgn?
    g.push_rubinius
    g.find_const :Runtime
    g.push_literal @name
    g.push_scope
    g.send :find_constant_for_op_asign_or, 2
  else
    if @top_level
      g.push_cpath_top
      g.find_const @name
    else
      g.push_const @name
    end
  end
end

#defined(g) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/rubinius/code/ast/constants.rb', line 240

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



232
233
234
235
236
237
238
# File 'lib/rubinius/code/ast/constants.rb', line 232

def masgn_bytecode(g)
  pos(g)

  g.push_scope
  g.swap
  g.push_literal @name
end

#to_sexpObject



289
290
291
# File 'lib/rubinius/code/ast/constants.rb', line 289

def to_sexp
  [:const, @name]
end

#value_defined(g, f) ⇒ Object



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/rubinius/code/ast/constants.rb', line 256

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_scope
  g.push_literal @name
  g.send :constant_scope_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