]> gitweb.factorcode.org Git - factor.git/blob - vm/arrays.hpp
added vm member to gc_root and growable arrays
[factor.git] / vm / arrays.hpp
1 namespace factor
2 {
3 inline static cell array_nth(array *array, cell slot)
4 {
5 #ifdef FACTOR_DEBUG
6         assert(slot < array_capacity(array));
7         assert(array->h.hi_tag() == ARRAY_TYPE);
8 #endif
9         return array->data()[slot];
10 }
11
12 inline static void set_array_nth(array *array, cell slot, cell value)
13 {
14 #ifdef FACTOR_DEBUG
15         assert(slot < array_capacity(array));
16         assert(array->h.hi_tag() == ARRAY_TYPE);
17         check_tagged_pointer(value);
18 #endif
19         array->data()[slot] = value;
20         write_barrier(array);
21 }
22
23 array *allot_array(cell capacity, cell fill);
24
25 cell allot_array_1(cell obj);
26 cell allot_array_2(cell v1, cell v2);
27 cell allot_array_4(cell v1, cell v2, cell v3, cell v4);
28
29 PRIMITIVE(array);
30 PRIMITIVE(resize_array);
31
32 struct growable_array {
33         cell count;
34         gc_root<array> elements;
35
36         growable_array(factorvm *myvm, cell capacity = 10) : count(0), elements(allot_array(capacity,F),myvm) {}
37
38         void add(cell elt);
39         void trim();
40 };
41
42 }