Class: CodeTools::AST::GlobalVariableAccess

Inherits:
VariableAccess show all
Defined in:
lib/rubinius/code/ast/variables.rb

Constant Summary collapse

EnglishBackrefs =
{
  :$LAST_MATCH_INFO => :~,
  :$MATCH => :&,
  :$PREMATCH => :'`',
  :$POSTMATCH => :"'",
  :$LAST_PAREN_MATCH => :+,
}

Instance Attribute Summary

Attributes inherited from VariableAccess

#name

Attributes inherited from Node

#line

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from VariableAccess

#initialize, #value_defined

Methods inherited from Node

#ascii_graph, #attributes, #children, #initialize, 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, #value_defined, #visit, #walk

Constructor Details

This class inherits a constructor from CodeTools::AST::VariableAccess

Class Method Details

.for_name(line, name) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/rubinius/code/ast/variables.rb', line 259

def self.for_name(line, name)
  case name
  when :$!
    CurrentException.new(line)
  when :$~
    BackRef.new(line, :~)
  else
    if backref = EnglishBackrefs[name]
      BackRef.new(line, backref)
    else
      new(line, name)
    end
  end
end

Instance Method Details

#bytecode(g) ⇒ Object



274
275
276
277
278
279
280
281
# File 'lib/rubinius/code/ast/variables.rb', line 274

def bytecode(g)
  pos(g)

  g.push_rubinius
  g.find_const :Globals
  g.push_literal @name
  g.send :[], 1
end

#defined(g) ⇒ Object



291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/rubinius/code/ast/variables.rb', line 291

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

  variable_defined(g, f)
  g.push_literal "global-variable"
  g.goto done

  f.set!
  g.push_nil

  done.set!
end

#to_sexpObject



305
306
307
# File 'lib/rubinius/code/ast/variables.rb', line 305

def to_sexp
  [:gvar, @name]
end

#variable_defined(g, f) ⇒ Object



283
284
285
286
287
288
289
# File 'lib/rubinius/code/ast/variables.rb', line 283

def variable_defined(g, f)
  g.push_rubinius
  g.find_const :Globals
  g.push_literal @name
  g.send :key?, 1
  g.goto_if_false f
end