]> gitweb.factorcode.org Git - factor.git/blob - vm/data_roots.hpp
Merge branch 'master' into simd-cleanup
[factor.git] / vm / data_roots.hpp
1 namespace factor
2 {
3
4 template<typename Type>
5 struct data_root : public tagged<Type> {
6         factor_vm *parent;
7
8         void push()
9         {
10                 parent->data_roots.push_back((cell)this);
11         }
12
13         explicit data_root(cell value_, factor_vm *parent_)
14                 : tagged<Type>(value_), parent(parent_)
15         {
16                 push();
17         }
18
19         explicit data_root(Type *value_, factor_vm *parent_) :
20                 tagged<Type>(value_), parent(parent_)
21         {
22                 push();
23         }
24
25         const data_root<Type>& operator=(const Type *x) { tagged<Type>::operator=(x); return *this; }
26         const data_root<Type>& operator=(const cell &x) { tagged<Type>::operator=(x); return *this; }
27
28         ~data_root()
29         {
30 #ifdef FACTOR_DEBUG
31                 assert(parent->data_roots.back() == (cell)this);
32 #endif
33                 parent->data_roots.pop_back();
34         }
35 };
36
37 /* A similar hack for the bignum implementation */
38 struct gc_bignum {
39         bignum **addr;
40         factor_vm *parent;
41
42         gc_bignum(bignum **addr_, factor_vm *parent_) : addr(addr_), parent(parent_)
43         {
44                 if(*addr_) parent->check_data_pointer(*addr_);
45                 parent->bignum_roots.push_back((cell)addr);
46         }
47
48         ~gc_bignum()
49         {
50 #ifdef FACTOR_DEBUG
51                 assert(parent->bignum_roots.back() == (cell)addr);
52 #endif
53                 parent->bignum_roots.pop_back();
54         }
55 };
56
57 #define GC_BIGNUM(x) gc_bignum x##__data_root(&x,this)
58
59 }