]> gitweb.factorcode.org Git - factor.git/commitdiff
moved tagged template code back into tagged.hpp header
authorPhil Dawes <phil@phildawes.net>
Mon, 17 Aug 2009 20:37:15 +0000 (21:37 +0100)
committerPhil Dawes <phil@phildawes.net>
Wed, 16 Sep 2009 07:16:26 +0000 (08:16 +0100)
vm/inlineimpls.hpp
vm/master.hpp
vm/tagged.hpp

index b88b3254dffea0adac09397a10964260b7d54a46..8885c09404747e8794010634bc8987901ae4a817 100644 (file)
@@ -6,76 +6,6 @@ namespace factor
 
 //tagged.hpp
 
-template <typename TYPE>
-struct tagged
-{
-       cell value_;
-
-       cell value() const { return value_; }
-       TYPE *untagged() const { return (TYPE *)(UNTAG(value_)); }
-
-       cell type() const {
-               cell tag = TAG(value_);
-               if(tag == OBJECT_TYPE)
-                       return untagged()->h.hi_tag();
-               else
-                       return tag;
-       }
-
-       bool type_p(cell type_) const { return type() == type_; }
-
-       TYPE *untag_check() const {
-               if(TYPE::type_number != TYPE_COUNT && !type_p(TYPE::type_number))
-                       type_error(TYPE::type_number,value_);
-               return untagged();
-       }
-
-       explicit tagged(cell tagged) : value_(tagged) {
-#ifdef FACTOR_DEBUG
-               untag_check();
-#endif
-       }
-
-       explicit tagged(TYPE *untagged) : value_(factor::tag(untagged)) {
-#ifdef FACTOR_DEBUG
-               untag_check();
-#endif
-       }
-
-       TYPE *operator->() const { return untagged(); }
-       cell *operator&() const { return &value_; }
-
-       const tagged<TYPE>& operator=(const TYPE *x) { value_ = tag(x); return *this; }
-       const tagged<TYPE>& operator=(const cell &x) { value_ = x; return *this; }
-
-       bool operator==(const tagged<TYPE> &x) { return value_ == x.value_; }
-       bool operator!=(const tagged<TYPE> &x) { return value_ != x.value_; }
-
-       template<typename X> tagged<X> as() { return tagged<X>(value_); }
-};
-
-template <typename TYPE> TYPE *factorvm::untag_check(cell value)
-{
-       return tagged<TYPE>(value).untag_check();
-}
-
-template <typename TYPE> TYPE *untag_check(cell value)
-{
-       return vm->untag_check<TYPE>(value);
-}
-
-template <typename TYPE> TYPE *factorvm::untag(cell value)
-{
-       return tagged<TYPE>(value).untagged();
-}
-
-template <typename TYPE> TYPE *untag(cell value)
-{
-       return vm->untag<TYPE>(value);
-}
-
-
-
 // write_barrier.hpp
 
 inline card *factorvm::addr_to_card(cell a)
index 5d95fa440e7074291b2807ccfe1ee20ee2f537e2..bf60d1e4f6c533322a664b77d0ed5b5a0481aee6 100755 (executable)
@@ -41,7 +41,6 @@
 #include "segments.hpp"
 #include "contexts.hpp"
 #include "run.hpp"
-#include "tagged.hpp"
 #include "profiler.hpp"
 #include "errors.hpp"
 #include "bignumint.hpp"
@@ -68,6 +67,7 @@
 #include "callstack.hpp"
 #include "alien.hpp"
 #include "vm.hpp"
+#include "tagged.hpp"
 #include "inlineimpls.hpp"
 #include "jit.hpp"
 #include "quotations.hpp"
index ca208555da1c64a942cce81f14d9d21248874cef..4a1babb59983b9f3dde802ec3bedb1942a09610c 100755 (executable)
@@ -10,4 +10,74 @@ inline static cell tag_dynamic(object *value)
 {
        return RETAG(value,tag_for(value->h.hi_tag()));
 }
+
+template <typename TYPE>
+struct tagged
+{
+       cell value_;
+
+       cell value() const { return value_; }
+       TYPE *untagged() const { return (TYPE *)(UNTAG(value_)); }
+
+       cell type() const {
+               cell tag = TAG(value_);
+               if(tag == OBJECT_TYPE)
+                       return untagged()->h.hi_tag();
+               else
+                       return tag;
+       }
+
+       bool type_p(cell type_) const { return type() == type_; }
+
+       TYPE *untag_check() const {
+               if(TYPE::type_number != TYPE_COUNT && !type_p(TYPE::type_number))
+                       type_error(TYPE::type_number,value_);
+               return untagged();
+       }
+
+       explicit tagged(cell tagged) : value_(tagged) {
+#ifdef FACTOR_DEBUG
+               untag_check();
+#endif
+       }
+
+       explicit tagged(TYPE *untagged) : value_(factor::tag(untagged)) {
+#ifdef FACTOR_DEBUG
+               untag_check();
+#endif
+       }
+
+       TYPE *operator->() const { return untagged(); }
+       cell *operator&() const { return &value_; }
+
+       const tagged<TYPE>& operator=(const TYPE *x) { value_ = tag(x); return *this; }
+       const tagged<TYPE>& operator=(const cell &x) { value_ = x; return *this; }
+
+       bool operator==(const tagged<TYPE> &x) { return value_ == x.value_; }
+       bool operator!=(const tagged<TYPE> &x) { return value_ != x.value_; }
+
+       template<typename X> tagged<X> as() { return tagged<X>(value_); }
+};
+
+template <typename TYPE> TYPE *factorvm::untag_check(cell value)
+{
+       return tagged<TYPE>(value).untag_check();
+}
+
+template <typename TYPE> TYPE *untag_check(cell value)
+{
+       return vm->untag_check<TYPE>(value);
+}
+
+template <typename TYPE> TYPE *factorvm::untag(cell value)
+{
+       return tagged<TYPE>(value).untagged();
+}
+
+template <typename TYPE> TYPE *untag(cell value)
+{
+       return vm->untag<TYPE>(value);
+}
+
+
 }