Class: CodeTools::AST::ConstantAssignment

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



296
297
298
299
300
301
302
303
304
305
# File 'lib/rubinius/code/ast/constants.rb', line 296

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.



294
295
296
# File 'lib/rubinius/code/ast/constants.rb', line 294

def constant
  @constant
end

#valueObject

Returns the value of attribute value.



294
295
296
# File 'lib/rubinius/code/ast/constants.rb', line 294

def value
  @value
end

Instance Method Details

#bytecode(g) ⇒ Object



313
314
315
316
317
318
319
320
# File 'lib/rubinius/code/ast/constants.rb', line 313

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



307
308
309
310
311
# File 'lib/rubinius/code/ast/constants.rb', line 307

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

#to_sexpObject



322
323
324
325
326
# File 'lib/rubinius/code/ast/constants.rb', line 322

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