From ef8263f81fdde2310ebb15c9a3fe5e954d57cab5 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 26 Feb 2018 11:16:05 -0300 Subject: [PATCH] better names for macros for tags and types. rttype -> rawtt; ttyperaw -> withvariant; ttype -> ttypetag; tnov -> ttype --- lapi.c | 32 ++++++++++++++++---------------- lcode.c | 4 ++-- ldo.c | 4 ++-- ldump.c | 6 +++--- lobject.h | 22 +++++++++++----------- ltable.c | 12 ++++++------ ltm.c | 8 ++++---- lvm.c | 10 +++++----- 8 files changed, 49 insertions(+), 49 deletions(-) diff --git a/lapi.c b/lapi.c index b6c52721..92e98def 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.286 2018/02/23 13:13:31 roberto Exp roberto $ +** $Id: lapi.c,v 2.287 2018/02/25 12:48:16 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -257,7 +257,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) { LUA_API int lua_type (lua_State *L, int idx) { const TValue *o = index2value(L, idx); - return (isvalid(o) ? ttnov(o) : LUA_TNONE); + return (isvalid(o) ? ttype(o) : LUA_TNONE); } @@ -399,7 +399,7 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) { const TValue *o = index2value(L, idx); - switch (ttype(o)) { + switch (ttypetag(o)) { case LUA_TSHRSTR: return tsvalue(o)->shrlen; case LUA_TLNGSTR: return tsvalue(o)->u.lnglen; case LUA_TUSERDATA: return uvalue(o)->len; @@ -420,7 +420,7 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { LUA_API void *lua_touserdata (lua_State *L, int idx) { const TValue *o = index2value(L, idx); - switch (ttnov(o)) { + switch (ttype(o)) { case LUA_TUSERDATA: return getudatamem(uvalue(o)); case LUA_TLIGHTUSERDATA: return pvalue(o); default: return NULL; @@ -436,7 +436,7 @@ LUA_API lua_State *lua_tothread (lua_State *L, int idx) { LUA_API const void *lua_topointer (lua_State *L, int idx) { const TValue *o = index2value(L, idx); - switch (ttype(o)) { + switch (ttypetag(o)) { case LUA_TTABLE: return hvalue(o); case LUA_TLCL: return clLvalue(o); case LUA_TCCL: return clCvalue(o); @@ -606,7 +606,7 @@ static int auxgetstr (lua_State *L, const TValue *t, const char *k) { luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot); } lua_unlock(L); - return ttnov(s2v(L->top - 1)); + return ttype(s2v(L->top - 1)); } @@ -628,7 +628,7 @@ LUA_API int lua_gettable (lua_State *L, int idx) { else luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot); lua_unlock(L); - return ttnov(s2v(L->top - 1)); + return ttype(s2v(L->top - 1)); } @@ -653,7 +653,7 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { } api_incr_top(L); lua_unlock(L); - return ttnov(s2v(L->top - 1)); + return ttype(s2v(L->top - 1)); } @@ -664,7 +664,7 @@ static int finishrawget (lua_State *L, const TValue *val) { setobj2s(L, L->top, val); api_incr_top(L); lua_unlock(L); - return ttnov(s2v(L->top - 1)); + return ttype(s2v(L->top - 1)); } @@ -749,7 +749,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { int res = 0; lua_lock(L); obj = index2value(L, objindex); - switch (ttnov(obj)) { + switch (ttype(obj)) { case LUA_TTABLE: mt = hvalue(obj)->metatable; break; @@ -757,7 +757,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { mt = uvalue(obj)->metatable; break; default: - mt = G(L)->mt[ttnov(obj)]; + mt = G(L)->mt[ttype(obj)]; break; } if (mt != NULL) { @@ -782,7 +782,7 @@ LUA_API int lua_getiuservalue (lua_State *L, int idx, int n) { } else { setobj2s(L, L->top, &uvalue(o)->uv[n - 1].uv); - t = ttnov(s2v(L->top)); + t = ttype(s2v(L->top)); } api_incr_top(L); lua_unlock(L); @@ -917,7 +917,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { api_check(L, ttistable(s2v(L->top - 1)), "table expected"); mt = hvalue(s2v(L->top - 1)); } - switch (ttnov(obj)) { + switch (ttype(obj)) { case LUA_TTABLE: { hvalue(obj)->metatable = mt; if (mt) { @@ -935,7 +935,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { break; } default: { - G(L)->mt[ttnov(obj)] = mt; + G(L)->mt[ttype(obj)] = mt; break; } } @@ -1295,7 +1295,7 @@ LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) { static const char *aux_upvalue (TValue *fi, int n, TValue **val, GCObject **owner) { - switch (ttype(fi)) { + switch (ttypetag(fi)) { case LUA_TCCL: { /* C closure */ CClosure *f = clCvalue(fi); if (!(1 <= n && n <= f->nupvalues)) return NULL; @@ -1364,7 +1364,7 @@ static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) { TValue *fi = index2value(L, fidx); - switch (ttype(fi)) { + switch (ttypetag(fi)) { case LUA_TLCL: { /* lua closure */ return *getupvalref(L, fidx, n, NULL); } diff --git a/lcode.c b/lcode.c index 30bf13d8..8f3c68c0 100644 --- a/lcode.c +++ b/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.156 2018/02/21 12:54:26 roberto Exp roberto $ +** $Id: lcode.c,v 2.157 2018/02/21 15:49:32 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -504,7 +504,7 @@ static int addk (FuncState *fs, TValue *key, TValue *v) { if (ttisinteger(idx)) { /* is there an index there? */ k = cast_int(ivalue(idx)); /* correct value? (warning: must distinguish floats from integers!) */ - if (k < fs->nk && ttype(&f->k[k]) == ttype(v) && + if (k < fs->nk && ttypetag(&f->k[k]) == ttypetag(v) && luaV_rawequalobj(&f->k[k], v)) return k; /* reuse index */ } diff --git a/ldo.c b/ldo.c index 6acd2f64..7489a962 100644 --- a/ldo.c +++ b/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 2.194 2018/02/15 15:34:29 roberto Exp roberto $ +** $Id: ldo.c,v 2.196 2018/02/17 19:29:29 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -453,7 +453,7 @@ void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) { void luaD_call (lua_State *L, StkId func, int nresults) { lua_CFunction f; TValue *funcv = s2v(func); - switch (ttype(funcv)) { + switch (ttypetag(funcv)) { case LUA_TCCL: /* C closure */ f = clCvalue(funcv)->f; goto Cfunc; diff --git a/ldump.c b/ldump.c index 4d3f6435..0724aeb5 100644 --- a/ldump.c +++ b/ldump.c @@ -1,5 +1,5 @@ /* -** $Id: ldump.c,v 2.39 2017/06/27 14:21:12 roberto Exp roberto $ +** $Id: ldump.c,v 2.40 2017/11/28 11:19:07 roberto Exp roberto $ ** save precompiled Lua chunks ** See Copyright Notice in lua.h */ @@ -111,8 +111,8 @@ static void DumpConstants (const Proto *f, DumpState *D) { DumpInt(n, D); for (i = 0; i < n; i++) { const TValue *o = &f->k[i]; - DumpByte(ttype(o), D); - switch (ttype(o)) { + DumpByte(ttypetag(o), D); + switch (ttypetag(o)) { case LUA_TNIL: break; case LUA_TBOOLEAN: diff --git a/lobject.h b/lobject.h index 6d34759f..b18dce47 100644 --- a/lobject.h +++ b/lobject.h @@ -1,5 +1,5 @@ /* -** $Id: lobject.h,v 2.139 2018/02/25 12:52:32 roberto Exp roberto $ +** $Id: lobject.h,v 2.140 2018/02/26 13:35:03 roberto Exp roberto $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ @@ -67,26 +67,26 @@ typedef struct TValue { /* raw type tag of a TValue */ -#define rttype(o) ((o)->tt_) +#define rawtt(o) ((o)->tt_) /* tag with no variants (bits 0-3) */ #define novariant(t) ((t) & 0x0F) /* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */ -#define ttyperaw(t) ((t) & 0x3F) -#define ttype(o) ttyperaw(rttype(o)) +#define withvariant(t) ((t) & 0x3F) +#define ttypetag(o) withvariant(rawtt(o)) -/* type tag of a TValue with no variants (bits 0-3) */ -#define ttnov(o) (novariant(rttype(o))) +/* type of a TValue */ +#define ttype(o) (novariant(rawtt(o))) /* Macros to test type */ -#define checktag(o,t) (rttype(o) == (t)) -#define checktype(o,t) (ttnov(o) == (t)) +#define checktag(o,t) (rawtt(o) == (t)) +#define checktype(o,t) (ttype(o) == (t)) /* Macros for internal tests */ -#define righttt(obj) (ttype(obj) == gcvalue(obj)->tt) +#define righttt(obj) (ttypetag(obj) == gcvalue(obj)->tt) #define checkliveness(L,obj) \ lua_longassert(!iscollectable(obj) || \ @@ -244,7 +244,7 @@ typedef struct GCObject { /* Bit mark for collectable types */ #define BIT_ISCOLLECTABLE (1 << 6) -#define iscollectable(o) (rttype(o) & BIT_ISCOLLECTABLE) +#define iscollectable(o) (rawtt(o) & BIT_ISCOLLECTABLE) /* mark a tag as collectable */ #define ctb(t) ((t) | BIT_ISCOLLECTABLE) @@ -535,7 +535,7 @@ typedef struct Proto { #define LUA_TCCL (LUA_TFUNCTION | (3 << 4)) /* C closure */ #define ttisfunction(o) checktype(o, LUA_TFUNCTION) -#define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TLCL) +#define ttisclosure(o) ((rawtt(o) & 0x1F) == LUA_TLCL) #define ttisLclosure(o) checktag((o), ctb(LUA_TLCL)) #define ttislcf(o) checktag((o), LUA_TLCF) #define ttisCclosure(o) checktag((o), ctb(LUA_TCCL)) diff --git a/ltable.c b/ltable.c index c71d627a..be8f67f0 100644 --- a/ltable.c +++ b/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 2.133 2018/02/21 12:54:26 roberto Exp roberto $ +** $Id: ltable.c,v 2.134 2018/02/23 13:13:31 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -133,7 +133,7 @@ static int l_hashfloat (lua_Number n) { ** nodes. */ static Node *mainposition (const Table *t, int ktt, const Value *kvl) { - switch (ttyperaw(ktt)) { + switch (withvariant(ktt)) { case LUA_TNUMINT: return hashint(t, ivalueraw(*kvl)); case LUA_TNUMFLT: @@ -155,7 +155,7 @@ static Node *mainposition (const Table *t, int ktt, const Value *kvl) { static Node *mainpositionTV (const Table *t, const TValue *key) { - return mainposition(t, rttype(key), valraw(key)); + return mainposition(t, rawtt(key), valraw(key)); } @@ -168,9 +168,9 @@ static Node *mainpositionTV (const Table *t, const TValue *key) { ** default case. */ static int equalkey (const TValue *k1, const Node *n2) { - if (rttype(k1) != keytt(n2)) /* not the same variants? */ + if (rawtt(k1) != keytt(n2)) /* not the same variants? */ return 0; /* cannot be same key */ - switch (ttype(k1)) { + switch (ttypetag(k1)) { case LUA_TNIL: return 1; case LUA_TNUMINT: @@ -667,7 +667,7 @@ const TValue *luaH_getstr (Table *t, TString *key) { ** main search function */ const TValue *luaH_get (Table *t, const TValue *key) { - switch (ttype(key)) { + switch (ttypetag(key)) { case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key)); case LUA_TNUMINT: return luaH_getint(t, ivalue(key)); case LUA_TNIL: return luaH_emptyobject; diff --git a/ltm.c b/ltm.c index 0187c6f5..c06c8296 100644 --- a/ltm.c +++ b/ltm.c @@ -1,5 +1,5 @@ /* -** $Id: ltm.c,v 2.63 2018/02/21 15:49:32 roberto Exp roberto $ +** $Id: ltm.c,v 2.64 2018/02/23 13:13:31 roberto Exp roberto $ ** Tag methods ** See Copyright Notice in lua.h */ @@ -70,7 +70,7 @@ const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) { Table *mt; - switch (ttnov(o)) { + switch (ttype(o)) { case LUA_TTABLE: mt = hvalue(o)->metatable; break; @@ -78,7 +78,7 @@ const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) { mt = uvalue(o)->metatable; break; default: - mt = G(L)->mt[ttnov(o)]; + mt = G(L)->mt[ttype(o)]; } return (mt ? luaH_getshortstr(mt, G(L)->tmname[event]) : luaO_nilobject); } @@ -96,7 +96,7 @@ const char *luaT_objtypename (lua_State *L, const TValue *o) { if (ttisstring(name)) /* is '__name' a string? */ return getstr(tsvalue(name)); /* use it as type name */ } - return ttypename(ttnov(o)); /* else use standard type name */ + return ttypename(ttype(o)); /* else use standard type name */ } diff --git a/lvm.c b/lvm.c index 99e0d6b7..cd54369e 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.346 2018/02/21 19:43:44 roberto Exp roberto $ +** $Id: lvm.c,v 2.347 2018/02/23 13:13:31 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -458,8 +458,8 @@ int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { */ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { const TValue *tm; - if (ttype(t1) != ttype(t2)) { /* not the same variant? */ - if (ttnov(t1) != ttnov(t2) || ttnov(t1) != LUA_TNUMBER) + if (ttypetag(t1) != ttypetag(t2)) { /* not the same variant? */ + if (ttype(t1) != ttype(t2) || ttype(t1) != LUA_TNUMBER) return 0; /* only numbers can be equal with different variants */ else { /* two numbers with different variants */ lua_Integer i1, i2; /* compare them as integers */ @@ -467,7 +467,7 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { } } /* values have same type and same variant */ - switch (ttype(t1)) { + switch (ttypetag(t1)) { case LUA_TNIL: return 1; case LUA_TNUMINT: return (ivalue(t1) == ivalue(t2)); case LUA_TNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2)); @@ -569,7 +569,7 @@ void luaV_concat (lua_State *L, int total) { */ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { const TValue *tm; - switch (ttype(rb)) { + switch (ttypetag(rb)) { case LUA_TTABLE: { Table *h = hvalue(rb); tm = fasttm(L, h->metatable, TM_LEN);