diff --git a/vm/inlineimpls.hpp b/vm/inlineimpls.hpp index b88b3254df..8885c09404 100644 --- a/vm/inlineimpls.hpp +++ b/vm/inlineimpls.hpp @@ -6,76 +6,6 @@ namespace factor //tagged.hpp -template -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& operator=(const TYPE *x) { value_ = tag(x); return *this; } - const tagged& operator=(const cell &x) { value_ = x; return *this; } - - bool operator==(const tagged &x) { return value_ == x.value_; } - bool operator!=(const tagged &x) { return value_ != x.value_; } - - template tagged as() { return tagged(value_); } -}; - -template TYPE *factorvm::untag_check(cell value) -{ - return tagged(value).untag_check(); -} - -template TYPE *untag_check(cell value) -{ - return vm->untag_check(value); -} - -template TYPE *factorvm::untag(cell value) -{ - return tagged(value).untagged(); -} - -template TYPE *untag(cell value) -{ - return vm->untag(value); -} - - - // write_barrier.hpp inline card *factorvm::addr_to_card(cell a) diff --git a/vm/master.hpp b/vm/master.hpp index 5d95fa440e..bf60d1e4f6 100755 --- a/vm/master.hpp +++ b/vm/master.hpp @@ -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" diff --git a/vm/tagged.hpp b/vm/tagged.hpp index ca208555da..4a1babb599 100755 --- a/vm/tagged.hpp +++ b/vm/tagged.hpp @@ -10,4 +10,74 @@ inline static cell tag_dynamic(object *value) { return RETAG(value,tag_for(value->h.hi_tag())); } + +template +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& operator=(const TYPE *x) { value_ = tag(x); return *this; } + const tagged& operator=(const cell &x) { value_ = x; return *this; } + + bool operator==(const tagged &x) { return value_ == x.value_; } + bool operator!=(const tagged &x) { return value_ != x.value_; } + + template tagged as() { return tagged(value_); } +}; + +template TYPE *factorvm::untag_check(cell value) +{ + return tagged(value).untag_check(); +} + +template TYPE *untag_check(cell value) +{ + return vm->untag_check(value); +} + +template TYPE *factorvm::untag(cell value) +{ + return tagged(value).untagged(); +} + +template TYPE *untag(cell value) +{ + return vm->untag(value); +} + + }