]> gitweb.factorcode.org Git - factor.git/blob - vm/data_roots.hpp
VM: FACTOR_ASSERT so that data_root never wraps a null pointer, cause if it does...
[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     FACTOR_ASSERT(value);
18     push();
19   }
20
21   const data_root<Type>& operator=(const Type* x) {
22     tagged<Type>::operator=(x);
23     return *this;
24   }
25   const data_root<Type>& operator=(const cell& x) {
26     tagged<Type>::operator=(x);
27     return *this;
28   }
29
30   ~data_root() {
31     parent->data_roots.pop_back();
32   }
33
34   friend void swap(data_root<Type>& a, data_root<Type>& b) {
35     cell tmp = a.value_;
36     a.value_ = b.value_;
37     b.value_ = tmp;
38   }
39 };
40
41 }