Class: Atomy::Code::Constant

Inherits:
Object
  • Object
show all
Defined in:
lib/atomy/code/constant.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, parent = nil) ⇒ Constant

Returns a new instance of Constant.



6
7
8
9
# File 'lib/atomy/code/constant.rb', line 6

def initialize(name, parent = nil)
  @name = name
  @parent = parent
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/atomy/code/constant.rb', line 4

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



4
5
6
# File 'lib/atomy/code/constant.rb', line 4

def parent
  @parent
end

Instance Method Details

#bytecode(gen, mod) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/atomy/code/constant.rb', line 11

def bytecode(gen, mod)
  if @parent
    mod.compile(gen, @parent)
    gen.find_const(@name)
  else
    gen.push_const(@name)
  end
end