]> gitweb.factorcode.org Git - factor.git/blob - vm/local_roots.hpp
moved local_roots and write_barrier stuff out of inlineimpls.hpp
[factor.git] / vm / local_roots.hpp
1 namespace factor
2 {
3
4 //local_roots.hpp
5 template <typename TYPE>
6 struct gc_root : public tagged<TYPE>
7 {
8         factor_vm *parent_vm;
9
10         void push() { parent_vm->check_tagged_pointer(tagged<TYPE>::value()); parent_vm->gc_locals.push_back((cell)this); }
11         
12         explicit gc_root(cell value_,factor_vm *vm) : tagged<TYPE>(value_),parent_vm(vm) { push(); }
13         explicit gc_root(TYPE *value_, factor_vm *vm) : tagged<TYPE>(value_),parent_vm(vm) { push(); }
14
15         const gc_root<TYPE>& operator=(const TYPE *x) { tagged<TYPE>::operator=(x); return *this; }
16         const gc_root<TYPE>& operator=(const cell &x) { tagged<TYPE>::operator=(x); return *this; }
17
18         ~gc_root() {
19 #ifdef FACTOR_DEBUG
20                 assert(myvm->gc_locals.back() == (cell)this);
21 #endif
22                 parent_vm->gc_locals.pop_back();
23         }
24 };
25
26 /* A similar hack for the bignum implementation */
27 struct gc_bignum
28 {
29         bignum **addr;
30         factor_vm *parent_vm;
31         gc_bignum(bignum **addr_, factor_vm *vm) : addr(addr_), parent_vm(vm) {
32                 if(*addr_)
33                         parent_vm->check_data_pointer(*addr_);
34                 parent_vm->gc_bignums.push_back((cell)addr);
35         }
36
37         ~gc_bignum() {
38 #ifdef FACTOR_DEBUG
39                 assert(myvm->gc_bignums.back() == (cell)addr);
40 #endif
41                 parent_vm->gc_bignums.pop_back();
42         }
43 };
44
45 #define GC_BIGNUM(x) gc_bignum x##__gc_root(&x,this)
46
47 }