From e4f92cdbf25253b2bcc545c2f490b6d2050394bb Mon Sep 17 00:00:00 2001 From: Phil Dawes Date: Mon, 17 Aug 2009 21:37:15 +0100 Subject: [PATCH] moved tagged.hpp templates to vm.hpp --- vm/tagged.hpp | 63 ++------------------------------------------ vm/vm.hpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 61 deletions(-) mode change 100644 => 100755 vm/tagged.hpp diff --git a/vm/tagged.hpp b/vm/tagged.hpp old mode 100644 new mode 100755 index ea1942e10c..ca208555da --- a/vm/tagged.hpp +++ b/vm/tagged.hpp @@ -1,72 +1,13 @@ namespace factor { -template cell tag(T *value) +template cell tag(TYPE *value) { - return RETAG(value,tag_for(T::type_number)); + return RETAG(value,tag_for(TYPE::type_number)); } 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_; } - T *untagged() const { return (T *)(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_; } - - T *untag_check() const { - if(T::type_number != TYPE_COUNT && !type_p(T::type_number)) - type_error(T::type_number,value_); - return untagged(); - } - - explicit tagged(cell tagged) : value_(tagged) { -#ifdef FACTOR_DEBUG - untag_check(); -#endif - } - - explicit tagged(T *untagged) : value_(factor::tag(untagged)) { -#ifdef FACTOR_DEBUG - untag_check(); -#endif - } - - T *operator->() const { return untagged(); } - cell *operator&() const { return &value_; } - - const tagged& operator=(const T *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 T *untag_check(cell value) -{ - return tagged(value).untag_check(); -} - -template T *untag(cell value) -{ - return tagged(value).untagged(); -} - } diff --git a/vm/vm.hpp b/vm/vm.hpp index 30b7395a70..24cb7a98f1 100644 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -410,6 +410,8 @@ struct factorvm { inline double untag_float_check(cell tagged); inline fixnum float_to_fixnum(cell tagged); inline double fixnum_to_float(cell tagged); + template T *untag_check(cell value); + template T *untag(cell value); // next method here: //io @@ -642,6 +644,77 @@ struct factorvm { extern factorvm *vm; +//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