]> gitweb.factorcode.org Git - factor.git/blob - vm/data_roots.hpp
VM: change type of bignum_roots and remove unnecessary not-null checks
[factor.git] / vm / data_roots.hpp
1 namespace factor {
2
3 template <typename Type> struct data_root : public tagged<Type> {
4   factor_vm* parent;
5
6   void push() {
7     parent->data_roots.push_back(&this->value_);
8   }
9
10   data_root(cell value, factor_vm* parent)
11       : tagged<Type>(value), parent(parent) {
12     push();
13   }
14
15   data_root(Type* value, factor_vm* parent)
16       : tagged<Type>(value), parent(parent) {
17     push();
18   }
19
20   const data_root<Type>& operator=(const Type* x) {
21     tagged<Type>::operator=(x);
22     return *this;
23   }
24   const data_root<Type>& operator=(const cell& x) {
25     tagged<Type>::operator=(x);
26     return *this;
27   }
28
29   ~data_root() { parent->data_roots.pop_back(); }
30 };
31
32 /* A similar hack for the bignum implementation */
33 struct gc_bignum {
34   bignum** addr;
35   factor_vm* parent;
36
37   gc_bignum(bignum** addr, factor_vm* parent) : addr(addr), parent(parent) {
38     parent->check_data_pointer(*addr);
39     parent->bignum_roots.push_back(addr);
40   }
41
42   ~gc_bignum() {
43     FACTOR_ASSERT(parent->bignum_roots.back() == addr);
44     parent->bignum_roots.pop_back();
45   }
46 };
47
48 #define GC_BIGNUM(x) gc_bignum x##__data_root(&x, this)
49
50 }