summaryrefslogtreecommitdiff
path: root/ltable.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-03-18 09:50:04 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-03-18 09:50:04 -0300
commitab9e062928f7b9201fd5366a34a4fc855d13bc46 (patch)
tree37224175e0dd89badfccc6d745bdb5c850fd34c4 /ltable.c
parent81cdbabf095e23bf9fb5cef842967acb499b7bcc (diff)
downloadlua-ab9e062928f7b9201fd5366a34a4fc855d13bc46.tar.gz
lua-ab9e062928f7b9201fd5366a34a4fc855d13bc46.tar.bz2
lua-ab9e062928f7b9201fd5366a34a4fc855d13bc46.zip
name changes to avoid name collision between macros and variables
Diffstat (limited to 'ltable.c')
-rw-r--r--ltable.c72
1 files changed, 36 insertions, 36 deletions
diff --git a/ltable.c b/ltable.c
index 28634cc5..50f33719 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.127 2003/02/13 16:08:32 roberto Exp roberto $ 2** $Id: ltable.c,v 1.128 2003/02/20 20:12:39 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*/
@@ -56,15 +56,15 @@
56 56
57 57
58#define hashnum(t,n) \ 58#define hashnum(t,n) \
59 (node(t, lmod(cast(lu_hash, cast(ls_hash, n)), sizenode(t)))) 59 (gnode(t, lmod(cast(lu_hash, cast(ls_hash, n)), sizenode(t))))
60#define hashstr(t,str) (node(t, lmod((str)->tsv.hash, sizenode(t)))) 60#define hashstr(t,str) (gnode(t, lmod((str)->tsv.hash, sizenode(t))))
61#define hashboolean(t,p) (node(t, lmod(p, sizenode(t)))) 61#define hashboolean(t,p) (gnode(t, lmod(p, sizenode(t))))
62 62
63/* 63/*
64** avoid modulus by power of 2 for pointers, as they tend to have many 64** avoid modulus by power of 2 for pointers, as they tend to have many
65** 2 factors. 65** 2 factors.
66*/ 66*/
67#define hashpointer(t,p) (node(t, (IntPoint(p) % ((sizenode(t)-1)|1)))) 67#define hashpointer(t,p) (gnode(t, (IntPoint(p) % ((sizenode(t)-1)|1))))
68 68
69 69
70/* 70/*
@@ -122,7 +122,7 @@ static int luaH_index (lua_State *L, Table *t, StkId key) {
122 if (v == &luaO_nilobject) 122 if (v == &luaO_nilobject)
123 luaG_runerror(L, "invalid key for `next'"); 123 luaG_runerror(L, "invalid key for `next'");
124 i = cast(int, (cast(const lu_byte *, v) - 124 i = cast(int, (cast(const lu_byte *, v) -
125 cast(const lu_byte *, val(node(t, 0)))) / sizeof(Node)); 125 cast(const lu_byte *, gval(gnode(t, 0)))) / sizeof(Node));
126 return i + t->sizearray; /* hash elements are numbered after array ones */ 126 return i + t->sizearray; /* hash elements are numbered after array ones */
127 } 127 }
128} 128}
@@ -138,9 +138,9 @@ int luaH_next (lua_State *L, Table *t, StkId key) {
138 } 138 }
139 } 139 }
140 for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */ 140 for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */
141 if (!ttisnil(val(node(t, i)))) { /* a non-nil value? */ 141 if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */
142 setobj2s(key, key(node(t, i))); 142 setobj2s(key, gkey(gnode(t, i)));
143 setobj2s(key+1, val(node(t, i))); 143 setobj2s(key+1, gval(gnode(t, i)));
144 return 1; 144 return 1;
145 } 145 }
146 } 146 }
@@ -201,8 +201,8 @@ static void numuse (const Table *t, int *narray, int *nhash) {
201 i = sizenode(t); 201 i = sizenode(t);
202 while (i--) { 202 while (i--) {
203 Node *n = &t->node[i]; 203 Node *n = &t->node[i];
204 if (!ttisnil(val(n))) { 204 if (!ttisnil(gval(n))) {
205 int k = arrayindex(key(n)); 205 int k = arrayindex(gkey(n));
206 if (k >= 0) { /* is `key' an appropriate array index? */ 206 if (k >= 0) { /* is `key' an appropriate array index? */
207 nums[luaO_log2(k-1)+1]++; /* count as such */ 207 nums[luaO_log2(k-1)+1]++; /* count as such */
208 (*narray)++; 208 (*narray)++;
@@ -230,20 +230,20 @@ static void setnodevector (lua_State *L, Table *t, int lsize) {
230 luaG_runerror(L, "table overflow"); 230 luaG_runerror(L, "table overflow");
231 if (lsize == 0) { /* no elements to hash part? */ 231 if (lsize == 0) { /* no elements to hash part? */
232 t->node = G(L)->dummynode; /* use common `dummynode' */ 232 t->node = G(L)->dummynode; /* use common `dummynode' */
233 lua_assert(ttisnil(key(t->node))); /* assert invariants: */ 233 lua_assert(ttisnil(gkey(t->node))); /* assert invariants: */
234 lua_assert(ttisnil(val(t->node))); 234 lua_assert(ttisnil(gval(t->node)));
235 lua_assert(t->node->next == NULL); /* (`dummynode' must be empty) */ 235 lua_assert(t->node->next == NULL); /* (`dummynode' must be empty) */
236 } 236 }
237 else { 237 else {
238 t->node = luaM_newvector(L, size, Node); 238 t->node = luaM_newvector(L, size, Node);
239 for (i=0; i<size; i++) { 239 for (i=0; i<size; i++) {
240 t->node[i].next = NULL; 240 t->node[i].next = NULL;
241 setnilvalue(key(node(t, i))); 241 setnilvalue(gkey(gnode(t, i)));
242 setnilvalue(val(node(t, i))); 242 setnilvalue(gval(gnode(t, i)));
243 } 243 }
244 } 244 }
245 t->lsizenode = cast(lu_byte, lsize); 245 t->lsizenode = cast(lu_byte, lsize);
246 t->firstfree = node(t, size-1); /* first free position to be used */ 246 t->firstfree = gnode(t, size-1); /* first free position to be used */
247} 247}
248 248
249 249
@@ -259,8 +259,8 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
259 lua_assert(t->node == G(L)->dummynode); 259 lua_assert(t->node == G(L)->dummynode);
260 temp[0] = t->node[0]; /* copy it to `temp' */ 260 temp[0] = t->node[0]; /* copy it to `temp' */
261 nold = temp; 261 nold = temp;
262 setnilvalue(key(G(L)->dummynode)); /* restate invariant */ 262 setnilvalue(gkey(G(L)->dummynode)); /* restate invariant */
263 setnilvalue(val(G(L)->dummynode)); 263 setnilvalue(gval(G(L)->dummynode));
264 lua_assert(G(L)->dummynode->next == NULL); 264 lua_assert(G(L)->dummynode->next == NULL);
265 } 265 }
266 if (nasize > oldasize) /* array part must grow? */ 266 if (nasize > oldasize) /* array part must grow? */
@@ -281,8 +281,8 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
281 /* re-insert elements in hash part */ 281 /* re-insert elements in hash part */
282 for (i = twoto(oldhsize) - 1; i >= 0; i--) { 282 for (i = twoto(oldhsize) - 1; i >= 0; i--) {
283 Node *old = nold+i; 283 Node *old = nold+i;
284 if (!ttisnil(val(old))) 284 if (!ttisnil(gval(old)))
285 setobjt2t(luaH_set(L, t, key(old)), val(old)); 285 setobjt2t(luaH_set(L, t, gkey(old)), gval(old));
286 } 286 }
287 if (oldhsize) 287 if (oldhsize)
288 luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ 288 luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */
@@ -332,7 +332,7 @@ void luaH_free (lua_State *L, Table *t) {
332** (because gc can call `remove' during a table traversal) 332** (because gc can call `remove' during a table traversal)
333*/ 333*/
334void luaH_remove (Table *t, Node *e) { 334void luaH_remove (Table *t, Node *e) {
335 Node *mp = luaH_mainposition(t, key(e)); 335 Node *mp = luaH_mainposition(t, gkey(e));
336 if (e != mp) { /* element not in its main position? */ 336 if (e != mp) { /* element not in its main position? */
337 while (mp->next != e) mp = mp->next; /* find previous */ 337 while (mp->next != e) mp = mp->next; /* find previous */
338 mp->next = e->next; /* remove `e' from its list */ 338 mp->next = e->next; /* remove `e' from its list */
@@ -340,8 +340,8 @@ void luaH_remove (Table *t, Node *e) {
340 else { 340 else {
341 if (e->next != NULL) ?? 341 if (e->next != NULL) ??
342 } 342 }
343 lua_assert(ttisnil(val(node))); 343 lua_assert(ttisnil(gval(node)));
344 setnilvalue(key(e)); /* clear node `e' */ 344 setnilvalue(gkey(e)); /* clear node `e' */
345 e->next = NULL; 345 e->next = NULL;
346} 346}
347#endif 347#endif
@@ -357,8 +357,8 @@ void luaH_remove (Table *t, Node *e) {
357static TObject *newkey (lua_State *L, Table *t, const TObject *key) { 357static TObject *newkey (lua_State *L, Table *t, const TObject *key) {
358 TObject *val; 358 TObject *val;
359 Node *mp = luaH_mainposition(t, key); 359 Node *mp = luaH_mainposition(t, key);
360 if (!ttisnil(val(mp))) { /* main position is not free? */ 360 if (!ttisnil(gval(mp))) { /* main position is not free? */
361 Node *othern = luaH_mainposition(t, key(mp)); /* `mp' of colliding node */ 361 Node *othern = luaH_mainposition(t, gkey(mp)); /* `mp' of colliding node */
362 Node *n = t->firstfree; /* get a free place */ 362 Node *n = t->firstfree; /* get a free place */
363 if (othern != mp) { /* is colliding node out of its main position? */ 363 if (othern != mp) { /* is colliding node out of its main position? */
364 /* yes; move colliding node into free position */ 364 /* yes; move colliding node into free position */
@@ -366,7 +366,7 @@ static TObject *newkey (lua_State *L, Table *t, const TObject *key) {
366 othern->next = n; /* redo the chain with `n' in place of `mp' */ 366 othern->next = n; /* redo the chain with `n' in place of `mp' */
367 *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */ 367 *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */
368 mp->next = NULL; /* now `mp' is free */ 368 mp->next = NULL; /* now `mp' is free */
369 setnilvalue(val(mp)); 369 setnilvalue(gval(mp));
370 } 370 }
371 else { /* colliding node is in its own main position */ 371 else { /* colliding node is in its own main position */
372 /* new node will go into free position */ 372 /* new node will go into free position */
@@ -375,16 +375,16 @@ static TObject *newkey (lua_State *L, Table *t, const TObject *key) {
375 mp = n; 375 mp = n;
376 } 376 }
377 } 377 }
378 setobj2t(key(mp), key); /* write barrier */ 378 setobj2t(gkey(mp), key); /* write barrier */
379 lua_assert(ttisnil(val(mp))); 379 lua_assert(ttisnil(gval(mp)));
380 for (;;) { /* correct `firstfree' */ 380 for (;;) { /* correct `firstfree' */
381 if (ttisnil(key(t->firstfree))) 381 if (ttisnil(gkey(t->firstfree)))
382 return val(mp); /* OK; table still has a free place */ 382 return gval(mp); /* OK; table still has a free place */
383 else if (t->firstfree == t->node) break; /* cannot decrement from here */ 383 else if (t->firstfree == t->node) break; /* cannot decrement from here */
384 else (t->firstfree)--; 384 else (t->firstfree)--;
385 } 385 }
386 /* no more free places; must create one */ 386 /* no more free places; must create one */
387 setbvalue(val(mp), 0); /* avoid new key being removed */ 387 setbvalue(gval(mp), 0); /* avoid new key being removed */
388 rehash(L, t); /* grow table */ 388 rehash(L, t); /* grow table */
389 val = cast(TObject *, luaH_get(t, key)); /* get new position */ 389 val = cast(TObject *, luaH_get(t, key)); /* get new position */
390 lua_assert(ttisboolean(val)); 390 lua_assert(ttisboolean(val));
@@ -401,7 +401,7 @@ static const TObject *luaH_getany (Table *t, const TObject *key) {
401 else { 401 else {
402 Node *n = luaH_mainposition(t, key); 402 Node *n = luaH_mainposition(t, key);
403 do { /* check whether `key' is somewhere in the chain */ 403 do { /* check whether `key' is somewhere in the chain */
404 if (luaO_rawequalObj(key(n), key)) return val(n); /* that's it */ 404 if (luaO_rawequalObj(gkey(n), key)) return gval(n); /* that's it */
405 else n = n->next; 405 else n = n->next;
406 } while (n); 406 } while (n);
407 return &luaO_nilobject; 407 return &luaO_nilobject;
@@ -418,8 +418,8 @@ const TObject *luaH_getnum (Table *t, int key) {
418 else { 418 else {
419 Node *n = hashnum(t, key); 419 Node *n = hashnum(t, key);
420 do { /* check whether `key' is somewhere in the chain */ 420 do { /* check whether `key' is somewhere in the chain */
421 if (ttisnumber(key(n)) && nvalue(key(n)) == (lua_Number)key) 421 if (ttisnumber(gkey(n)) && nvalue(gkey(n)) == (lua_Number)key)
422 return val(n); /* that's it */ 422 return gval(n); /* that's it */
423 else n = n->next; 423 else n = n->next;
424 } while (n); 424 } while (n);
425 return &luaO_nilobject; 425 return &luaO_nilobject;
@@ -433,8 +433,8 @@ const TObject *luaH_getnum (Table *t, int key) {
433const TObject *luaH_getstr (Table *t, TString *key) { 433const TObject *luaH_getstr (Table *t, TString *key) {
434 Node *n = hashstr(t, key); 434 Node *n = hashstr(t, key);
435 do { /* check whether `key' is somewhere in the chain */ 435 do { /* check whether `key' is somewhere in the chain */
436 if (ttisstring(key(n)) && tsvalue(key(n)) == key) 436 if (ttisstring(gkey(n)) && tsvalue(gkey(n)) == key)
437 return val(n); /* that's it */ 437 return gval(n); /* that's it */
438 else n = n->next; 438 else n = n->next;
439 } while (n); 439 } while (n);
440 return &luaO_nilobject; 440 return &luaO_nilobject;