diff --git a/hawk/lib/Hawk.hpp b/hawk/lib/Hawk.hpp index 280761c8..a9ee84cd 100644 --- a/hawk/lib/Hawk.hpp +++ b/hawk/lib/Hawk.hpp @@ -1045,6 +1045,8 @@ public: return p; } + int getType () const { return hawk_get_val_type(this->val); } + int getInt (hawk_int_t* v) const; int getFlt (hawk_flt_t* v) const; int getNum (hawk_int_t* lv, hawk_flt_t* fv) const; diff --git a/hawk/lib/HawkStd.cpp b/hawk/lib/HawkStd.cpp index ecab3c94..745845f0 100644 --- a/hawk/lib/HawkStd.cpp +++ b/hawk/lib/HawkStd.cpp @@ -1279,7 +1279,7 @@ int HawkStd::SourceFile::open (Data& io) if (this->cmgr) hawk_sio_setcmgr (sio, this->cmgr); io.setName (xpath); - io.setPath (xpath); // let parser use this path, especially upon an error + io.setPath (xpath); // let the parser use this path, especially upon an error } else { @@ -1367,11 +1367,8 @@ hawk_ooi_t HawkStd::SourceFile::write (Data& io, const hawk_ooch_t* buf, hawk_oo HawkStd::SourceString::~SourceString () { - if (this->_hawk) - { - HAWK_ASSERT (this->str != HAWK_NULL); - hawk_freemem (this->_hawk, this->str); - } + HAWK_ASSERT (this->_hawk == HAWK_NULL); + HAWK_ASSERT (this->str == HAWK_NULL); } int HawkStd::SourceString::open (Data& io) @@ -1394,21 +1391,21 @@ int HawkStd::SourceString::open (Data& io) if (this->_type == STR_UCH) { #if defined(HAWK_OOCH_IS_UCH) - this->str = hawk_dupucstr(this->_hawk, (hawk_uch_t*)this->_str, HAWK_NULL); + this->str = hawk_dupucstr(this->_hawk, (const hawk_uch_t*)this->_str, HAWK_NULL); #else - this->str = hawk_duputobcstr(this->_hawk, (hawk_uch_t*)this->_str, HAWK_NULL); + this->str = hawk_duputobcstr(this->_hawk, (const hawk_uch_t*)this->_str, HAWK_NULL); #endif } else { HAWK_ASSERT (this->_type == STR_BCH); #if defined(HAWK_OOCH_IS_UCH) - this->str = hawk_dupbtoucstr(this->_hawk, (hawk_bch_t*)this->_str, HAWK_NULL, 0); + this->str = hawk_dupbtoucstr(this->_hawk, (const hawk_bch_t*)this->_str, HAWK_NULL, 0); #else - this->str = hawk_dupbcstr(this->_hawk, (hawk_bch_t*)this->_str, HAWK_NULL); + this->str = hawk_dupbcstr(this->_hawk, (const hawk_bch_t*)this->_str, HAWK_NULL); #endif } - if (!this->str) + if (HAWK_UNLIKELY(!this->str)) { this->_hawk = HAWK_NULL; return -1; @@ -1448,7 +1445,7 @@ int HawkStd::SourceString::open (Data& io) if (totlen >= HAWK_COUNTOF(fbuf)) { dbuf = (hawk_ooch_t*)hawk_allocmem((hawk_t*)io, HAWK_SIZEOF(hawk_ooch_t) * (totlen + 1)); - if (!dbuf) return -1; + if (HAWK_UNLIKELY(!dbuf)) return -1; path = dbuf; } else path = fbuf; @@ -1464,7 +1461,7 @@ int HawkStd::SourceString::open (Data& io) { xpath = hawk_addsionamewithoochars((hawk_t*)io, ioname, hawk_count_oocstr(ioname)); } - if (!xpath) return -1; + if (HAWK_UNLIKELY(!xpath)) return -1; sio = open_sio( io, HAWK_NULL, xpath, diff --git a/hawk/lib/hawk.h b/hawk/lib/hawk.h index 40ae059a..03a9fc37 100644 --- a/hawk/lib/hawk.h +++ b/hawk/lib/hawk.h @@ -130,6 +130,7 @@ struct hawk_rtx_alt_t /* ------------------------------------------------------------------------ */ +/* garbage collection header */ typedef struct hawk_gch_t hawk_gch_t; struct hawk_gch_t { @@ -3609,6 +3610,10 @@ HAWK_EXPORT hawk_val_t* hawk_get_nil_val ( void ); +HAWK_EXPORT int hawk_get_val_type ( + hawk_val_t* val +); + #if defined(__cplusplus) } #endif diff --git a/hawk/lib/val-prv.h b/hawk/lib/val-prv.h index fd3371c5..d6b8eca2 100644 --- a/hawk/lib/val-prv.h +++ b/hawk/lib/val-prv.h @@ -142,11 +142,12 @@ struct hawk_val_rchunk_t #define HAWK_VTR_TO_QCHAR(p) ((hawk_ooch_t)((hawk_uintptr_t)(p) >> HAWK_VTR_NUM_TYPE_BITS_LO)) #define HAWK_VTR_TO_QBCHR(p) ((hawk_ooch_t)((hawk_uintptr_t)(p) >> HAWK_VTR_NUM_TYPE_BITS_LOHI)) -#define HAWK_RTX_GETVALTYPE(rtx,p) (HAWK_VTR_IS_QINT(p)? HAWK_VAL_INT: \ - HAWK_VTR_IS_QCHAR(p)? HAWK_VAL_CHAR: \ - HAWK_VTR_IS_QBCHR(p)? HAWK_VAL_BCHR: (p)->v_type) +#define HAWK_GET_VAL_TYPE(p) (HAWK_VTR_IS_QINT(p)? HAWK_VAL_INT: \ + HAWK_VTR_IS_QCHAR(p)? HAWK_VAL_CHAR: \ + HAWK_VTR_IS_QBCHR(p)? HAWK_VAL_BCHR: (p)->v_type) -#define HAWK_RTX_GETINTFROMVAL(rtx,p) ((HAWK_VTR_IS_QINT(p)? (hawk_int_t)HAWK_VTR_TO_QINT(p): ((hawk_val_int_t*)(p))->i_val)) +#define HAWK_RTX_GETVALTYPE(rtx, p) HAWK_GET_VAL_TYPE(p) +#define HAWK_RTX_GETINTFROMVAL(rtx, p) ((HAWK_VTR_IS_QINT(p)? (hawk_int_t)HAWK_VTR_TO_QINT(p): ((hawk_val_int_t*)(p))->i_val)) #define HAWK_RTX_GETCHARFROMVAL(rtx, p) (HAWK_VTR_TO_QCHAR(p)) #define HAWK_RTX_GETBCHRFROMVAL(rtx, p) (HAWK_VTR_TO_QBCHR(p)) diff --git a/hawk/lib/val.c b/hawk/lib/val.c index d74222fa..fdb56671 100644 --- a/hawk/lib/val.c +++ b/hawk/lib/val.c @@ -469,6 +469,11 @@ static HAWK_INLINE hawk_val_t* gc_calloc_val (hawk_rtx_t* rtx, hawk_oow_t size) /* --------------------------------------------------------------------- */ +int hawk_get_val_type (hawk_val_t* val) +{ + return HAWK_GET_VAL_TYPE(val); +} + hawk_val_t* hawk_get_nil_val (void) { return (hawk_val_t*)&hawk_nil;