diff options
-rw-r--r-- | hash.c | 52 | ||||
-rw-r--r-- | table.c | 28 |
2 files changed, 40 insertions, 40 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** hash manager for lua | 3 | ** hash manager for lua |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_hash="$Id: hash.c,v 2.9 1994/10/17 19:03:23 celes Exp roberto $"; | 6 | char *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) | |||
257 | Object *lua_hashget (Hash *t, Object *ref) | 257 | Object *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 | } |
@@ -3,7 +3,7 @@ | |||
3 | ** Module to control static tables | 3 | ** Module to control static tables |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_table="$Id: table.c,v 2.6 1994/10/18 18:34:47 roberto Exp $"; | 6 | char *rcs_table="$Id: table.c,v 2.7 1994/11/02 19:09:23 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <string.h> | 9 | #include <string.h> |
@@ -54,19 +54,19 @@ static void lua_initsymbol (void) | |||
54 | return; | 54 | return; |
55 | } | 55 | } |
56 | n = lua_findsymbol("type"); | 56 | n = lua_findsymbol("type"); |
57 | s_tag(n) = T_CFUNCTION; s_fvalue(n) = lua_type; | 57 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_type; |
58 | n = lua_findsymbol("tonumber"); | 58 | n = lua_findsymbol("tonumber"); |
59 | s_tag(n) = T_CFUNCTION; s_fvalue(n) = lua_obj2number; | 59 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_obj2number; |
60 | n = lua_findsymbol("next"); | 60 | n = lua_findsymbol("next"); |
61 | s_tag(n) = T_CFUNCTION; s_fvalue(n) = lua_next; | 61 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_next; |
62 | n = lua_findsymbol("nextvar"); | 62 | n = lua_findsymbol("nextvar"); |
63 | s_tag(n) = T_CFUNCTION; s_fvalue(n) = lua_nextvar; | 63 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_nextvar; |
64 | n = lua_findsymbol("print"); | 64 | n = lua_findsymbol("print"); |
65 | s_tag(n) = T_CFUNCTION; s_fvalue(n) = lua_print; | 65 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_print; |
66 | n = lua_findsymbol("dofile"); | 66 | n = lua_findsymbol("dofile"); |
67 | s_tag(n) = T_CFUNCTION; s_fvalue(n) = lua_internaldofile; | 67 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldofile; |
68 | n = lua_findsymbol("dostring"); | 68 | n = lua_findsymbol("dostring"); |
69 | s_tag(n) = T_CFUNCTION; s_fvalue(n) = lua_internaldostring; | 69 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldostring; |
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
@@ -126,7 +126,7 @@ int lua_findsymbol (char *s) | |||
126 | } | 126 | } |
127 | } | 127 | } |
128 | indexstring(n) = lua_ntable; | 128 | indexstring(n) = lua_ntable; |
129 | s_tag(lua_ntable) = T_NIL; | 129 | s_tag(lua_ntable) = LUA_T_NIL; |
130 | lua_ntable++; | 130 | lua_ntable++; |
131 | } | 131 | } |
132 | return indexstring(n); | 132 | return indexstring(n); |
@@ -190,9 +190,9 @@ void lua_travsymbol (void (*fn)(Object *)) | |||
190 | */ | 190 | */ |
191 | void lua_markobject (Object *o) | 191 | void lua_markobject (Object *o) |
192 | { | 192 | { |
193 | if (tag(o) == T_STRING && indexstring(svalue(o)) == UNMARKED_STRING) | 193 | if (tag(o) == LUA_T_STRING && indexstring(svalue(o)) == UNMARKED_STRING) |
194 | indexstring(svalue(o)) = MARKED_STRING; | 194 | indexstring(svalue(o)) = MARKED_STRING; |
195 | else if (tag(o) == T_ARRAY) | 195 | else if (tag(o) == LUA_T_ARRAY) |
196 | lua_hashmark (avalue(o)); | 196 | lua_hashmark (avalue(o)); |
197 | } | 197 | } |
198 | 198 | ||
@@ -278,11 +278,11 @@ void lua_nextvar (void) | |||
278 | { lua_error ("too few arguments to function `nextvar'"); return; } | 278 | { lua_error ("too few arguments to function `nextvar'"); return; } |
279 | if (lua_getparam (2) != NULL) | 279 | if (lua_getparam (2) != NULL) |
280 | { lua_error ("too many arguments to function `nextvar'"); return; } | 280 | { lua_error ("too many arguments to function `nextvar'"); return; } |
281 | if (tag(o) == T_NIL) | 281 | if (tag(o) == LUA_T_NIL) |
282 | { | 282 | { |
283 | varname = 0; | 283 | varname = 0; |
284 | } | 284 | } |
285 | else if (tag(o) != T_STRING) | 285 | else if (tag(o) != LUA_T_STRING) |
286 | { | 286 | { |
287 | lua_error ("incorrect argument to function `nextvar'"); | 287 | lua_error ("incorrect argument to function `nextvar'"); |
288 | return; | 288 | return; |
@@ -300,7 +300,7 @@ void lua_nextvar (void) | |||
300 | else | 300 | else |
301 | { | 301 | { |
302 | Object name; | 302 | Object name; |
303 | tag(&name) = T_STRING; | 303 | tag(&name) = LUA_T_STRING; |
304 | svalue(&name) = next; | 304 | svalue(&name) = next; |
305 | if (lua_pushobject (&name)) return; | 305 | if (lua_pushobject (&name)) return; |
306 | if (lua_pushobject (&s_object(indexstring(next)))) return; | 306 | if (lua_pushobject (&s_object(indexstring(next)))) return; |