2013-05-11 21:56:42 -04:00
|
|
|
namespace factor {
|
|
|
|
|
|
|
|
template <typename Type> struct data_root : public tagged<Type> {
|
|
|
|
factor_vm* parent;
|
|
|
|
|
|
|
|
void push() {
|
2014-06-11 14:33:33 -04:00
|
|
|
parent->data_roots.push_back(&this->value_);
|
2013-05-11 21:56:42 -04:00
|
|
|
}
|
|
|
|
|
2013-05-12 23:20:43 -04:00
|
|
|
data_root(cell value, factor_vm* parent)
|
|
|
|
: tagged<Type>(value), parent(parent) {
|
2013-05-11 21:56:42 -04:00
|
|
|
push();
|
|
|
|
}
|
|
|
|
|
2013-05-12 23:20:43 -04:00
|
|
|
data_root(Type* value, factor_vm* parent)
|
|
|
|
: tagged<Type>(value), parent(parent) {
|
2013-05-11 21:56:42 -04:00
|
|
|
push();
|
|
|
|
}
|
|
|
|
|
|
|
|
const data_root<Type>& operator=(const Type* x) {
|
|
|
|
tagged<Type>::operator=(x);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
const data_root<Type>& operator=(const cell& x) {
|
|
|
|
tagged<Type>::operator=(x);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
~data_root() { parent->data_roots.pop_back(); }
|
2009-11-02 19:11:12 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/* A similar hack for the bignum implementation */
|
|
|
|
struct gc_bignum {
|
2013-05-11 21:56:42 -04:00
|
|
|
bignum** addr;
|
|
|
|
factor_vm* parent;
|
2009-11-02 19:11:12 -05:00
|
|
|
|
2013-05-12 23:20:43 -04:00
|
|
|
gc_bignum(bignum** addr, factor_vm* parent) : addr(addr), parent(parent) {
|
2014-06-12 13:10:42 -04:00
|
|
|
parent->check_data_pointer(*addr);
|
|
|
|
parent->bignum_roots.push_back(addr);
|
2013-05-11 21:56:42 -04:00
|
|
|
}
|
2009-11-02 19:11:12 -05:00
|
|
|
|
2013-05-11 21:56:42 -04:00
|
|
|
~gc_bignum() {
|
2014-06-12 13:10:42 -04:00
|
|
|
FACTOR_ASSERT(parent->bignum_roots.back() == addr);
|
2013-05-11 21:56:42 -04:00
|
|
|
parent->bignum_roots.pop_back();
|
|
|
|
}
|
2009-11-02 19:11:12 -05:00
|
|
|
};
|
|
|
|
|
2013-05-11 21:56:42 -04:00
|
|
|
#define GC_BIGNUM(x) gc_bignum x##__data_root(&x, this)
|
2009-11-02 19:11:12 -05:00
|
|
|
|
|
|
|
}
|