]> gitweb.factorcode.org Git - factor.git/blob - vm/arrays.hpp
Merge branch 'master' into simd-cleanup
[factor.git] / vm / arrays.hpp
1 namespace factor
2 {
3
4 inline cell array_nth(array *array, cell slot)
5 {
6 #ifdef FACTOR_DEBUG
7         assert(slot < array_capacity(array));
8         assert(array->h.hi_tag() == ARRAY_TYPE);
9 #endif
10         return array->data()[slot];
11 }
12
13 inline void factor_vm::set_array_nth(array *array, cell slot, cell value)
14 {
15 #ifdef FACTOR_DEBUG
16         assert(slot < array_capacity(array));
17         assert(array->h.hi_tag() == ARRAY_TYPE);
18 #endif
19         cell *slot_ptr = &array->data()[slot];
20         *slot_ptr = value;
21         write_barrier(slot_ptr);
22 }
23
24 struct growable_array {
25         cell count;
26         data_root<array> elements;
27
28         explicit growable_array(factor_vm *parent, cell capacity = 10) :
29                 count(0), elements(parent->allot_array(capacity,false_object),parent) {}
30
31         void add(cell elt);
32         void append(array *elts);
33         void trim();
34 };
35
36 }