Class: Citrus::Array

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer, length = nil) ⇒ Array

Returns a new instance of Array.



16
17
18
19
# File 'lib/citrus/compiler/array.rb', line 16

def initialize(pointer, length=nil)
  @pointer = pointer
  @length = length
end

Instance Attribute Details

#lengthObject



21
22
23
24
25
26
27
# File 'lib/citrus/compiler/array.rb', line 21

def length
  unless @length.nil?
    return @length
  else
    return @length = INT.from_i(LLVM::C.LLVMGetArrayLength(LLVM::Type(@pointer).element_type))
  end
end

#pointerObject

Returns the value of attribute pointer.



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

def pointer
  @pointer
end

Class Method Details

.create(values, builder) ⇒ Object



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

def self.create(values, builder)
  ary = builder.alloca(LLVM::Array(LLVM::Type(values.first), values.size))
  for index in 0...values.size
    ptr = builder.gep(ary, [INT.from_i(0), INT.from_i(index)])
    builder.store(values[index], ptr)
  end
  self.new(ary)
end