better names for macros for tags and types. · lua/lua@ef8263f · GitHub
Skip to content

Commit ef8263f

Browse files
committed
better names for macros for tags and types.
rttype -> rawtt; ttyperaw -> withvariant; ttype -> ttypetag; tnov -> ttype
1 parent 2952bc5 commit ef8263f

8 files changed

Lines changed: 49 additions & 49 deletions

File tree

‎lapi.c‎

Lines changed: 16 additions & 16 deletions

‎lcode.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lcode.c,v 2.156 2018/02/21 12:54:26 roberto Exp roberto $
2+
** $Id: lcode.c,v 2.157 2018/02/21 15:49:32 roberto Exp roberto $
33
** Code generator for Lua
44
** See Copyright Notice in lua.h
55
*/
@@ -504,7 +504,7 @@ static int addk (FuncState *fs, TValue *key, TValue *v) {
504504
if (ttisinteger(idx)) { /* is there an index there? */
505505
k = cast_int(ivalue(idx));
506506
/* correct value? (warning: must distinguish floats from integers!) */
507-
if (k < fs->nk && ttype(&f->k[k]) == ttype(v) &&
507+
if (k < fs->nk && ttypetag(&f->k[k]) == ttypetag(v) &&
508508
luaV_rawequalobj(&f->k[k], v))
509509
return k; /* reuse index */
510510
}

‎ldo.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: ldo.c,v 2.194 2018/02/15 15:34:29 roberto Exp roberto $
2+
** $Id: ldo.c,v 2.196 2018/02/17 19:29:29 roberto Exp roberto $
33
** Stack and Call structure of Lua
44
** See Copyright Notice in lua.h
55
*/
@@ -453,7 +453,7 @@ void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) {
453453
void luaD_call (lua_State *L, StkId func, int nresults) {
454454
lua_CFunction f;
455455
TValue *funcv = s2v(func);
456-
switch (ttype(funcv)) {
456+
switch (ttypetag(funcv)) {
457457
case LUA_TCCL: /* C closure */
458458
f = clCvalue(funcv)->f;
459459
goto Cfunc;

‎ldump.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: ldump.c,v 2.39 2017/06/27 14:21:12 roberto Exp roberto $
2+
** $Id: ldump.c,v 2.40 2017/11/28 11:19:07 roberto Exp roberto $
33
** save precompiled Lua chunks
44
** See Copyright Notice in lua.h
55
*/
@@ -111,8 +111,8 @@ static void DumpConstants (const Proto *f, DumpState *D) {
111111
DumpInt(n, D);
112112
for (i = 0; i < n; i++) {
113113
const TValue *o = &f->k[i];
114-
DumpByte(ttype(o), D);
115-
switch (ttype(o)) {
114+
DumpByte(ttypetag(o), D);
115+
switch (ttypetag(o)) {
116116
case LUA_TNIL:
117117
break;
118118
case LUA_TBOOLEAN:

‎lobject.h‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lobject.h,v 2.139 2018/02/25 12:52:32 roberto Exp roberto $
2+
** $Id: lobject.h,v 2.140 2018/02/26 13:35:03 roberto Exp roberto $
33
** Type definitions for Lua objects
44
** See Copyright Notice in lua.h
55
*/
@@ -67,26 +67,26 @@ typedef struct TValue {
6767

6868

6969
/* raw type tag of a TValue */
70-
#define rttype(o) ((o)->tt_)
70+
#define rawtt(o) ((o)->tt_)
7171

7272
/* tag with no variants (bits 0-3) */
7373
#define novariant(t) ((t) & 0x0F)
7474

7575
/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */
76-
#define ttyperaw(t) ((t) & 0x3F)
77-
#define ttype(o) ttyperaw(rttype(o))
76+
#define withvariant(t) ((t) & 0x3F)
77+
#define ttypetag(o) withvariant(rawtt(o))
7878

79-
/* type tag of a TValue with no variants (bits 0-3) */
80-
#define ttnov(o) (novariant(rttype(o)))
79+
/* type of a TValue */
80+
#define ttype(o) (novariant(rawtt(o)))
8181

8282

8383
/* Macros to test type */
84-
#define checktag(o,t) (rttype(o) == (t))
85-
#define checktype(o,t) (ttnov(o) == (t))
84+
#define checktag(o,t) (rawtt(o) == (t))
85+
#define checktype(o,t) (ttype(o) == (t))
8686

8787

8888
/* Macros for internal tests */
89-
#define righttt(obj) (ttype(obj) == gcvalue(obj)->tt)
89+
#define righttt(obj) (ttypetag(obj) == gcvalue(obj)->tt)
9090

9191
#define checkliveness(L,obj) \
9292
lua_longassert(!iscollectable(obj) || \
@@ -244,7 +244,7 @@ typedef struct GCObject {
244244
/* Bit mark for collectable types */
245245
#define BIT_ISCOLLECTABLE (1 << 6)
246246

247-
#define iscollectable(o) (rttype(o) & BIT_ISCOLLECTABLE)
247+
#define iscollectable(o) (rawtt(o) & BIT_ISCOLLECTABLE)
248248

249249
/* mark a tag as collectable */
250250
#define ctb(t) ((t) | BIT_ISCOLLECTABLE)
@@ -535,7 +535,7 @@ typedef struct Proto {
535535
#define LUA_TCCL (LUA_TFUNCTION | (3 << 4)) /* C closure */
536536

537537
#define ttisfunction(o) checktype(o, LUA_TFUNCTION)
538-
#define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TLCL)
538+
#define ttisclosure(o) ((rawtt(o) & 0x1F) == LUA_TLCL)
539539
#define ttisLclosure(o) checktag((o), ctb(LUA_TLCL))
540540
#define ttislcf(o) checktag((o), LUA_TLCF)
541541
#define ttisCclosure(o) checktag((o), ctb(LUA_TCCL))

‎ltable.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: ltable.c,v 2.133 2018/02/21 12:54:26 roberto Exp roberto $
2+
** $Id: ltable.c,v 2.134 2018/02/23 13:13:31 roberto Exp roberto $
33
** Lua tables (hash)
44
** See Copyright Notice in lua.h
55
*/
@@ -133,7 +133,7 @@ static int l_hashfloat (lua_Number n) {
133133
** nodes.
134134
*/
135135
static Node *mainposition (const Table *t, int ktt, const Value *kvl) {
136-
switch (ttyperaw(ktt)) {
136+
switch (withvariant(ktt)) {
137137
case LUA_TNUMINT:
138138
return hashint(t, ivalueraw(*kvl));
139139
case LUA_TNUMFLT:
@@ -155,7 +155,7 @@ static Node *mainposition (const Table *t, int ktt, const Value *kvl) {
155155

156156

157157
static Node *mainpositionTV (const Table *t, const TValue *key) {
158-
return mainposition(t, rttype(key), valraw(key));
158+
return mainposition(t, rawtt(key), valraw(key));
159159
}
160160

161161

@@ -168,9 +168,9 @@ static Node *mainpositionTV (const Table *t, const TValue *key) {
168168
** default case.
169169
*/
170170
static int equalkey (const TValue *k1, const Node *n2) {
171-
if (rttype(k1) != keytt(n2)) /* not the same variants? */
171+
if (rawtt(k1) != keytt(n2)) /* not the same variants? */
172172
return 0; /* cannot be same key */
173-
switch (ttype(k1)) {
173+
switch (ttypetag(k1)) {
174174
case LUA_TNIL:
175175
return 1;
176176
case LUA_TNUMINT:
@@ -667,7 +667,7 @@ const TValue *luaH_getstr (Table *t, TString *key) {
667667
** main search function
668668
*/
669669
const TValue *luaH_get (Table *t, const TValue *key) {
670-
switch (ttype(key)) {
670+
switch (ttypetag(key)) {
671671
case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key));
672672
case LUA_TNUMINT: return luaH_getint(t, ivalue(key));
673673
case LUA_TNIL: return luaH_emptyobject;

‎ltm.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: ltm.c,v 2.63 2018/02/21 15:49:32 roberto Exp roberto $
2+
** $Id: ltm.c,v 2.64 2018/02/23 13:13:31 roberto Exp roberto $
33
** Tag methods
44
** See Copyright Notice in lua.h
55
*/
@@ -70,15 +70,15 @@ const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
7070

7171
const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
7272
Table *mt;
73-
switch (ttnov(o)) {
73+
switch (ttype(o)) {
7474
case LUA_TTABLE:
7575
mt = hvalue(o)->metatable;
7676
break;
7777
case LUA_TUSERDATA:
7878
mt = uvalue(o)->metatable;
7979
break;
8080
default:
81-
mt = G(L)->mt[ttnov(o)];
81+
mt = G(L)->mt[ttype(o)];
8282
}
8383
return (mt ? luaH_getshortstr(mt, G(L)->tmname[event]) : luaO_nilobject);
8484
}
@@ -96,7 +96,7 @@ const char *luaT_objtypename (lua_State *L, const TValue *o) {
9696
if (ttisstring(name)) /* is '__name' a string? */
9797
return getstr(tsvalue(name)); /* use it as type name */
9898
}
99-
return ttypename(ttnov(o)); /* else use standard type name */
99+
return ttypename(ttype(o)); /* else use standard type name */
100100
}
101101

102102

‎lvm.c‎

Lines changed: 5 additions & 5 deletions

0 commit comments

Comments
 (0)