]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/local_roots.hpp
moved local_roots and write_barrier stuff out of inlineimpls.hpp
[factor.git] / vm / local_roots.hpp
index 0d6a033f82fbb5ec026e60ae817da61a1b8ea832..a827c08f9c867fe92518214a2a63ef90191773b7 100644 (file)
@@ -1,3 +1,47 @@
 namespace factor
 {
+
+//local_roots.hpp
+template <typename TYPE>
+struct gc_root : public tagged<TYPE>
+{
+       factor_vm *parent_vm;
+
+       void push() { parent_vm->check_tagged_pointer(tagged<TYPE>::value()); parent_vm->gc_locals.push_back((cell)this); }
+       
+       explicit gc_root(cell value_,factor_vm *vm) : tagged<TYPE>(value_),parent_vm(vm) { push(); }
+       explicit gc_root(TYPE *value_, factor_vm *vm) : tagged<TYPE>(value_),parent_vm(vm) { push(); }
+
+       const gc_root<TYPE>& operator=(const TYPE *x) { tagged<TYPE>::operator=(x); return *this; }
+       const gc_root<TYPE>& operator=(const cell &x) { tagged<TYPE>::operator=(x); return *this; }
+
+       ~gc_root() {
+#ifdef FACTOR_DEBUG
+               assert(myvm->gc_locals.back() == (cell)this);
+#endif
+               parent_vm->gc_locals.pop_back();
+       }
+};
+
+/* A similar hack for the bignum implementation */
+struct gc_bignum
+{
+       bignum **addr;
+       factor_vm *parent_vm;
+       gc_bignum(bignum **addr_, factor_vm *vm) : addr(addr_), parent_vm(vm) {
+               if(*addr_)
+                       parent_vm->check_data_pointer(*addr_);
+               parent_vm->gc_bignums.push_back((cell)addr);
+       }
+
+       ~gc_bignum() {
+#ifdef FACTOR_DEBUG
+               assert(myvm->gc_bignums.back() == (cell)addr);
+#endif
+               parent_vm->gc_bignums.pop_back();
+       }
+};
+
+#define GC_BIGNUM(x) gc_bignum x##__gc_root(&x,this)
+
 }