factor/vm/arrays.hpp

37 lines
758 B
C++
Raw Normal View History

2009-05-04 02:46:13 -04:00
namespace factor
{
2009-08-17 16:37:10 -04:00
inline cell array_nth(array *array, cell slot)
{
#ifdef FACTOR_DEBUG
assert(slot < array_capacity(array));
2009-05-04 05:50:24 -04:00
assert(array->h.hi_tag() == ARRAY_TYPE);
#endif
return array->data()[slot];
}
2009-09-29 14:53:10 -04:00
inline void factor_vm::set_array_nth(array *array, cell slot, cell value)
{
#ifdef FACTOR_DEBUG
assert(slot < array_capacity(array));
assert(array->h.hi_tag() == ARRAY_TYPE);
#endif
cell *slot_ptr = &array->data()[slot];
*slot_ptr = value;
write_barrier(slot_ptr);
2009-09-29 14:53:10 -04:00
}
struct growable_array {
cell count;
data_root<array> elements;
2009-09-29 14:53:10 -04:00
explicit growable_array(factor_vm *parent, cell capacity = 10) :
count(0), elements(parent->allot_array(capacity,false_object),parent) {}
2009-09-29 14:53:10 -04:00
void add(cell elt);
void append(array *elts);
2009-09-29 14:53:10 -04:00
void trim();
};
2009-05-04 02:46:13 -04:00
}