]> gitweb.factorcode.org Git - factor.git/blob - vm/arrays.hpp
merge project-euler.factor
[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         check_tagged_pointer(value);
19 #endif
20         array->data()[slot] = value;
21         write_barrier(array);
22 }
23
24 struct growable_array {
25         cell count;
26         gc_root<array> elements;
27
28         explicit growable_array(factor_vm *myvm, cell capacity = 10) : count(0), elements(myvm->allot_array(capacity,F),myvm) {}
29
30         void add(cell elt);
31         void trim();
32 };
33
34 }