Class: CodeTools::AST::ClassVariableAccess

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

Instance Attribute Summary

Attributes inherited from VariableAccess

#name

Attributes inherited from Node

#line

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, #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

Instance Method Details

#bytecode(g) ⇒ Object



160
161
162
163
164
165
# File 'lib/rubinius/code/ast/variables.rb', line 160

def bytecode(g)
  pos(g)

  push_scope(g)
  g.send :class_variable_get, 1
end

#defined(g) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/rubinius/code/ast/variables.rb', line 182

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

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

  f.set!
  g.push_nil

  done.set!
end

#or_bytecode(g) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/rubinius/code/ast/variables.rb', line 139

def or_bytecode(g)
  pos(g)

  done =     g.new_label
  notfound = g.new_label

  variable_defined(g, notfound)

  # Ok, we know the value exists, get it.
  bytecode(g)
  g.dup
  g.goto_if_true done
  g.pop

  # yield to generate the code for when it's not found
  notfound.set!
  yield

  done.set!
end

#push_scope(g) ⇒ Object



167
168
169
170
171
172
173
174
# File 'lib/rubinius/code/ast/variables.rb', line 167

def push_scope(g)
  if g.state.scope.module?
    g.push_self
  else
    g.push_scope
  end
  g.push_literal @name
end

#to_sexpObject



196
197
198
# File 'lib/rubinius/code/ast/variables.rb', line 196

def to_sexp
  [:cvar, @name]
end

#variable_defined(g, f) ⇒ Object



176
177
178
179
180
# File 'lib/rubinius/code/ast/variables.rb', line 176

def variable_defined(g, f)
  push_scope(g)
  g.send :class_variable_defined?, 1
  g.goto_if_false f
end