]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/arrays.hpp
io.streams.256color: faster by caching styles
[factor.git] / vm / arrays.hpp
old mode 100755 (executable)
new mode 100644 (file)
index e3eaccf..6be877b
@@ -1,17 +1,32 @@
-namespace factor
-{
+namespace factor {
 
-inline cell array_nth(array *array, cell slot)
-{
-#ifdef FACTOR_DEBUG
-       assert(slot < array_capacity(array));
-       assert(array->h.hi_tag() == ARRAY_TYPE);
-#endif
-       return array->data()[slot];
+inline cell array_nth(array* array, cell slot) {
+  FACTOR_ASSERT(slot < array_capacity(array));
+  FACTOR_ASSERT(array->type() == ARRAY_TYPE);
+  return array->data()[slot];
 }
 
-PRIMITIVE(array);
-PRIMITIVE(resize_array);
+inline void factor_vm::set_array_nth(array* array, cell slot, cell value) {
+  FACTOR_ASSERT(slot < array_capacity(array));
+  FACTOR_ASSERT(array->type() == ARRAY_TYPE);
+  cell* slot_ptr = &array->data()[slot];
+  *slot_ptr = value;
+  write_barrier(slot_ptr);
+}
+
+struct growable_array {
+  cell count;
+  data_root<array> elements;
+
+  // Allocates memory
+  growable_array(factor_vm* parent, cell capacity = 10)
+      : count(0),
+        elements(parent->allot_array(capacity, false_object), parent) {}
 
+  void reallot_array(cell count);
+  void add(cell elt);
+  void append(array* elts);
+  void trim();
+};
 
 }