Class: Array64
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#ptr ⇒ Object
readonly
Returns the value of attribute ptr.
Instance Method Summary collapse
- #[](idx) ⇒ Object
- #[]=(idx, value) ⇒ Object
- #empty? ⇒ Boolean
- #free ⇒ Object
-
#initialize(count) ⇒ Array64
constructor
count: number of elements in Array Array elements are native types or pointers to objects Arrays are fixed size for now.
- #length ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(count) ⇒ Array64
count: number of elements in Array Array elements are native types or pointers to objects Arrays are fixed size for now
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rlang/lib/array/array64.rb', line 19 def initialize(count) # Avoid allocating 0 bytes in memory if count == 0 @ptr = 0 else # Memory size is count * 8 bytes @ptr = Object.allocate(count << 3) end @count = count end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
13 14 15 |
# File 'lib/rlang/lib/array/array64.rb', line 13 def count @count end |
#ptr ⇒ Object (readonly)
Returns the value of attribute ptr.
13 14 15 |
# File 'lib/rlang/lib/array/array64.rb', line 13 def ptr @ptr end |
Instance Method Details
#[](idx) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/rlang/lib/array/array64.rb', line 34 def [](idx) result :I64 raise "Index out of bound" if idx >= @count || idx < -@count # offset in memory for elt #idx is idx * 8 Memory.load64(@ptr + (idx << 3)) end |
#[]=(idx, value) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/rlang/lib/array/array64.rb', line 41 def []=(idx, value) arg value: :I64 result :I64 raise "Index out of bound" if idx >= @count || idx < -@count # offset in memory for elt #idx is idx * 8 Memory.store64(@ptr + (idx << 3), value) value end |
#empty? ⇒ Boolean
32 |
# File 'lib/rlang/lib/array/array64.rb', line 32 def empty?; self.size == 0; end |
#free ⇒ Object
50 51 52 53 54 |
# File 'lib/rlang/lib/array/array64.rb', line 50 def free result :none Object.free(@ptr) Object.free(self) end |
#length ⇒ Object
31 |
# File 'lib/rlang/lib/array/array64.rb', line 31 def length; @count; end |
#size ⇒ Object
30 |
# File 'lib/rlang/lib/array/array64.rb', line 30 def size; @count; end |