moved tagged.hpp templates to vm.hpp
parent
75c81af691
commit
e4f92cdbf2
|
@ -1,72 +1,13 @@
|
||||||
namespace factor
|
namespace factor
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename T> cell tag(T *value)
|
template <typename TYPE> 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)
|
inline static cell tag_dynamic(object *value)
|
||||||
{
|
{
|
||||||
return RETAG(value,tag_for(value->h.hi_tag()));
|
return RETAG(value,tag_for(value->h.hi_tag()));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
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<T>& operator=(const T *x) { value_ = tag(x); return *this; }
|
|
||||||
const tagged<T>& operator=(const cell &x) { value_ = x; return *this; }
|
|
||||||
|
|
||||||
bool operator==(const tagged<T> &x) { return value_ == x.value_; }
|
|
||||||
bool operator!=(const tagged<T> &x) { return value_ != x.value_; }
|
|
||||||
|
|
||||||
template<typename X> tagged<X> as() { return tagged<X>(value_); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T> T *untag_check(cell value)
|
|
||||||
{
|
|
||||||
return tagged<T>(value).untag_check();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T> T *untag(cell value)
|
|
||||||
{
|
|
||||||
return tagged<T>(value).untagged();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
73
vm/vm.hpp
73
vm/vm.hpp
|
@ -410,6 +410,8 @@ struct factorvm {
|
||||||
inline double untag_float_check(cell tagged);
|
inline double untag_float_check(cell tagged);
|
||||||
inline fixnum float_to_fixnum(cell tagged);
|
inline fixnum float_to_fixnum(cell tagged);
|
||||||
inline double fixnum_to_float(cell tagged);
|
inline double fixnum_to_float(cell tagged);
|
||||||
|
template <typename T> T *untag_check(cell value);
|
||||||
|
template <typename T> T *untag(cell value);
|
||||||
// next method here:
|
// next method here:
|
||||||
|
|
||||||
//io
|
//io
|
||||||
|
@ -642,6 +644,77 @@ struct factorvm {
|
||||||
|
|
||||||
extern factorvm *vm;
|
extern factorvm *vm;
|
||||||
|
|
||||||
|
//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
|
// write_barrier.hpp
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue