From 238e9d98100cde150160571a4ea54d1c1b9287be Mon Sep 17 00:00:00 2001 From: Erik Charlebois Date: Sat, 11 May 2013 22:29:22 -0400 Subject: [PATCH] VM: Refactor tagged.hpp to Factor style --- vm/tagged.hpp | 107 +++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 58 deletions(-) diff --git a/vm/tagged.hpp b/vm/tagged.hpp index 12f649669c..04a25486b9 100644 --- a/vm/tagged.hpp +++ b/vm/tagged.hpp @@ -1,85 +1,76 @@ -namespace factor -{ +namespace factor { -template cell tag(Type *value) -{ - return RETAG(value,Type::type_number); +template cell tag(Type* value) { + return RETAG(value, Type::type_number); } -inline static cell tag_dynamic(object *value) -{ - return RETAG(value,value->type()); +inline static cell tag_dynamic(object* value) { + return RETAG(value, value->type()); } -template -struct tagged -{ - cell value_; +template struct tagged { + cell value_; - cell type() const - { - return TAG(value_); - } + cell type() const { return TAG(value_); } - bool type_p(cell type_) const - { - return type() == type_; - } + bool type_p(cell type_) const { return type() == type_; } - bool type_p() const - { - if(Type::type_number == TYPE_COUNT) - return true; - else - return type_p(Type::type_number); - } + bool type_p() const { + if (Type::type_number == TYPE_COUNT) + return true; + else + return type_p(Type::type_number); + } - cell value() const - { + cell value() const { #ifdef FACTOR_DEBUG - FACTOR_ASSERT(type_p()); + FACTOR_ASSERT(type_p()); #endif - return value_; - } + return value_; + } - Type *untagged() const - { + Type* untagged() const { #ifdef FACTOR_DEBUG - FACTOR_ASSERT(type_p()); + FACTOR_ASSERT(type_p()); #endif - return (Type *)(UNTAG(value_)); - } + return (Type*)(UNTAG(value_)); + } - Type *untag_check(factor_vm *parent) const - { - if(!type_p()) - parent->type_error(Type::type_number,value_); - return untagged(); - } + Type* untag_check(factor_vm* parent) const { + if (!type_p()) + parent->type_error(Type::type_number, value_); + return untagged(); + } - explicit tagged(cell tagged) : value_(tagged) {} - explicit tagged(Type *untagged) : value_(factor::tag(untagged)) {} + explicit tagged(cell tagged) : value_(tagged) {} + explicit tagged(Type* untagged) : value_(factor::tag(untagged)) {} - Type *operator->() const { return untagged(); } - cell *operator&() const { return &value_; } + 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; } + 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_; } + 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 tagged as() { + return tagged(value_); + } }; -template Type *factor_vm::untag_check(cell value) -{ - return tagged(value).untag_check(this); +template Type* factor_vm::untag_check(cell value) { + return tagged(value).untag_check(this); } -template Type *untag(cell value) -{ - return tagged(value).untagged(); +template Type* untag(cell value) { + return tagged(value).untagged(); } }