aboutsummaryrefslogtreecommitdiff
path: root/ltable.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-01-31 11:09:53 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-01-31 11:09:53 -0300
commit46c3587a6feb28e1ee4a32aabe463b0ecb9e8f5e (patch)
tree7e1ae9b55536171511506532a04f4ebe6dc764b0 /ltable.c
parent69c7139ff88bf26e05d80bf19d0351e5c88d13a3 (diff)
downloadlua-46c3587a6feb28e1ee4a32aabe463b0ecb9e8f5e.tar.gz
lua-46c3587a6feb28e1ee4a32aabe463b0ecb9e8f5e.tar.bz2
lua-46c3587a6feb28e1ee4a32aabe463b0ecb9e8f5e.zip
Clearer distinction between types and tags
LUA_T* represents only types; tags (types + Variants) are represented by LUA_V* constants.
Diffstat (limited to 'ltable.c')
-rw-r--r--ltable.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/ltable.c b/ltable.c
index ebd45dda..d7eb69a2 100644
--- a/ltable.c
+++ b/ltable.c
@@ -88,8 +88,8 @@
88#define dummynode (&dummynode_) 88#define dummynode (&dummynode_)
89 89
90static const Node dummynode_ = { 90static const Node dummynode_ = {
91 {{NULL}, LUA_TEMPTY, /* value's value and type */ 91 {{NULL}, LUA_VEMPTY, /* value's value and type */
92 LUA_TNIL, 0, {NULL}} /* key type, next, and key value */ 92 LUA_VNIL, 0, {NULL}} /* key type, next, and key value */
93}; 93};
94 94
95 95
@@ -135,21 +135,21 @@ static int l_hashfloat (lua_Number n) {
135*/ 135*/
136static Node *mainposition (const Table *t, int ktt, const Value *kvl) { 136static Node *mainposition (const Table *t, int ktt, const Value *kvl) {
137 switch (withvariant(ktt)) { 137 switch (withvariant(ktt)) {
138 case LUA_TNUMINT: 138 case LUA_VNUMINT:
139 return hashint(t, ivalueraw(*kvl)); 139 return hashint(t, ivalueraw(*kvl));
140 case LUA_TNUMFLT: 140 case LUA_VNUMFLT:
141 return hashmod(t, l_hashfloat(fltvalueraw(*kvl))); 141 return hashmod(t, l_hashfloat(fltvalueraw(*kvl)));
142 case LUA_TSHRSTR: 142 case LUA_VSHRSTR:
143 return hashstr(t, tsvalueraw(*kvl)); 143 return hashstr(t, tsvalueraw(*kvl));
144 case LUA_TLNGSTR: 144 case LUA_VLNGSTR:
145 return hashpow2(t, luaS_hashlongstr(tsvalueraw(*kvl))); 145 return hashpow2(t, luaS_hashlongstr(tsvalueraw(*kvl)));
146 case LUA_TFALSE: 146 case LUA_VFALSE:
147 return hashboolean(t, 0); 147 return hashboolean(t, 0);
148 case LUA_TTRUE: 148 case LUA_VTRUE:
149 return hashboolean(t, 1); 149 return hashboolean(t, 1);
150 case LUA_TLIGHTUSERDATA: 150 case LUA_VLIGHTUSERDATA:
151 return hashpointer(t, pvalueraw(*kvl)); 151 return hashpointer(t, pvalueraw(*kvl));
152 case LUA_TLCF: 152 case LUA_VLCF:
153 return hashpointer(t, fvalueraw(*kvl)); 153 return hashpointer(t, fvalueraw(*kvl));
154 default: 154 default:
155 return hashpointer(t, gcvalueraw(*kvl)); 155 return hashpointer(t, gcvalueraw(*kvl));
@@ -177,17 +177,17 @@ static int equalkey (const TValue *k1, const Node *n2) {
177 if (rawtt(k1) != keytt(n2)) /* not the same variants? */ 177 if (rawtt(k1) != keytt(n2)) /* not the same variants? */
178 return 0; /* cannot be same key */ 178 return 0; /* cannot be same key */
179 switch (ttypetag(k1)) { 179 switch (ttypetag(k1)) {
180 case LUA_TNIL: case LUA_TFALSE: case LUA_TTRUE: 180 case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE:
181 return 1; 181 return 1;
182 case LUA_TNUMINT: 182 case LUA_VNUMINT:
183 return (ivalue(k1) == keyival(n2)); 183 return (ivalue(k1) == keyival(n2));
184 case LUA_TNUMFLT: 184 case LUA_VNUMFLT:
185 return luai_numeq(fltvalue(k1), fltvalueraw(keyval(n2))); 185 return luai_numeq(fltvalue(k1), fltvalueraw(keyval(n2)));
186 case LUA_TLIGHTUSERDATA: 186 case LUA_VLIGHTUSERDATA:
187 return pvalue(k1) == pvalueraw(keyval(n2)); 187 return pvalue(k1) == pvalueraw(keyval(n2));
188 case LUA_TLCF: 188 case LUA_VLCF:
189 return fvalue(k1) == fvalueraw(keyval(n2)); 189 return fvalue(k1) == fvalueraw(keyval(n2));
190 case LUA_TLNGSTR: 190 case LUA_VLNGSTR:
191 return luaS_eqlngstr(tsvalue(k1), keystrval(n2)); 191 return luaS_eqlngstr(tsvalue(k1), keystrval(n2));
192 default: 192 default:
193 return gcvalue(k1) == gcvalueraw(keyval(n2)); 193 return gcvalue(k1) == gcvalueraw(keyval(n2));
@@ -580,7 +580,7 @@ static void rehash (lua_State *L, Table *t, const TValue *ek) {
580 580
581 581
582Table *luaH_new (lua_State *L) { 582Table *luaH_new (lua_State *L) {
583 GCObject *o = luaC_newobj(L, LUA_TTABLE, sizeof(Table)); 583 GCObject *o = luaC_newobj(L, LUA_VTABLE, sizeof(Table));
584 Table *t = gco2t(o); 584 Table *t = gco2t(o);
585 t->metatable = NULL; 585 t->metatable = NULL;
586 t->flags = cast_byte(~0); 586 t->flags = cast_byte(~0);
@@ -710,7 +710,7 @@ const TValue *luaH_getint (Table *t, lua_Integer key) {
710*/ 710*/
711const TValue *luaH_getshortstr (Table *t, TString *key) { 711const TValue *luaH_getshortstr (Table *t, TString *key) {
712 Node *n = hashstr(t, key); 712 Node *n = hashstr(t, key);
713 lua_assert(key->tt == LUA_TSHRSTR); 713 lua_assert(key->tt == LUA_VSHRSTR);
714 for (;;) { /* check whether 'key' is somewhere in the chain */ 714 for (;;) { /* check whether 'key' is somewhere in the chain */
715 if (keyisshrstr(n) && eqshrstr(keystrval(n), key)) 715 if (keyisshrstr(n) && eqshrstr(keystrval(n), key))
716 return gval(n); /* that's it */ 716 return gval(n); /* that's it */
@@ -725,7 +725,7 @@ const TValue *luaH_getshortstr (Table *t, TString *key) {
725 725
726 726
727const TValue *luaH_getstr (Table *t, TString *key) { 727const TValue *luaH_getstr (Table *t, TString *key) {
728 if (key->tt == LUA_TSHRSTR) 728 if (key->tt == LUA_VSHRSTR)
729 return luaH_getshortstr(t, key); 729 return luaH_getshortstr(t, key);
730 else { /* for long strings, use generic case */ 730 else { /* for long strings, use generic case */
731 TValue ko; 731 TValue ko;
@@ -740,10 +740,10 @@ const TValue *luaH_getstr (Table *t, TString *key) {
740*/ 740*/
741const TValue *luaH_get (Table *t, const TValue *key) { 741const TValue *luaH_get (Table *t, const TValue *key) {
742 switch (ttypetag(key)) { 742 switch (ttypetag(key)) {
743 case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key)); 743 case LUA_VSHRSTR: return luaH_getshortstr(t, tsvalue(key));
744 case LUA_TNUMINT: return luaH_getint(t, ivalue(key)); 744 case LUA_VNUMINT: return luaH_getint(t, ivalue(key));
745 case LUA_TNIL: return &absentkey; 745 case LUA_VNIL: return &absentkey;
746 case LUA_TNUMFLT: { 746 case LUA_VNUMFLT: {
747 lua_Integer k; 747 lua_Integer k;
748 if (luaV_flttointeger(fltvalue(key), &k, F2Ieq)) /* integral index? */ 748 if (luaV_flttointeger(fltvalue(key), &k, F2Ieq)) /* integral index? */
749 return luaH_getint(t, k); /* use specialized version */ 749 return luaH_getint(t, k); /* use specialized version */