aboutsummaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-02 18:29:09 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-02 18:29:09 -0200
commit0162decc58cca093a7deeec6651718a5d301468b (patch)
tree65656ec33befde71548383aa38d0df70009f2e17 /hash.c
parentac68a3abc483cf1b1473fd35e00cc4f887baab92 (diff)
downloadlua-0162decc58cca093a7deeec6651718a5d301468b.tar.gz
lua-0162decc58cca093a7deeec6651718a5d301468b.tar.bz2
lua-0162decc58cca093a7deeec6651718a5d301468b.zip
tags T_NIL, etc, changed to LUA_T_NIL, etc
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/hash.c b/hash.c
index 67d8f097..16c0b461 100644
--- a/hash.c
+++ b/hash.c
@@ -3,7 +3,7 @@
3** hash manager for lua 3** hash manager for lua
4*/ 4*/
5 5
6char *rcs_hash="$Id: hash.c,v 2.9 1994/10/17 19:03:23 celes Exp roberto $"; 6char *rcs_hash="$Id: hash.c,v 2.10 1994/11/01 17:54:31 roberto Exp roberto $";
7 7
8#include <string.h> 8#include <string.h>
9#include <stdlib.h> 9#include <stdlib.h>
@@ -54,9 +54,9 @@ static int hashindex (Hash *t, Object *ref) /* hash function */
54{ 54{
55 switch (tag(ref)) 55 switch (tag(ref))
56 { 56 {
57 case T_NUMBER: 57 case LUA_T_NUMBER:
58 return (((int)nvalue(ref))%nhash(t)); 58 return (((int)nvalue(ref))%nhash(t));
59 case T_STRING: 59 case LUA_T_STRING:
60 { 60 {
61 int h; 61 int h;
62 char *name = svalue(ref); 62 char *name = svalue(ref);
@@ -68,13 +68,13 @@ static int hashindex (Hash *t, Object *ref) /* hash function */
68 } 68 }
69 return h; 69 return h;
70 } 70 }
71 case T_FUNCTION: 71 case LUA_T_FUNCTION:
72 return (((int)bvalue(ref))%nhash(t)); 72 return (((int)bvalue(ref))%nhash(t));
73 case T_CFUNCTION: 73 case LUA_T_CFUNCTION:
74 return (((int)fvalue(ref))%nhash(t)); 74 return (((int)fvalue(ref))%nhash(t));
75 case T_ARRAY: 75 case LUA_T_ARRAY:
76 return (((int)avalue(ref))%nhash(t)); 76 return (((int)avalue(ref))%nhash(t));
77 case T_USERDATA: 77 case LUA_T_USERDATA:
78 return (((int)uvalue(ref))%nhash(t)); 78 return (((int)uvalue(ref))%nhash(t));
79 default: 79 default:
80 lua_reportbug ("unexpected type to index table"); 80 lua_reportbug ("unexpected type to index table");
@@ -87,8 +87,8 @@ static int equalObj (Object *t1, Object *t2)
87 if (tag(t1) != tag(t2)) return 0; 87 if (tag(t1) != tag(t2)) return 0;
88 switch (tag(t1)) 88 switch (tag(t1))
89 { 89 {
90 case T_NUMBER: return nvalue(t1) == nvalue(t2); 90 case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2);
91 case T_STRING: return streq(svalue(t1), svalue(t2)); 91 case LUA_T_STRING: return streq(svalue(t1), svalue(t2));
92 default: return uvalue(t1) == uvalue(t2); 92 default: return uvalue(t1) == uvalue(t2);
93 } 93 }
94} 94}
@@ -97,7 +97,7 @@ static int present (Hash *t, Object *ref)
97{ 97{
98 int h = hashindex(t, ref); 98 int h = hashindex(t, ref);
99 if (h < 0) return h; 99 if (h < 0) return h;
100 while (tag(ref(node(t, h))) != T_NIL) 100 while (tag(ref(node(t, h))) != LUA_T_NIL)
101 { 101 {
102 if (equalObj(ref, ref(node(t, h)))) 102 if (equalObj(ref, ref(node(t, h))))
103 return h; 103 return h;
@@ -120,7 +120,7 @@ static Node *hashnodecreate (int nhash)
120 return NULL; 120 return NULL;
121 } 121 }
122 for (i=0; i<nhash; i++) 122 for (i=0; i<nhash; i++)
123 tag(ref(&v[i])) = T_NIL; 123 tag(ref(&v[i])) = LUA_T_NIL;
124 return v; 124 return v;
125} 125}
126 126
@@ -169,7 +169,7 @@ void lua_hashmark (Hash *h)
169 for (i=0; i<nhash(h); i++) 169 for (i=0; i<nhash(h); i++)
170 { 170 {
171 Node *n = node(h,i); 171 Node *n = node(h,i);
172 if (tag(ref(n)) != T_NIL) 172 if (tag(ref(n)) != LUA_T_NIL)
173 { 173 {
174 lua_markobject(&n->ref); 174 lua_markobject(&n->ref);
175 lua_markobject(&n->val); 175 lua_markobject(&n->val);
@@ -243,7 +243,7 @@ static void rehash (Hash *t)
243 for (i=0; i<nold; i++) 243 for (i=0; i<nold; i++)
244 { 244 {
245 Node *n = vold+i; 245 Node *n = vold+i;
246 if (tag(ref(n)) != T_NIL && tag(val(n)) != T_NIL) 246 if (tag(ref(n)) != LUA_T_NIL && tag(val(n)) != LUA_T_NIL)
247 *node(t, present(t, ref(n))) = *n; /* copy old node to new hahs */ 247 *node(t, present(t, ref(n))) = *n; /* copy old node to new hahs */
248 } 248 }
249 free(vold); 249 free(vold);
@@ -257,10 +257,10 @@ static void rehash (Hash *t)
257Object *lua_hashget (Hash *t, Object *ref) 257Object *lua_hashget (Hash *t, Object *ref)
258{ 258{
259 static int count = 1000; 259 static int count = 1000;
260 static Object nil_obj = {T_NIL, {NULL}}; 260 static Object nil_obj = {LUA_T_NIL, {NULL}};
261 int h = present(t, ref); 261 int h = present(t, ref);
262 if (h < 0) return &nil_obj; 262 if (h < 0) return &nil_obj;
263 if (tag(ref(node(t, h))) != T_NIL) return val(node(t, h)); 263 if (tag(ref(node(t, h))) != LUA_T_NIL) return val(node(t, h));
264 if (--count == 0) 264 if (--count == 0)
265 { 265 {
266 lua_reportbug ("hierarchy too deep (maybe there is an inheritance loop)"); 266 lua_reportbug ("hierarchy too deep (maybe there is an inheritance loop)");
@@ -271,25 +271,25 @@ Object *lua_hashget (Hash *t, Object *ref)
271 Hash *p; 271 Hash *p;
272 Object parent; 272 Object parent;
273 Object godparent; 273 Object godparent;
274 tag(&parent) = T_STRING; svalue(&parent) = "parent"; 274 tag(&parent) = LUA_T_STRING; svalue(&parent) = "parent";
275 tag(&godparent) = T_STRING; svalue(&godparent) = "godparent"; 275 tag(&godparent) = LUA_T_STRING; svalue(&godparent) = "godparent";
276 276
277 h = present(t, &parent); /* assert(h >= 0); */ 277 h = present(t, &parent); /* assert(h >= 0); */
278 p = tag(ref(node(t, h))) != T_NIL && tag(val(node(t, h))) == T_ARRAY ? 278 p = tag(ref(node(t, h))) != LUA_T_NIL && tag(val(node(t, h))) == LUA_T_ARRAY ?
279 avalue(val(node(t, h))) : NULL; 279 avalue(val(node(t, h))) : NULL;
280 if (p != NULL) 280 if (p != NULL)
281 { 281 {
282 Object *r = lua_hashget(p, ref); 282 Object *r = lua_hashget(p, ref);
283 if (tag(r) != T_NIL) { count++; return r; } 283 if (tag(r) != LUA_T_NIL) { count++; return r; }
284 } 284 }
285 285
286 h = present(t, &godparent); /* assert(h >= 0); */ 286 h = present(t, &godparent); /* assert(h >= 0); */
287 p = tag(ref(node(t, h))) != T_NIL && tag(val(node(t, h))) == T_ARRAY ? 287 p = tag(ref(node(t, h))) != LUA_T_NIL && tag(val(node(t, h))) == LUA_T_ARRAY ?
288 avalue(val(node(t, h))) : NULL; 288 avalue(val(node(t, h))) : NULL;
289 if (p != NULL) 289 if (p != NULL)
290 { 290 {
291 Object *r = lua_hashget(p, ref); 291 Object *r = lua_hashget(p, ref);
292 if (tag(r) != T_NIL) { count++; return r; } 292 if (tag(r) != LUA_T_NIL) { count++; return r; }
293 } 293 }
294 } 294 }
295 count++; 295 count++;
@@ -308,7 +308,7 @@ Object *lua_hashdefine (Hash *t, Object *ref)
308 h = present(t, ref); 308 h = present(t, ref);
309 if (h < 0) return NULL; 309 if (h < 0) return NULL;
310 n = node(t, h); 310 n = node(t, h);
311 if (tag(ref(n)) == T_NIL) 311 if (tag(ref(n)) == LUA_T_NIL)
312 { 312 {
313 nuse(t)++; 313 nuse(t)++;
314 if ((float)nuse(t) > (float)nhash(t)*REHASH_LIMIT) 314 if ((float)nuse(t) > (float)nhash(t)*REHASH_LIMIT)
@@ -318,7 +318,7 @@ Object *lua_hashdefine (Hash *t, Object *ref)
318 n = node(t, h); 318 n = node(t, h);
319 } 319 }
320 *ref(n) = *ref; 320 *ref(n) = *ref;
321 tag(val(n)) = T_NIL; 321 tag(val(n)) = LUA_T_NIL;
322 } 322 }
323 return (val(n)); 323 return (val(n));
324} 324}
@@ -337,7 +337,7 @@ static void hashnext (Hash *t, int i)
337 lua_pushnil(); lua_pushnil(); 337 lua_pushnil(); lua_pushnil();
338 return; 338 return;
339 } 339 }
340 while (tag(ref(node(t,i))) == T_NIL || tag(val(node(t,i))) == T_NIL) 340 while (tag(ref(node(t,i))) == LUA_T_NIL || tag(val(node(t,i))) == LUA_T_NIL)
341 { 341 {
342 if (++i >= nhash(t)) 342 if (++i >= nhash(t))
343 { 343 {
@@ -358,11 +358,11 @@ void lua_next (void)
358 { lua_error ("too few arguments to function `next'"); return; } 358 { lua_error ("too few arguments to function `next'"); return; }
359 if (lua_getparam (3) != NULL) 359 if (lua_getparam (3) != NULL)
360 { lua_error ("too many arguments to function `next'"); return; } 360 { lua_error ("too many arguments to function `next'"); return; }
361 if (tag(o) != T_ARRAY) 361 if (tag(o) != LUA_T_ARRAY)
362 { lua_error ("first argument of function `next' is not a table"); return; } 362 { lua_error ("first argument of function `next' is not a table"); return; }
363 363
364 t = avalue(o); 364 t = avalue(o);
365 if (tag(r) == T_NIL) 365 if (tag(r) == LUA_T_NIL)
366 { 366 {
367 hashnext(t, 0); 367 hashnext(t, 0);
368 } 368 }