Class: Citrus::Variable

Inherits:
Object
  • Object
show all
Defined in:
lib/citrus/compiler/variable.rb

Direct Known Subclasses

GlobalVariable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, builder) ⇒ Variable

Returns a new instance of Variable.



7
8
9
10
11
12
13
14
15
16
# File 'lib/citrus/compiler/variable.rb', line 7

def initialize(value, builder)
  @value = nil
  if value.is_a?(Citrus::Array)
    @value = value
    @type = LLVM::Type(value.pointer)
  else
    @type = LLVM::Type(value)
  end
  build_initialize(value, builder)
end

Instance Attribute Details

#pointerObject (readonly)

Returns the value of attribute pointer.



5
6
7
# File 'lib/citrus/compiler/variable.rb', line 5

def pointer
  @pointer
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/citrus/compiler/variable.rb', line 4

def type
  @type
end

Instance Method Details

#assign(value, builder) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/citrus/compiler/variable.rb', line 18

def assign(value, builder)
  if value.is_a?(Citrus::Array)
    @value = value
    @type = LLVM::Type(value.pointer)
  end
  build_assign(value, builder)
end

#value(builder) ⇒ Object



26
27
28
29
# File 'lib/citrus/compiler/variable.rb', line 26

def value(builder)
  val = build_load(builder)
  return @value.nil? ? val : @value
end