Class: CodeTools::AST::ConstantAssignment

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

#initialize(line, expr, value) ⇒ ConstantAssignment

Returns a new instance of ConstantAssignment.



292
293
294
295
296
297
298
299
300
301
# File 'lib/rubinius/ast/constants.rb', line 292

def initialize(line, expr, value)
  @line = line
  @value = value

  if expr.kind_of? Symbol
    @constant = ConstantAccess.new line, expr
  else
    @constant = expr
  end
end

Instance Attribute Details

#constantObject

Returns the value of attribute constant.



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

def constant
  @constant
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#bytecode(g) ⇒ Object



309
310
311
312
313
314
315
316
# File 'lib/rubinius/ast/constants.rb', line 309

def bytecode(g)
  pos(g)

  return masgn_bytecode(g) if g.state.masgn?

  @constant.assign_bytecode(g, @value)
  g.send :const_set, 2
end

#masgn_bytecode(g) ⇒ Object



303
304
305
306
307
# File 'lib/rubinius/ast/constants.rb', line 303

def masgn_bytecode(g)
  @constant.masgn_bytecode(g)
  g.swap
  g.send :const_set, 2
end

#to_sexpObject



318
319
320
321
322
# File 'lib/rubinius/ast/constants.rb', line 318

def to_sexp
  sexp = [:cdecl, @constant.assign_sexp]
  sexp << @value.to_sexp if @value
  sexp
end