diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-12-20 19:20:36 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-12-20 19:20:36 -0200 |
commit | 8cb8594a3bcfdc1447aebfcd0ac85db9af5ca490 (patch) | |
tree | 13d09f704662cafa2597e77c92611b468e4741c9 | |
parent | fe8338335dfb4bf37e6b164cb55bfcc94ec6563d (diff) | |
download | lua-8cb8594a3bcfdc1447aebfcd0ac85db9af5ca490.tar.gz lua-8cb8594a3bcfdc1447aebfcd0ac85db9af5ca490.tar.bz2 lua-8cb8594a3bcfdc1447aebfcd0ac85db9af5ca490.zip |
better control of integer types and their limits
-rw-r--r-- | fallback.c | 10 | ||||
-rw-r--r-- | hash.c | 62 | ||||
-rw-r--r-- | hash.h | 12 | ||||
-rw-r--r-- | inout.c | 22 | ||||
-rw-r--r-- | inout.h | 11 | ||||
-rw-r--r-- | lex.c | 4 | ||||
-rw-r--r-- | lua.stx | 20 | ||||
-rw-r--r-- | luamem.c | 6 | ||||
-rw-r--r-- | opcode.c | 49 | ||||
-rw-r--r-- | opcode.h | 45 | ||||
-rw-r--r-- | table.c | 31 | ||||
-rw-r--r-- | table.h | 8 | ||||
-rw-r--r-- | tree.c | 6 | ||||
-rw-r--r-- | tree.h | 5 |
14 files changed, 148 insertions, 143 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_fallback="$Id: fallback.c,v 1.8 1994/11/21 13:30:15 roberto Exp roberto $"; | 6 | char *rcs_fallback="$Id: fallback.c,v 1.9 1994/11/21 18:22:58 roberto Stab roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | 9 | ||
@@ -116,12 +116,12 @@ static void funcFB (void) | |||
116 | */ | 116 | */ |
117 | 117 | ||
118 | static Object *lockArray = NULL; | 118 | static Object *lockArray = NULL; |
119 | static int lockSize = 0; | 119 | static Word lockSize = 0; |
120 | 120 | ||
121 | int luaI_lock (Object *object) | 121 | int luaI_lock (Object *object) |
122 | { | 122 | { |
123 | int i; | 123 | Word i; |
124 | int oldSize; | 124 | Word oldSize; |
125 | if (tag(object) == LUA_T_NIL) | 125 | if (tag(object) == LUA_T_NIL) |
126 | return -1; | 126 | return -1; |
127 | for (i=0; i<lockSize; i++) | 127 | for (i=0; i<lockSize; i++) |
@@ -163,7 +163,7 @@ Object *luaI_getlocked (int ref) | |||
163 | 163 | ||
164 | void luaI_travlock (void (*fn)(Object *)) | 164 | void luaI_travlock (void (*fn)(Object *)) |
165 | { | 165 | { |
166 | int i; | 166 | Word i; |
167 | for (i=0; i<lockSize; i++) | 167 | for (i=0; i<lockSize; i++) |
168 | fn(&lockArray[i]); | 168 | fn(&lockArray[i]); |
169 | } | 169 | } |
@@ -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.20 1994/11/28 15:10:51 roberto Exp roberto $"; | 6 | char *rcs_hash="$Id: hash.c,v 2.21 1994/12/16 15:55:04 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include "mem.h" | 8 | #include "mem.h" |
9 | #include "opcode.h" | 9 | #include "opcode.h" |
@@ -31,21 +31,23 @@ static Hash *listhead = NULL; | |||
31 | 31 | ||
32 | 32 | ||
33 | /* hash dimensions values */ | 33 | /* hash dimensions values */ |
34 | static int dimensions[] = | 34 | static Word dimensions[] = |
35 | {3, 5, 7, 11, 23, 47, 97, 197, 397, 797, 1597, 3203, 6421, | 35 | {3, 5, 7, 11, 23, 47, 97, 197, 397, 797, 1597, 3203, 6421, |
36 | 12853, 25717, 51437, 0}; | 36 | 12853, 25717, 51437, 65521, 0}; /* 65521 == last prime < MAX_WORD */ |
37 | static int redimension (int nhash) | 37 | |
38 | static Word redimension (Word nhash) | ||
38 | { | 39 | { |
39 | int i; | 40 | Word i; |
40 | for (i=0; dimensions[i]!=0; i++) | 41 | for (i=0; dimensions[i]!=0; i++) |
41 | { | 42 | { |
42 | if (dimensions[i] > nhash) | 43 | if (dimensions[i] > nhash) |
43 | return dimensions[i]; | 44 | return dimensions[i]; |
44 | } | 45 | } |
45 | return nhash*2+1; | 46 | lua_error("table overflow"); |
47 | return 0; /* to avoid warnings */ | ||
46 | } | 48 | } |
47 | 49 | ||
48 | static int hashindex (Hash *t, Object *ref) /* hash function */ | 50 | static Word hashindex (Hash *t, Object *ref) /* hash function */ |
49 | { | 51 | { |
50 | switch (tag(ref)) | 52 | switch (tag(ref)) |
51 | { | 53 | { |
@@ -53,7 +55,7 @@ static int hashindex (Hash *t, Object *ref) /* hash function */ | |||
53 | lua_reportbug ("unexpected type to index table"); | 55 | lua_reportbug ("unexpected type to index table"); |
54 | return -1; /* UNREACHEABLE */ | 56 | return -1; /* UNREACHEABLE */ |
55 | case LUA_T_NUMBER: | 57 | case LUA_T_NUMBER: |
56 | return (((int)nvalue(ref))%nhash(t)); | 58 | return (((Word)nvalue(ref))%nhash(t)); |
57 | case LUA_T_STRING: | 59 | case LUA_T_STRING: |
58 | { | 60 | { |
59 | unsigned long h = tsvalue(ref)->hash; | 61 | unsigned long h = tsvalue(ref)->hash; |
@@ -64,20 +66,20 @@ static int hashindex (Hash *t, Object *ref) /* hash function */ | |||
64 | h = ((h<<5)-h)^(unsigned char)*(name++); | 66 | h = ((h<<5)-h)^(unsigned char)*(name++); |
65 | tsvalue(ref)->hash = h; | 67 | tsvalue(ref)->hash = h; |
66 | } | 68 | } |
67 | return h%nhash(t); /* make it a valid index */ | 69 | return (Word)h%nhash(t); /* make it a valid index */ |
68 | } | 70 | } |
69 | case LUA_T_FUNCTION: | 71 | case LUA_T_FUNCTION: |
70 | return (((int)bvalue(ref))%nhash(t)); | 72 | return (((IntPoint)bvalue(ref))%nhash(t)); |
71 | case LUA_T_CFUNCTION: | 73 | case LUA_T_CFUNCTION: |
72 | return (((int)fvalue(ref))%nhash(t)); | 74 | return (((IntPoint)fvalue(ref))%nhash(t)); |
73 | case LUA_T_ARRAY: | 75 | case LUA_T_ARRAY: |
74 | return (((int)avalue(ref))%nhash(t)); | 76 | return (((IntPoint)avalue(ref))%nhash(t)); |
75 | default: /* user data */ | 77 | default: /* user data */ |
76 | return (((int)uvalue(ref))%nhash(t)); | 78 | return (((IntPoint)uvalue(ref))%nhash(t)); |
77 | } | 79 | } |
78 | } | 80 | } |
79 | 81 | ||
80 | int lua_equalObj (Object *t1, Object *t2) | 82 | Bool lua_equalObj (Object *t1, Object *t2) |
81 | { | 83 | { |
82 | if (tag(t1) != tag(t2)) return 0; | 84 | if (tag(t1) != tag(t2)) return 0; |
83 | switch (tag(t1)) | 85 | switch (tag(t1)) |
@@ -92,9 +94,9 @@ int lua_equalObj (Object *t1, Object *t2) | |||
92 | } | 94 | } |
93 | } | 95 | } |
94 | 96 | ||
95 | static int present (Hash *t, Object *ref) | 97 | static Word present (Hash *t, Object *ref) |
96 | { | 98 | { |
97 | int h = hashindex(t, ref); | 99 | Word h = hashindex(t, ref); |
98 | while (tag(ref(node(t, h))) != LUA_T_NIL) | 100 | while (tag(ref(node(t, h))) != LUA_T_NIL) |
99 | { | 101 | { |
100 | if (lua_equalObj(ref, ref(node(t, h)))) | 102 | if (lua_equalObj(ref, ref(node(t, h)))) |
@@ -108,9 +110,9 @@ static int present (Hash *t, Object *ref) | |||
108 | /* | 110 | /* |
109 | ** Alloc a vector node | 111 | ** Alloc a vector node |
110 | */ | 112 | */ |
111 | static Node *hashnodecreate (int nhash) | 113 | static Node *hashnodecreate (Word nhash) |
112 | { | 114 | { |
113 | int i; | 115 | Word i; |
114 | Node *v = newvector (nhash, Node); | 116 | Node *v = newvector (nhash, Node); |
115 | for (i=0; i<nhash; i++) | 117 | for (i=0; i<nhash; i++) |
116 | tag(ref(&v[i])) = LUA_T_NIL; | 118 | tag(ref(&v[i])) = LUA_T_NIL; |
@@ -120,10 +122,10 @@ static Node *hashnodecreate (int nhash) | |||
120 | /* | 122 | /* |
121 | ** Create a new hash. Return the hash pointer or NULL on error. | 123 | ** Create a new hash. Return the hash pointer or NULL on error. |
122 | */ | 124 | */ |
123 | static Hash *hashcreate (int nhash) | 125 | static Hash *hashcreate (Word nhash) |
124 | { | 126 | { |
125 | Hash *t = new(Hash); | 127 | Hash *t = new(Hash); |
126 | nhash = redimension((int)((float)nhash/REHASH_LIMIT)); | 128 | nhash = redimension((Word)((float)nhash/REHASH_LIMIT)); |
127 | nodevector(t) = hashnodecreate(nhash); | 129 | nodevector(t) = hashnodecreate(nhash); |
128 | nhash(t) = nhash; | 130 | nhash(t) = nhash; |
129 | nuse(t) = 0; | 131 | nuse(t) = 0; |
@@ -148,7 +150,7 @@ void lua_hashmark (Hash *h) | |||
148 | { | 150 | { |
149 | if (markarray(h) == 0) | 151 | if (markarray(h) == 0) |
150 | { | 152 | { |
151 | int i; | 153 | Word i; |
152 | markarray(h) = 1; | 154 | markarray(h) = 1; |
153 | for (i=0; i<nhash(h); i++) | 155 | for (i=0; i<nhash(h); i++) |
154 | { | 156 | { |
@@ -183,10 +185,10 @@ static void call_fallbacks (void) | |||
183 | ** Garbage collection to arrays | 185 | ** Garbage collection to arrays |
184 | ** Delete all unmarked arrays. | 186 | ** Delete all unmarked arrays. |
185 | */ | 187 | */ |
186 | int lua_hashcollector (void) | 188 | Word lua_hashcollector (void) |
187 | { | 189 | { |
188 | Hash *curr_array = listhead, *prev = NULL; | 190 | Hash *curr_array = listhead, *prev = NULL; |
189 | int counter = 0; | 191 | Word counter = 0; |
190 | call_fallbacks(); | 192 | call_fallbacks(); |
191 | while (curr_array != NULL) | 193 | while (curr_array != NULL) |
192 | { | 194 | { |
@@ -215,7 +217,7 @@ int lua_hashcollector (void) | |||
215 | ** executes garbage collection if the number of arrays created | 217 | ** executes garbage collection if the number of arrays created |
216 | ** exceed a pre-defined range. | 218 | ** exceed a pre-defined range. |
217 | */ | 219 | */ |
218 | Hash *lua_createarray (int nhash) | 220 | Hash *lua_createarray (Word nhash) |
219 | { | 221 | { |
220 | Hash *array; | 222 | Hash *array; |
221 | lua_pack(); | 223 | lua_pack(); |
@@ -231,8 +233,8 @@ Hash *lua_createarray (int nhash) | |||
231 | */ | 233 | */ |
232 | static void rehash (Hash *t) | 234 | static void rehash (Hash *t) |
233 | { | 235 | { |
234 | int i; | 236 | Word i; |
235 | int nold = nhash(t); | 237 | Word nold = nhash(t); |
236 | Node *vold = nodevector(t); | 238 | Node *vold = nodevector(t); |
237 | nhash(t) = redimension(nhash(t)); | 239 | nhash(t) = redimension(nhash(t)); |
238 | nodevector(t) = hashnodecreate(nhash(t)); | 240 | nodevector(t) = hashnodecreate(nhash(t)); |
@@ -251,7 +253,7 @@ static void rehash (Hash *t) | |||
251 | */ | 253 | */ |
252 | Object *lua_hashget (Hash *t, Object *ref) | 254 | Object *lua_hashget (Hash *t, Object *ref) |
253 | { | 255 | { |
254 | int h = present(t, ref); | 256 | Word h = present(t, ref); |
255 | if (tag(ref(node(t, h))) != LUA_T_NIL) return val(node(t, h)); | 257 | if (tag(ref(node(t, h))) != LUA_T_NIL) return val(node(t, h)); |
256 | else return NULL; | 258 | else return NULL; |
257 | } | 259 | } |
@@ -263,7 +265,7 @@ Object *lua_hashget (Hash *t, Object *ref) | |||
263 | */ | 265 | */ |
264 | Object *lua_hashdefine (Hash *t, Object *ref) | 266 | Object *lua_hashdefine (Hash *t, Object *ref) |
265 | { | 267 | { |
266 | int h; | 268 | Word h; |
267 | Node *n; | 269 | Node *n; |
268 | h = present(t, ref); | 270 | h = present(t, ref); |
269 | n = node(t, h); | 271 | n = node(t, h); |
@@ -289,7 +291,7 @@ Object *lua_hashdefine (Hash *t, Object *ref) | |||
289 | ** in the hash. | 291 | ** in the hash. |
290 | ** This function pushs the element value and its reference to the stack. | 292 | ** This function pushs the element value and its reference to the stack. |
291 | */ | 293 | */ |
292 | static void hashnext (Hash *t, int i) | 294 | static void hashnext (Hash *t, Word i) |
293 | { | 295 | { |
294 | if (i >= nhash(t)) | 296 | if (i >= nhash(t)) |
295 | { | 297 | { |
@@ -326,7 +328,7 @@ void lua_next (void) | |||
326 | } | 328 | } |
327 | else | 329 | else |
328 | { | 330 | { |
329 | int h = present (t, luaI_Address(r)); | 331 | Word h = present (t, luaI_Address(r)); |
330 | hashnext(t, h+1); | 332 | hashnext(t, h+1); |
331 | } | 333 | } |
332 | } | 334 | } |
@@ -2,7 +2,7 @@ | |||
2 | ** hash.h | 2 | ** hash.h |
3 | ** hash manager for lua | 3 | ** hash manager for lua |
4 | ** Luiz Henrique de Figueiredo - 17 Aug 90 | 4 | ** Luiz Henrique de Figueiredo - 17 Aug 90 |
5 | ** $Id: hash.h,v 2.5 1994/11/14 18:41:15 roberto Exp roberto $ | 5 | ** $Id: hash.h,v 2.6 1994/11/17 13:58:57 roberto Stab roberto $ |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #ifndef hash_h | 8 | #ifndef hash_h |
@@ -18,16 +18,16 @@ typedef struct Hash | |||
18 | { | 18 | { |
19 | struct Hash *next; | 19 | struct Hash *next; |
20 | char mark; | 20 | char mark; |
21 | unsigned int nhash; | 21 | Word nhash; |
22 | unsigned int nuse; | 22 | Word nuse; |
23 | Node *node; | 23 | Node *node; |
24 | } Hash; | 24 | } Hash; |
25 | 25 | ||
26 | 26 | ||
27 | int lua_equalObj (Object *t1, Object *t2); | 27 | Bool lua_equalObj (Object *t1, Object *t2); |
28 | Hash *lua_createarray (int nhash); | 28 | Hash *lua_createarray (Word nhash); |
29 | void lua_hashmark (Hash *h); | 29 | void lua_hashmark (Hash *h); |
30 | int lua_hashcollector (void); | 30 | Word lua_hashcollector (void); |
31 | Object *lua_hashget (Hash *t, Object *ref); | 31 | Object *lua_hashget (Hash *t, Object *ref); |
32 | Object *lua_hashdefine (Hash *t, Object *ref); | 32 | Object *lua_hashdefine (Hash *t, Object *ref); |
33 | void lua_next (void); | 33 | void lua_next (void); |
@@ -5,7 +5,7 @@ | |||
5 | ** Also provides some predefined lua functions. | 5 | ** Also provides some predefined lua functions. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | char *rcs_inout="$Id: inout.c,v 2.14 1994/12/13 15:54:21 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.15 1994/12/16 15:55:04 roberto Exp roberto $"; |
9 | 9 | ||
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
@@ -20,9 +20,9 @@ char *rcs_inout="$Id: inout.c,v 2.14 1994/12/13 15:54:21 roberto Exp roberto $"; | |||
20 | #include "lua.h" | 20 | #include "lua.h" |
21 | 21 | ||
22 | /* Exported variables */ | 22 | /* Exported variables */ |
23 | int lua_linenumber; | 23 | Word lua_linenumber; |
24 | int lua_debug; | 24 | Bool lua_debug; |
25 | int lua_debugline = 0; | 25 | Word lua_debugline = 0; |
26 | 26 | ||
27 | 27 | ||
28 | /* Internal variables */ | 28 | /* Internal variables */ |
@@ -34,12 +34,12 @@ int lua_debugline = 0; | |||
34 | typedef struct FuncStackNode { | 34 | typedef struct FuncStackNode { |
35 | struct FuncStackNode *next; | 35 | struct FuncStackNode *next; |
36 | char *file; | 36 | char *file; |
37 | int function; | 37 | Word function; |
38 | int line; | 38 | Word line; |
39 | } FuncStackNode; | 39 | } FuncStackNode; |
40 | 40 | ||
41 | static FuncStackNode *funcStack = NULL; | 41 | static FuncStackNode *funcStack = NULL; |
42 | static int nfuncstack=0; | 42 | static Word nfuncstack=0; |
43 | 43 | ||
44 | static FILE *fp; | 44 | static FILE *fp; |
45 | static char *st; | 45 | static char *st; |
@@ -119,7 +119,7 @@ void lua_closestring (void) | |||
119 | ** Called to execute SETFUNCTION opcode, this function pushs a function into | 119 | ** Called to execute SETFUNCTION opcode, this function pushs a function into |
120 | ** function stack. | 120 | ** function stack. |
121 | */ | 121 | */ |
122 | void lua_pushfunction (char *file, int function) | 122 | void lua_pushfunction (char *file, Word function) |
123 | { | 123 | { |
124 | FuncStackNode *newNode; | 124 | FuncStackNode *newNode; |
125 | if (nfuncstack++ >= MAXFUNCSTACK) | 125 | if (nfuncstack++ >= MAXFUNCSTACK) |
@@ -165,8 +165,8 @@ void lua_reportbug (char *s) | |||
165 | do | 165 | do |
166 | { | 166 | { |
167 | sprintf (strchr(msg,0), | 167 | sprintf (strchr(msg,0), |
168 | "\t-> function \"%s\" at file \"%s\":%d\n", | 168 | "\t-> function \"%s\" at file \"%s\":%u\n", |
169 | lua_constant[func->function]->str, func->file, line); | 169 | lua_constant[func->function]->str, func->file, line); |
170 | line = func->line; | 170 | line = func->line; |
171 | func = func->next; | 171 | func = func->next; |
172 | lua_popfunction(); | 172 | lua_popfunction(); |
@@ -175,7 +175,7 @@ void lua_reportbug (char *s) | |||
175 | else | 175 | else |
176 | { | 176 | { |
177 | sprintf (strchr(msg,0), | 177 | sprintf (strchr(msg,0), |
178 | "\n\tin statement begining at line %d of file \"%s\"", | 178 | "\n\tin statement begining at line %u of file \"%s\"", |
179 | lua_debugline, lua_filename()); | 179 | lua_debugline, lua_filename()); |
180 | } | 180 | } |
181 | } | 181 | } |
@@ -1,21 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: inout.h,v 1.5 1994/11/08 20:06:15 roberto Exp roberto $ | 2 | ** $Id: inout.h,v 1.6 1994/11/21 21:41:09 roberto Stab roberto $ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | 5 | ||
6 | #ifndef inout_h | 6 | #ifndef inout_h |
7 | #define inout_h | 7 | #define inout_h |
8 | 8 | ||
9 | #include "types.h" | ||
9 | 10 | ||
10 | extern int lua_linenumber; | 11 | extern Word lua_linenumber; |
11 | extern int lua_debug; | 12 | extern Bool lua_debug; |
12 | extern int lua_debugline; | 13 | extern Word lua_debugline; |
13 | 14 | ||
14 | char *lua_openfile (char *fn); | 15 | char *lua_openfile (char *fn); |
15 | void lua_closefile (void); | 16 | void lua_closefile (void); |
16 | char *lua_openstring (char *s); | 17 | char *lua_openstring (char *s); |
17 | void lua_closestring (void); | 18 | void lua_closestring (void); |
18 | void lua_pushfunction (char *file, int function); | 19 | void lua_pushfunction (char *file, Word function); |
19 | void lua_popfunction (void); | 20 | void lua_popfunction (void); |
20 | void lua_reportbug (char *s); | 21 | void lua_reportbug (char *s); |
21 | 22 | ||
@@ -1,4 +1,4 @@ | |||
1 | char *rcs_lex = "$Id: lex.c,v 2.11 1994/11/14 21:40:14 roberto Exp $"; | 1 | char *rcs_lex = "$Id: lex.c,v 2.12 1994/11/22 16:13:45 roberto Stab $"; |
2 | 2 | ||
3 | 3 | ||
4 | #include <ctype.h> | 4 | #include <ctype.h> |
@@ -195,7 +195,7 @@ int yylex (void) | |||
195 | case 'Z': | 195 | case 'Z': |
196 | case '_': | 196 | case '_': |
197 | { | 197 | { |
198 | int res; | 198 | Word res; |
199 | do { save_and_next(); } while (isalnum(current) || current == '_'); | 199 | do { save_and_next(); } while (isalnum(current) || current == '_'); |
200 | *yytextLast = 0; | 200 | *yytextLast = 0; |
201 | res = findReserved(yytext); | 201 | res = findReserved(yytext); |
@@ -1,6 +1,6 @@ | |||
1 | %{ | 1 | %{ |
2 | 2 | ||
3 | char *rcs_luastx = "$Id: lua.stx,v 3.12 1994/11/25 19:24:57 roberto Exp $"; | 3 | char *rcs_luastx = "$Id: lua.stx,v 3.13 1994/12/06 14:27:18 roberto Exp roberto $"; |
4 | 4 | ||
5 | #include <stdio.h> | 5 | #include <stdio.h> |
6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
@@ -29,17 +29,17 @@ int yyparse (void); | |||
29 | #ifndef CODE_BLOCK | 29 | #ifndef CODE_BLOCK |
30 | #define CODE_BLOCK 256 | 30 | #define CODE_BLOCK 256 |
31 | #endif | 31 | #endif |
32 | static Long maxcode; | 32 | static Word maxcode; |
33 | static Long maxmain; | 33 | static Word maxmain; |
34 | static Long maxcurr ; | 34 | static Long maxcurr; /* to allow maxcurr *= 2 without overflow */ |
35 | static Byte *funcCode = NULL; | 35 | static Byte *funcCode = NULL; |
36 | static Byte **initcode; | 36 | static Byte **initcode; |
37 | static Byte *basepc; | 37 | static Byte *basepc; |
38 | static Long maincode; | 38 | static Word maincode; |
39 | static Long pc; | 39 | static Word pc; |
40 | 40 | ||
41 | #define MAXVAR 32 | 41 | #define MAXVAR 32 |
42 | static long varbuffer[MAXVAR]; /* variables in an assignment list; | 42 | static Long varbuffer[MAXVAR]; /* variables in an assignment list; |
43 | it's long to store negative Word values */ | 43 | it's long to store negative Word values */ |
44 | static int nvarbuffer=0; /* number of variables at a list */ | 44 | static int nvarbuffer=0; /* number of variables at a list */ |
45 | 45 | ||
@@ -57,7 +57,11 @@ static void code_byte (Byte c) | |||
57 | { | 57 | { |
58 | if (pc>maxcurr-2) /* 1 byte free to code HALT of main code */ | 58 | if (pc>maxcurr-2) /* 1 byte free to code HALT of main code */ |
59 | { | 59 | { |
60 | if (maxcurr >= MAX_WORD) | ||
61 | lua_error("code size overflow"); | ||
60 | maxcurr *= 2; | 62 | maxcurr *= 2; |
63 | if (maxcurr >= MAX_WORD) | ||
64 | maxcurr = MAX_WORD; | ||
61 | basepc = growvector(basepc, maxcurr, Byte); | 65 | basepc = growvector(basepc, maxcurr, Byte); |
62 | } | 66 | } |
63 | basepc[pc++] = c; | 67 | basepc[pc++] = c; |
@@ -567,7 +571,7 @@ static int lua_localname (Word n) | |||
567 | ** indexed by (number -1). If negative, push local indexed by ABS(number)-1. | 571 | ** indexed by (number -1). If negative, push local indexed by ABS(number)-1. |
568 | ** Otherwise, if zero, push indexed variable (record). | 572 | ** Otherwise, if zero, push indexed variable (record). |
569 | */ | 573 | */ |
570 | static void lua_pushvar (long number) | 574 | static void lua_pushvar (Long number) |
571 | { | 575 | { |
572 | if (number > 0) /* global var */ | 576 | if (number > 0) /* global var */ |
573 | { | 577 | { |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_mem = "$Id: mem.c,v 1.1 1994/11/16 17:38:08 roberto Exp $"; | 6 | char *rcs_mem = "$Id: mem.c,v 1.2 1994/11/16 18:09:11 roberto Stab $"; |
7 | 7 | ||
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | 9 | ||
@@ -19,7 +19,7 @@ void luaI_free (void *block) | |||
19 | 19 | ||
20 | void *luaI_malloc (unsigned long size) | 20 | void *luaI_malloc (unsigned long size) |
21 | { | 21 | { |
22 | void *block = malloc(size); | 22 | void *block = malloc((size_t)size); |
23 | if (block == NULL) | 23 | if (block == NULL) |
24 | lua_error("not enough memory"); | 24 | lua_error("not enough memory"); |
25 | return block; | 25 | return block; |
@@ -28,7 +28,7 @@ void *luaI_malloc (unsigned long size) | |||
28 | 28 | ||
29 | void *luaI_realloc (void *oldblock, unsigned long size) | 29 | void *luaI_realloc (void *oldblock, unsigned long size) |
30 | { | 30 | { |
31 | void *block = realloc(oldblock, size); | 31 | void *block = realloc(oldblock, (size_t)size); |
32 | if (block == NULL) | 32 | if (block == NULL) |
33 | lua_error("not enough memory"); | 33 | lua_error("not enough memory"); |
34 | return block; | 34 | return block; |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.26 1994/12/16 15:56:45 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.27 1994/12/16 16:08:34 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -24,6 +24,8 @@ char *rcs_opcode="$Id: opcode.c,v 3.26 1994/12/16 15:56:45 roberto Exp roberto $ | |||
24 | 24 | ||
25 | #define STACK_BUFFER (STACKGAP+128) | 25 | #define STACK_BUFFER (STACKGAP+128) |
26 | 26 | ||
27 | typedef unsigned int StkId; /* index to stack elements */ | ||
28 | |||
27 | static Long maxstack = 0L; | 29 | static Long maxstack = 0L; |
28 | static Object *stack = NULL; | 30 | static Object *stack = NULL; |
29 | static Object *top = NULL; | 31 | static Object *top = NULL; |
@@ -35,16 +37,16 @@ static Object *top = NULL; | |||
35 | #define Ref(st) ((st)-stack+1) | 37 | #define Ref(st) ((st)-stack+1) |
36 | 38 | ||
37 | 39 | ||
38 | static int CBase = 0; /* when Lua calls C or C calls Lua, points to the */ | 40 | static StkId CBase = 0; /* when Lua calls C or C calls Lua, points to */ |
39 | /* first slot after the last parameter. */ | 41 | /* the first slot after the last parameter. */ |
40 | static int CnResults = 0; /* when Lua calls C, has the number of parameters; */ | 42 | static int CnResults = 0; /* when Lua calls C, has the number of parameters; */ |
41 | /* when C calls Lua, has the number of results. */ | 43 | /* when C calls Lua, has the number of results. */ |
42 | 44 | ||
43 | static jmp_buf *errorJmp = NULL; /* current error recover point */ | 45 | static jmp_buf *errorJmp = NULL; /* current error recover point */ |
44 | 46 | ||
45 | 47 | ||
46 | static int lua_execute (Byte *pc, int base); | 48 | static StkId lua_execute (Byte *pc, StkId base); |
47 | static void do_call (Object *func, int base, int nResults, int whereRes); | 49 | static void do_call (Object *func, StkId base, int nResults, StkId whereRes); |
48 | 50 | ||
49 | 51 | ||
50 | 52 | ||
@@ -94,11 +96,11 @@ static void lua_initstack (void) | |||
94 | /* | 96 | /* |
95 | ** Check stack overflow and, if necessary, realloc vector | 97 | ** Check stack overflow and, if necessary, realloc vector |
96 | */ | 98 | */ |
97 | static void lua_checkstack (Word n) | 99 | static void lua_checkstack (StkId n) |
98 | { | 100 | { |
99 | if ((Long)n > maxstack) | 101 | if ((Long)n > maxstack) |
100 | { | 102 | { |
101 | int t; | 103 | StkId t; |
102 | if (stack == NULL) | 104 | if (stack == NULL) |
103 | lua_initstack(); | 105 | lua_initstack(); |
104 | t = top-stack; | 106 | t = top-stack; |
@@ -176,7 +178,7 @@ static int lua_tostring (Object *obj) | |||
176 | /* | 178 | /* |
177 | ** Adjust stack. Set top to the given value, pushing NILs if needed. | 179 | ** Adjust stack. Set top to the given value, pushing NILs if needed. |
178 | */ | 180 | */ |
179 | static void adjust_top (int newtop) | 181 | static void adjust_top (StkId newtop) |
180 | { | 182 | { |
181 | Object *nt = stack+newtop; | 183 | Object *nt = stack+newtop; |
182 | while (top < nt) tag(top++) = LUA_T_NIL; | 184 | while (top < nt) tag(top++) = LUA_T_NIL; |
@@ -195,11 +197,11 @@ static void adjustC (int nParams) | |||
195 | ** and CnResults is the number of parameters. Returns an index | 197 | ** and CnResults is the number of parameters. Returns an index |
196 | ** to the first result from C. | 198 | ** to the first result from C. |
197 | */ | 199 | */ |
198 | static int callC (lua_CFunction func, int base) | 200 | static StkId callC (lua_CFunction func, StkId base) |
199 | { | 201 | { |
200 | int oldBase = CBase; | 202 | StkId oldBase = CBase; |
201 | int oldCnResults = CnResults; | 203 | int oldCnResults = CnResults; |
202 | int firstResult; | 204 | StkId firstResult; |
203 | CnResults = (top-stack) - base; | 205 | CnResults = (top-stack) - base; |
204 | /* incorporate parameters on the stack */ | 206 | /* incorporate parameters on the stack */ |
205 | CBase = base+CnResults; | 207 | CBase = base+CnResults; |
@@ -213,9 +215,9 @@ static int callC (lua_CFunction func, int base) | |||
213 | /* | 215 | /* |
214 | ** Call the fallback for invalid functions (see do_call) | 216 | ** Call the fallback for invalid functions (see do_call) |
215 | */ | 217 | */ |
216 | static void call_funcFB (Object *func, int base, int nResults, int whereRes) | 218 | static void call_funcFB (Object *func, StkId base, int nResults, StkId whereRes) |
217 | { | 219 | { |
218 | int i; | 220 | StkId i; |
219 | /* open space for first parameter (func) */ | 221 | /* open space for first parameter (func) */ |
220 | for (i=top-stack; i>base; i--) | 222 | for (i=top-stack; i>base; i--) |
221 | stack[i] = stack[i-1]; | 223 | stack[i] = stack[i-1]; |
@@ -231,9 +233,9 @@ static void call_funcFB (Object *func, int base, int nResults, int whereRes) | |||
231 | ** between [stack+whereRes,top). The number of results is nResults, unless | 233 | ** between [stack+whereRes,top). The number of results is nResults, unless |
232 | ** nResults=MULT_RET. | 234 | ** nResults=MULT_RET. |
233 | */ | 235 | */ |
234 | static void do_call (Object *func, int base, int nResults, int whereRes) | 236 | static void do_call (Object *func, StkId base, int nResults, StkId whereRes) |
235 | { | 237 | { |
236 | int firstResult; | 238 | StkId firstResult; |
237 | if (tag(func) == LUA_T_CFUNCTION) | 239 | if (tag(func) == LUA_T_CFUNCTION) |
238 | firstResult = callC(fvalue(func), base); | 240 | firstResult = callC(fvalue(func), base); |
239 | else if (tag(func) == LUA_T_FUNCTION) | 241 | else if (tag(func) == LUA_T_FUNCTION) |
@@ -315,7 +317,7 @@ static int do_protectedrun (Object *function, int nResults) | |||
315 | { | 317 | { |
316 | jmp_buf myErrorJmp; | 318 | jmp_buf myErrorJmp; |
317 | int status; | 319 | int status; |
318 | int oldCBase = CBase; | 320 | StkId oldCBase = CBase; |
319 | jmp_buf *oldErr = errorJmp; | 321 | jmp_buf *oldErr = errorJmp; |
320 | errorJmp = &myErrorJmp; | 322 | errorJmp = &myErrorJmp; |
321 | if (setjmp(myErrorJmp) == 0) | 323 | if (setjmp(myErrorJmp) == 0) |
@@ -340,7 +342,7 @@ static int do_protectedmain (void) | |||
340 | { | 342 | { |
341 | Byte *code = NULL; | 343 | Byte *code = NULL; |
342 | int status; | 344 | int status; |
343 | int oldCBase = CBase; | 345 | StkId oldCBase = CBase; |
344 | jmp_buf myErrorJmp; | 346 | jmp_buf myErrorJmp; |
345 | jmp_buf *oldErr = errorJmp; | 347 | jmp_buf *oldErr = errorJmp; |
346 | errorJmp = &myErrorJmp; | 348 | errorJmp = &myErrorJmp; |
@@ -377,7 +379,7 @@ int lua_callfunction (lua_Object function) | |||
377 | 379 | ||
378 | int lua_call (char *funcname) | 380 | int lua_call (char *funcname) |
379 | { | 381 | { |
380 | int n = luaI_findsymbolbyname(funcname); | 382 | Word n = luaI_findsymbolbyname(funcname); |
381 | return do_protectedrun(&s_object(n), MULT_RET); | 383 | return do_protectedrun(&s_object(n), MULT_RET); |
382 | } | 384 | } |
383 | 385 | ||
@@ -455,7 +457,7 @@ lua_Object lua_getsubscript (void) | |||
455 | #define MAX_C_BLOCKS 10 | 457 | #define MAX_C_BLOCKS 10 |
456 | 458 | ||
457 | static int numCblocks = 0; | 459 | static int numCblocks = 0; |
458 | static int Cblocks[MAX_C_BLOCKS]; | 460 | static StkId Cblocks[MAX_C_BLOCKS]; |
459 | 461 | ||
460 | /* | 462 | /* |
461 | ** API: starts a new block | 463 | ** API: starts a new block |
@@ -580,7 +582,7 @@ int lua_lock (void) | |||
580 | */ | 582 | */ |
581 | lua_Object lua_getglobal (char *name) | 583 | lua_Object lua_getglobal (char *name) |
582 | { | 584 | { |
583 | int n = luaI_findsymbolbyname(name); | 585 | Word n = luaI_findsymbolbyname(name); |
584 | adjustC(0); | 586 | adjustC(0); |
585 | *top = s_object(n); | 587 | *top = s_object(n); |
586 | top++; | 588 | top++; |
@@ -594,8 +596,7 @@ lua_Object lua_getglobal (char *name) | |||
594 | */ | 596 | */ |
595 | int lua_storeglobal (char *name) | 597 | int lua_storeglobal (char *name) |
596 | { | 598 | { |
597 | int n = luaI_findsymbolbyname(name); | 599 | Word n = luaI_findsymbolbyname(name); |
598 | if (n < 0) return 1; | ||
599 | adjustC(1); | 600 | adjustC(1); |
600 | s_object(n) = *(--top); | 601 | s_object(n) = *(--top); |
601 | return 0; | 602 | return 0; |
@@ -736,7 +737,7 @@ static void comparison (lua_Type tag_less, lua_Type tag_equal, | |||
736 | ** [stack+base,top). Returns n such that the the results are between | 737 | ** [stack+base,top). Returns n such that the the results are between |
737 | ** [stack+n,top). | 738 | ** [stack+n,top). |
738 | */ | 739 | */ |
739 | static int lua_execute (Byte *pc, int base) | 740 | static StkId lua_execute (Byte *pc, StkId base) |
740 | { | 741 | { |
741 | lua_checkstack(STACKGAP+MAX_TEMPS+base); | 742 | lua_checkstack(STACKGAP+MAX_TEMPS+base); |
742 | while (1) | 743 | while (1) |
@@ -1080,7 +1081,7 @@ static int lua_execute (Byte *pc, int base) | |||
1080 | int nParams = *(pc++); | 1081 | int nParams = *(pc++); |
1081 | int nResults = *(pc++); | 1082 | int nResults = *(pc++); |
1082 | Object *func = top-1-nParams; /* function is below parameters */ | 1083 | Object *func = top-1-nParams; /* function is below parameters */ |
1083 | int newBase = (top-stack)-nParams; | 1084 | StkId newBase = (top-stack)-nParams; |
1084 | do_call(func, newBase, nResults, newBase-1); | 1085 | do_call(func, newBase, nResults, newBase-1); |
1085 | } | 1086 | } |
1086 | break; | 1087 | break; |
@@ -1,12 +1,13 @@ | |||
1 | /* | 1 | /* |
2 | ** TeCGraf - PUC-Rio | 2 | ** TeCGraf - PUC-Rio |
3 | ** $Id: opcode.h,v 3.8 1994/11/10 17:36:54 roberto Exp roberto $ | 3 | ** $Id: opcode.h,v 3.9 1994/11/23 14:31:11 roberto Stab $ |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #ifndef opcode_h | 6 | #ifndef opcode_h |
7 | #define opcode_h | 7 | #define opcode_h |
8 | 8 | ||
9 | #include "lua.h" | 9 | #include "lua.h" |
10 | #include "types.h" | ||
10 | #include "tree.h" | 11 | #include "tree.h" |
11 | 12 | ||
12 | #ifndef STACKGAP | 13 | #ifndef STACKGAP |
@@ -21,29 +22,6 @@ | |||
21 | 22 | ||
22 | #define MAX_TEMPS 20 | 23 | #define MAX_TEMPS 20 |
23 | 24 | ||
24 | typedef unsigned char Byte; | ||
25 | |||
26 | typedef unsigned short Word; | ||
27 | |||
28 | typedef signed long Long; | ||
29 | |||
30 | typedef union | ||
31 | { | ||
32 | struct {char c1; char c2;} m; | ||
33 | Word w; | ||
34 | } CodeWord; | ||
35 | |||
36 | typedef union | ||
37 | { | ||
38 | struct {char c1; char c2; char c3; char c4;} m; | ||
39 | float f; | ||
40 | } CodeFloat; | ||
41 | |||
42 | typedef union | ||
43 | { | ||
44 | struct {char c1; char c2; char c3; char c4;} m; | ||
45 | Byte *b; | ||
46 | } CodeCode; | ||
47 | 25 | ||
48 | typedef enum | 26 | typedef enum |
49 | { | 27 | { |
@@ -147,12 +125,29 @@ typedef struct | |||
147 | #define s_fvalue(i) (fvalue(&s_object(i))) | 125 | #define s_fvalue(i) (fvalue(&s_object(i))) |
148 | #define s_uvalue(i) (uvalue(&s_object(i))) | 126 | #define s_uvalue(i) (uvalue(&s_object(i))) |
149 | 127 | ||
128 | typedef union | ||
129 | { | ||
130 | struct {char c1; char c2;} m; | ||
131 | Word w; | ||
132 | } CodeWord; | ||
150 | #define get_word(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;} | 133 | #define get_word(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;} |
134 | |||
135 | typedef union | ||
136 | { | ||
137 | struct {char c1; char c2; char c3; char c4;} m; | ||
138 | float f; | ||
139 | } CodeFloat; | ||
151 | #define get_float(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\ | 140 | #define get_float(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\ |
152 | code.m.c3 = *pc++; code.m.c4 = *pc++;} | 141 | code.m.c3 = *pc++; code.m.c4 = *pc++;} |
142 | |||
143 | typedef union | ||
144 | { | ||
145 | struct {char c1; char c2; char c3; char c4;} m; | ||
146 | Byte *b; | ||
147 | } CodeCode; | ||
153 | #define get_code(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\ | 148 | #define get_code(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\ |
154 | code.m.c3 = *pc++; code.m.c4 = *pc++;} | 149 | code.m.c3 = *pc++; code.m.c4 = *pc++;} |
155 | 150 | ||
156 | 151 | ||
157 | /* Exported functions */ | 152 | /* Exported functions */ |
158 | char *lua_strdup (char *l); | 153 | char *lua_strdup (char *l); |
@@ -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.23 1994/11/23 14:31:11 roberto Stab roberto $"; | 6 | char *rcs_table="$Id: table.c,v 2.24 1994/12/16 15:55:04 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <string.h> | 8 | #include <string.h> |
9 | 9 | ||
@@ -17,8 +17,6 @@ char *rcs_table="$Id: table.c,v 2.23 1994/11/23 14:31:11 roberto Stab roberto $" | |||
17 | #include "fallback.h" | 17 | #include "fallback.h" |
18 | 18 | ||
19 | 19 | ||
20 | #define MAX_WORD 0xFFFD | ||
21 | |||
22 | #define BUFFER_BLOCK 256 | 20 | #define BUFFER_BLOCK 256 |
23 | 21 | ||
24 | Symbol *lua_table; | 22 | Symbol *lua_table; |
@@ -47,7 +45,7 @@ static void getglobal (void); | |||
47 | */ | 45 | */ |
48 | static void lua_initsymbol (void) | 46 | static void lua_initsymbol (void) |
49 | { | 47 | { |
50 | int n; | 48 | Word n; |
51 | lua_maxsymbol = BUFFER_BLOCK; | 49 | lua_maxsymbol = BUFFER_BLOCK; |
52 | lua_table = newvector(lua_maxsymbol, Symbol); | 50 | lua_table = newvector(lua_maxsymbol, Symbol); |
53 | n = luaI_findsymbolbyname("next"); | 51 | n = luaI_findsymbolbyname("next"); |
@@ -88,9 +86,8 @@ void lua_initconstant (void) | |||
88 | /* | 86 | /* |
89 | ** Given a name, search it at symbol table and return its index. If not | 87 | ** Given a name, search it at symbol table and return its index. If not |
90 | ** found, allocate it. | 88 | ** found, allocate it. |
91 | ** On error, return -1. | ||
92 | */ | 89 | */ |
93 | int luaI_findsymbol (TreeNode *t) | 90 | Word luaI_findsymbol (TreeNode *t) |
94 | { | 91 | { |
95 | if (lua_table == NULL) | 92 | if (lua_table == NULL) |
96 | lua_initsymbol(); | 93 | lua_initsymbol(); |
@@ -98,9 +95,11 @@ int luaI_findsymbol (TreeNode *t) | |||
98 | { | 95 | { |
99 | if (lua_ntable == lua_maxsymbol) | 96 | if (lua_ntable == lua_maxsymbol) |
100 | { | 97 | { |
101 | lua_maxsymbol *= 2; | 98 | if (lua_maxsymbol >= MAX_WORD) |
102 | if (lua_maxsymbol > MAX_WORD) | ||
103 | lua_error("symbol table overflow"); | 99 | lua_error("symbol table overflow"); |
100 | lua_maxsymbol *= 2; | ||
101 | if (lua_maxsymbol >= MAX_WORD) | ||
102 | lua_maxsymbol = MAX_WORD; | ||
104 | lua_table = growvector(lua_table, lua_maxsymbol, Symbol); | 103 | lua_table = growvector(lua_table, lua_maxsymbol, Symbol); |
105 | } | 104 | } |
106 | t->varindex = lua_ntable; | 105 | t->varindex = lua_ntable; |
@@ -111,7 +110,7 @@ int luaI_findsymbol (TreeNode *t) | |||
111 | } | 110 | } |
112 | 111 | ||
113 | 112 | ||
114 | int luaI_findsymbolbyname (char *name) | 113 | Word luaI_findsymbolbyname (char *name) |
115 | { | 114 | { |
116 | return luaI_findsymbol(lua_constcreate(name)); | 115 | return luaI_findsymbol(lua_constcreate(name)); |
117 | } | 116 | } |
@@ -122,7 +121,7 @@ int luaI_findsymbolbyname (char *name) | |||
122 | ** found, allocate it. | 121 | ** found, allocate it. |
123 | ** On error, return -1. | 122 | ** On error, return -1. |
124 | */ | 123 | */ |
125 | int luaI_findconstant (TreeNode *t) | 124 | Word luaI_findconstant (TreeNode *t) |
126 | { | 125 | { |
127 | if (lua_constant == NULL) | 126 | if (lua_constant == NULL) |
128 | lua_initconstant(); | 127 | lua_initconstant(); |
@@ -130,9 +129,11 @@ int luaI_findconstant (TreeNode *t) | |||
130 | { | 129 | { |
131 | if (lua_nconstant == lua_maxconstant) | 130 | if (lua_nconstant == lua_maxconstant) |
132 | { | 131 | { |
133 | lua_maxconstant *= 2; | 132 | if (lua_maxconstant >= MAX_WORD) |
134 | if (lua_maxconstant > MAX_WORD) | ||
135 | lua_error("constant table overflow"); | 133 | lua_error("constant table overflow"); |
134 | lua_maxconstant *= 2; | ||
135 | if (lua_maxconstant >= MAX_WORD) | ||
136 | lua_maxconstant = MAX_WORD; | ||
136 | lua_constant = growvector(lua_constant, lua_maxconstant, TaggedString *); | 137 | lua_constant = growvector(lua_constant, lua_maxconstant, TaggedString *); |
137 | } | 138 | } |
138 | t->constindex = lua_nconstant; | 139 | t->constindex = lua_nconstant; |
@@ -172,9 +173,9 @@ void lua_markobject (Object *o) | |||
172 | */ | 173 | */ |
173 | void lua_pack (void) | 174 | void lua_pack (void) |
174 | { | 175 | { |
175 | static int block = GARBAGE_BLOCK; /* when garbage collector will be called */ | 176 | static Word block = GARBAGE_BLOCK; /* when garbage collector will be called */ |
176 | static int nentity = 0; /* counter of new entities (strings and arrays) */ | 177 | static Word nentity = 0; /* counter of new entities (strings and arrays) */ |
177 | int recovered = 0; | 178 | Word recovered = 0; |
178 | if (nentity++ < block) return; | 179 | if (nentity++ < block) return; |
179 | lua_travstack(lua_markobject); /* mark stack objects */ | 180 | lua_travstack(lua_markobject); /* mark stack objects */ |
180 | lua_travsymbol(lua_markobject); /* mark symbol table objects */ | 181 | lua_travsymbol(lua_markobject); /* mark symbol table objects */ |
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | ** Module to control static tables | 2 | ** Module to control static tables |
3 | ** TeCGraf - PUC-Rio | 3 | ** TeCGraf - PUC-Rio |
4 | ** $Id: table.h,v 2.8 1994/11/18 19:27:38 roberto Exp roberto $ | 4 | ** $Id: table.h,v 2.9 1994/11/23 14:31:11 roberto Stab roberto $ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef table_h | 7 | #ifndef table_h |
@@ -18,9 +18,9 @@ extern int lua_nfile; | |||
18 | 18 | ||
19 | 19 | ||
20 | void lua_initconstant (void); | 20 | void lua_initconstant (void); |
21 | int luaI_findsymbolbyname (char *name); | 21 | Word luaI_findsymbolbyname (char *name); |
22 | int luaI_findsymbol (TreeNode *t); | 22 | Word luaI_findsymbol (TreeNode *t); |
23 | int luaI_findconstant (TreeNode *t); | 23 | Word luaI_findconstant (TreeNode *t); |
24 | void lua_travsymbol (void (*fn)(Object *)); | 24 | void lua_travsymbol (void (*fn)(Object *)); |
25 | void lua_markobject (Object *o); | 25 | void lua_markobject (Object *o); |
26 | void lua_pack (void); | 26 | void lua_pack (void); |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_tree="$Id: tree.c,v 1.10 1994/11/23 14:31:11 roberto Stab roberto $"; | 6 | char *rcs_tree="$Id: tree.c,v 1.11 1994/11/25 19:27:03 roberto Exp roberto $"; |
7 | 7 | ||
8 | 8 | ||
9 | #include <string.h> | 9 | #include <string.h> |
@@ -78,10 +78,10 @@ TreeNode *lua_constcreate (char *str) | |||
78 | ** Garbage collection function. | 78 | ** Garbage collection function. |
79 | ** This function traverse the string list freeing unindexed strings | 79 | ** This function traverse the string list freeing unindexed strings |
80 | */ | 80 | */ |
81 | int lua_strcollector (void) | 81 | Word lua_strcollector (void) |
82 | { | 82 | { |
83 | StringNode *curr = string_root, *prev = NULL; | 83 | StringNode *curr = string_root, *prev = NULL; |
84 | int counter = 0; | 84 | Word counter = 0; |
85 | while (curr) | 85 | while (curr) |
86 | { | 86 | { |
87 | StringNode *next = curr->next; | 87 | StringNode *next = curr->next; |
@@ -1,12 +1,13 @@ | |||
1 | /* | 1 | /* |
2 | ** tree.h | 2 | ** tree.h |
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | ** $Id: tree.h,v 1.6 1994/11/23 14:31:11 roberto Stab roberto $ | 4 | ** $Id: tree.h,v 1.7 1994/11/25 19:27:03 roberto Exp roberto $ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef tree_h | 7 | #ifndef tree_h |
8 | #define tree_h | 8 | #define tree_h |
9 | 9 | ||
10 | #include "types.h" | ||
10 | 11 | ||
11 | #define NOT_USED 0xFFFE | 12 | #define NOT_USED 0xFFFE |
12 | 13 | ||
@@ -30,7 +31,7 @@ typedef struct TreeNode | |||
30 | 31 | ||
31 | TaggedString *lua_createstring (char *str); | 32 | TaggedString *lua_createstring (char *str); |
32 | TreeNode *lua_constcreate (char *str); | 33 | TreeNode *lua_constcreate (char *str); |
33 | int lua_strcollector (void); | 34 | Word lua_strcollector (void); |
34 | TreeNode *lua_varnext (char *n); | 35 | TreeNode *lua_varnext (char *n); |
35 | 36 | ||
36 | #endif | 37 | #endif |