aboutsummaryrefslogtreecommitdiff
path: root/ltable.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-05 09:14:08 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-05 09:14:08 -0300
commit001f2bdd0e2f8803889c1b5164b57a51e44aef5b (patch)
treed200cf4d708be3c61e64640c45b47050c9c6a375 /ltable.c
parentcd2ddaded97f7f2b2af02cecfd165cf70e6f83f4 (diff)
downloadlua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.tar.gz
lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.tar.bz2
lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.zip
new definition for types-tags
Diffstat (limited to 'ltable.c')
-rw-r--r--ltable.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/ltable.c b/ltable.c
index 7a732e53..0e0fe772 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.55 2000/09/11 20:29:27 roberto Exp roberto $ 2** $Id: ltable.c,v 1.56 2000/09/29 12:42:13 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -31,7 +31,7 @@
31 31
32 32
33 33
34#define TagDefault TAG_TABLE 34#define TagDefault LUA_TTABLE
35 35
36 36
37 37
@@ -42,19 +42,19 @@
42Node *luaH_mainposition (const Hash *t, const TObject *key) { 42Node *luaH_mainposition (const Hash *t, const TObject *key) {
43 unsigned long h; 43 unsigned long h;
44 switch (ttype(key)) { 44 switch (ttype(key)) {
45 case TAG_NUMBER: 45 case LUA_TNUMBER:
46 h = (unsigned long)(long)nvalue(key); 46 h = (unsigned long)(long)nvalue(key);
47 break; 47 break;
48 case TAG_STRING: 48 case LUA_TSTRING:
49 h = tsvalue(key)->u.s.hash; 49 h = tsvalue(key)->u.s.hash;
50 break; 50 break;
51 case TAG_USERDATA: 51 case LUA_TUSERDATA:
52 h = IntPoint(tsvalue(key)); 52 h = IntPoint(tsvalue(key));
53 break; 53 break;
54 case TAG_TABLE: 54 case LUA_TTABLE:
55 h = IntPoint(hvalue(key)); 55 h = IntPoint(hvalue(key));
56 break; 56 break;
57 case TAG_LCLOSURE: case TAG_CCLOSURE: 57 case LUA_TFUNCTION:
58 h = IntPoint(clvalue(key)); 58 h = IntPoint(clvalue(key));
59 break; 59 break;
60 default: 60 default:
@@ -84,7 +84,7 @@ static const TObject *luaH_getany (lua_State *L, const Hash *t,
84const TObject *luaH_getnum (const Hash *t, Number key) { 84const TObject *luaH_getnum (const Hash *t, Number key) {
85 Node *n = &t->node[(unsigned long)(long)key&(t->size-1)]; 85 Node *n = &t->node[(unsigned long)(long)key&(t->size-1)];
86 do { 86 do {
87 if (ttype(&n->key) == TAG_NUMBER && nvalue(&n->key) == key) 87 if (ttype(&n->key) == LUA_TNUMBER && nvalue(&n->key) == key)
88 return &n->val; 88 return &n->val;
89 n = n->next; 89 n = n->next;
90 } while (n); 90 } while (n);
@@ -96,7 +96,7 @@ const TObject *luaH_getnum (const Hash *t, Number key) {
96const TObject *luaH_getstr (const Hash *t, TString *key) { 96const TObject *luaH_getstr (const Hash *t, TString *key) {
97 Node *n = &t->node[key->u.s.hash&(t->size-1)]; 97 Node *n = &t->node[key->u.s.hash&(t->size-1)];
98 do { 98 do {
99 if (ttype(&n->key) == TAG_STRING && tsvalue(&n->key) == key) 99 if (ttype(&n->key) == LUA_TSTRING && tsvalue(&n->key) == key)
100 return &n->val; 100 return &n->val;
101 n = n->next; 101 n = n->next;
102 } while (n); 102 } while (n);
@@ -106,8 +106,8 @@ const TObject *luaH_getstr (const Hash *t, TString *key) {
106 106
107const TObject *luaH_get (lua_State *L, const Hash *t, const TObject *key) { 107const TObject *luaH_get (lua_State *L, const Hash *t, const TObject *key) {
108 switch (ttype(key)) { 108 switch (ttype(key)) {
109 case TAG_NUMBER: return luaH_getnum(t, nvalue(key)); 109 case LUA_TNUMBER: return luaH_getnum(t, nvalue(key));
110 case TAG_STRING: return luaH_getstr(t, tsvalue(key)); 110 case LUA_TSTRING: return luaH_getstr(t, tsvalue(key));
111 default: return luaH_getany(L, t, key); 111 default: return luaH_getany(L, t, key);
112 } 112 }
113} 113}
@@ -115,7 +115,7 @@ const TObject *luaH_get (lua_State *L, const Hash *t, const TObject *key) {
115 115
116Node *luaH_next (lua_State *L, const Hash *t, const TObject *key) { 116Node *luaH_next (lua_State *L, const Hash *t, const TObject *key) {
117 int i; 117 int i;
118 if (ttype(key) == TAG_NIL) 118 if (ttype(key) == LUA_TNIL)
119 i = 0; /* first iteration */ 119 i = 0; /* first iteration */
120 else { 120 else {
121 const TObject *v = luaH_get(L, t, key); 121 const TObject *v = luaH_get(L, t, key);
@@ -126,7 +126,7 @@ Node *luaH_next (lua_State *L, const Hash *t, const TObject *key) {
126 } 126 }
127 for (; i<t->size; i++) { 127 for (; i<t->size; i++) {
128 Node *n = node(t, i); 128 Node *n = node(t, i);
129 if (ttype(val(n)) != TAG_NIL) 129 if (ttype(val(n)) != LUA_TNIL)
130 return n; 130 return n;
131 } 131 }
132 return NULL; /* no more elements */ 132 return NULL; /* no more elements */
@@ -138,8 +138,8 @@ Node *luaH_next (lua_State *L, const Hash *t, const TObject *key) {
138** hash, change `key' for a number with the same hash. 138** hash, change `key' for a number with the same hash.
139*/ 139*/
140void luaH_remove (Hash *t, TObject *key) { 140void luaH_remove (Hash *t, TObject *key) {
141 if (ttype(key) == TAG_NUMBER || 141 if (ttype(key) == LUA_TNUMBER ||
142 (ttype(key) == TAG_STRING && tsvalue(key)->u.s.len <= 30)) 142 (ttype(key) == LUA_TSTRING && tsvalue(key)->u.s.len <= 30))
143 return; /* do not remove numbers nor small strings */ 143 return; /* do not remove numbers nor small strings */
144 else { 144 else {
145 /* try to find a number `n' with the same hash as `key' */ 145 /* try to find a number `n' with the same hash as `key' */
@@ -151,7 +151,7 @@ void luaH_remove (Hash *t, TObject *key) {
151 return; /* give up; (to avoid overflow) */ 151 return; /* give up; (to avoid overflow) */
152 n += t->size; 152 n += t->size;
153 } 153 }
154 ttype(key) = TAG_NUMBER; 154 ttype(key) = LUA_TNUMBER;
155 nvalue(key) = n; 155 nvalue(key) = n;
156 LUA_ASSERT(luaH_mainposition(t, key) == mp, "cannot change hash"); 156 LUA_ASSERT(luaH_mainposition(t, key) == mp, "cannot change hash");
157 } 157 }
@@ -164,7 +164,7 @@ static void setnodevector (lua_State *L, Hash *t, lint32 size) {
164 lua_error(L, "table overflow"); 164 lua_error(L, "table overflow");
165 t->node = luaM_newvector(L, size, Node); 165 t->node = luaM_newvector(L, size, Node);
166 for (i=0; i<(int)size; i++) { 166 for (i=0; i<(int)size; i++) {
167 ttype(&t->node[i].key) = ttype(&t->node[i].val) = TAG_NIL; 167 ttype(&t->node[i].key) = ttype(&t->node[i].val) = LUA_TNIL;
168 t->node[i].next = NULL; 168 t->node[i].next = NULL;
169 } 169 }
170 L->nblocks += gcsize(L, size) - gcsize(L, t->size); 170 L->nblocks += gcsize(L, size) - gcsize(L, t->size);
@@ -200,7 +200,7 @@ static int numuse (const Hash *t) {
200 int realuse = 0; 200 int realuse = 0;
201 int i; 201 int i;
202 for (i=0; i<size; i++) { 202 for (i=0; i<size; i++) {
203 if (ttype(&v[i].val) != TAG_NIL) 203 if (ttype(&v[i].val) != LUA_TNIL)
204 realuse++; 204 realuse++;
205 } 205 }
206 return realuse; 206 return realuse;
@@ -222,7 +222,7 @@ static void rehash (lua_State *L, Hash *t) {
222 setnodevector(L, t, oldsize); 222 setnodevector(L, t, oldsize);
223 for (i=0; i<oldsize; i++) { 223 for (i=0; i<oldsize; i++) {
224 Node *old = nold+i; 224 Node *old = nold+i;
225 if (ttype(&old->val) != TAG_NIL) 225 if (ttype(&old->val) != LUA_TNIL)
226 *luaH_set(L, t, &old->key) = old->val; 226 *luaH_set(L, t, &old->key) = old->val;
227 } 227 }
228 luaM_free(L, nold); /* free old array */ 228 luaM_free(L, nold); /* free old array */
@@ -248,7 +248,7 @@ TObject *luaH_set (lua_State *L, Hash *t, const TObject *key) {
248 else n = n->next; 248 else n = n->next;
249 } while (n); 249 } while (n);
250 /* `key' not found; must insert it */ 250 /* `key' not found; must insert it */
251 if (ttype(&mp->key) != TAG_NIL) { /* main position is not free? */ 251 if (ttype(&mp->key) != LUA_TNIL) { /* main position is not free? */
252 Node *othern; /* main position of colliding node */ 252 Node *othern; /* main position of colliding node */
253 n = t->firstfree; /* get a free place */ 253 n = t->firstfree; /* get a free place */
254 /* is colliding node out of its main position? (can only happens if 254 /* is colliding node out of its main position? (can only happens if
@@ -269,7 +269,7 @@ TObject *luaH_set (lua_State *L, Hash *t, const TObject *key) {
269 } 269 }
270 mp->key = *key; 270 mp->key = *key;
271 for (;;) { /* correct `firstfree' */ 271 for (;;) { /* correct `firstfree' */
272 if (ttype(&t->firstfree->key) == TAG_NIL) 272 if (ttype(&t->firstfree->key) == LUA_TNIL)
273 return &mp->val; /* OK; table still has a free place */ 273 return &mp->val; /* OK; table still has a free place */
274 else if (t->firstfree == t->node) break; /* cannot decrement from here */ 274 else if (t->firstfree == t->node) break; /* cannot decrement from here */
275 else (t->firstfree)--; 275 else (t->firstfree)--;
@@ -281,7 +281,7 @@ TObject *luaH_set (lua_State *L, Hash *t, const TObject *key) {
281 281
282TObject *luaH_setint (lua_State *L, Hash *t, int key) { 282TObject *luaH_setint (lua_State *L, Hash *t, int key) {
283 TObject index; 283 TObject index;
284 ttype(&index) = TAG_NUMBER; 284 ttype(&index) = LUA_TNUMBER;
285 nvalue(&index) = key; 285 nvalue(&index) = key;
286 return luaH_set(L, t, &index); 286 return luaH_set(L, t, &index);
287} 287}
@@ -289,10 +289,10 @@ TObject *luaH_setint (lua_State *L, Hash *t, int key) {
289 289
290void luaH_setstrnum (lua_State *L, Hash *t, TString *key, Number val) { 290void luaH_setstrnum (lua_State *L, Hash *t, TString *key, Number val) {
291 TObject *value, index; 291 TObject *value, index;
292 ttype(&index) = TAG_STRING; 292 ttype(&index) = LUA_TSTRING;
293 tsvalue(&index) = key; 293 tsvalue(&index) = key;
294 value = luaH_set(L, t, &index); 294 value = luaH_set(L, t, &index);
295 ttype(value) = TAG_NUMBER; 295 ttype(value) = LUA_TNUMBER;
296 nvalue(value) = val; 296 nvalue(value) = val;
297} 297}
298 298