From 49baf397f42bf870cdaa5f07faffe17ff9bcde41 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 25 Oct 2009 08:07:36 -0500 Subject: [PATCH] vm: tagged typechecks work better with DEBUG=1 --- vm/tagged.hpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/vm/tagged.hpp b/vm/tagged.hpp index c5325542cb..ea696c6358 100755 --- a/vm/tagged.hpp +++ b/vm/tagged.hpp @@ -16,13 +16,10 @@ 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(); + return ((object *)UNTAG(value_))->h.hi_tag(); else return tag; } @@ -40,23 +37,27 @@ struct tagged return type_p(Type::type_number); } + cell value() const { +#ifdef FACTOR_DEBUG + assert(type_p()); +#endif + return value_; + } + Type *untagged() const { +#ifdef FACTOR_DEBUG + assert(type_p()); +#endif + return (Type *)(UNTAG(value_)); + } + 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) { -#ifdef FACTOR_DEBUG - assert(type_p()); -#endif - } - - explicit tagged(Type *untagged) : value_(factor::tag(untagged)) { -#ifdef FACTOR_DEBUG - assert(type_p()); -#endif - } + explicit tagged(cell tagged) : value_(tagged) {} + explicit tagged(Type *untagged) : value_(factor::tag(untagged)) {} Type *operator->() const { return untagged(); } cell *operator&() const { return &value_; }