VM: refactoring that removes data_root_ranges
instead of storing data_root_ranges in data_roots, you can just store cell pointers directly. the advantage with doing it that way is that registration and traversal code becomes simpler (and slightly faster).db4
parent
77d4d5179c
commit
0c9e61ca99
|
@ -42,14 +42,18 @@ void factor_vm::primitive_resize_array() {
|
||||||
|
|
||||||
/* Allocates memory */
|
/* Allocates memory */
|
||||||
cell factor_vm::std_vector_to_array(std::vector<cell>& elements) {
|
cell factor_vm::std_vector_to_array(std::vector<cell>& elements) {
|
||||||
|
|
||||||
cell element_count = elements.size();
|
cell element_count = elements.size();
|
||||||
data_roots.push_back(data_root_range(&elements[0], element_count));
|
cell orig_size = data_roots.size();
|
||||||
|
data_roots.reserve(orig_size + element_count);
|
||||||
|
|
||||||
|
for (cell n = 0; n < element_count; n++) {
|
||||||
|
data_roots.push_back(&elements[n]);
|
||||||
|
}
|
||||||
|
|
||||||
tagged<array> objects(allot_uninitialized_array<array>(element_count));
|
tagged<array> objects(allot_uninitialized_array<array>(element_count));
|
||||||
memcpy(objects->data(), &elements[0], element_count * sizeof(cell));
|
memcpy(objects->data(), &elements[0], element_count * sizeof(cell));
|
||||||
|
data_roots.resize(orig_size);
|
||||||
data_roots.pop_back();
|
|
||||||
|
|
||||||
return objects.value();
|
return objects.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ template <typename Type> struct data_root : public tagged<Type> {
|
||||||
factor_vm* parent;
|
factor_vm* parent;
|
||||||
|
|
||||||
void push() {
|
void push() {
|
||||||
parent->data_roots.push_back(data_root_range(&this->value_, 1));
|
parent->data_roots.push_back(&this->value_);
|
||||||
}
|
}
|
||||||
|
|
||||||
data_root(cell value, factor_vm* parent)
|
data_root(cell value, factor_vm* parent)
|
||||||
|
|
|
@ -323,12 +323,4 @@ struct tuple : public object {
|
||||||
cell* data() const { return (cell*)(this + 1); }
|
cell* data() const { return (cell*)(this + 1); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct data_root_range {
|
|
||||||
cell* start;
|
|
||||||
cell len;
|
|
||||||
|
|
||||||
data_root_range(cell* start, cell len)
|
|
||||||
: start(start), len(len) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,12 +175,14 @@ void slot_visitor<Fixup>::visit_stack_elements(segment* region, cell* top) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Fixup> void slot_visitor<Fixup>::visit_data_roots() {
|
template <typename Fixup> void slot_visitor<Fixup>::visit_data_roots() {
|
||||||
std::vector<data_root_range>::const_iterator iter =
|
std::vector<cell*>::const_iterator iter =
|
||||||
parent->data_roots.begin();
|
parent->data_roots.begin();
|
||||||
std::vector<data_root_range>::const_iterator end = parent->data_roots.end();
|
std::vector<cell*>::const_iterator end =
|
||||||
|
parent->data_roots.end();
|
||||||
|
|
||||||
for (; iter < end; iter++)
|
for (; iter < end; iter++) {
|
||||||
visit_object_array(iter->start, iter->start + iter->len);
|
visit_handle(*iter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Fixup> void slot_visitor<Fixup>::visit_bignum_roots() {
|
template <typename Fixup> void slot_visitor<Fixup>::visit_bignum_roots() {
|
||||||
|
|
|
@ -112,7 +112,8 @@ struct factor_vm {
|
||||||
allocates memory, it must wrap any references to the data and code
|
allocates memory, it must wrap any references to the data and code
|
||||||
heaps with data_root and code_root smart pointers, which register
|
heaps with data_root and code_root smart pointers, which register
|
||||||
themselves here. See data_roots.hpp and code_roots.hpp */
|
themselves here. See data_roots.hpp and code_roots.hpp */
|
||||||
std::vector<data_root_range> data_roots;
|
|
||||||
|
std::vector<cell*> data_roots;
|
||||||
std::vector<cell> bignum_roots;
|
std::vector<cell> bignum_roots;
|
||||||
std::vector<code_root*> code_roots;
|
std::vector<code_root*> code_roots;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue