diff options
-rw-r--r-- | lapi.c | 4 | ||||
-rw-r--r-- | lcode.h | 8 | ||||
-rw-r--r-- | ldebug.c | 8 | ||||
-rw-r--r-- | ldo.c | 4 | ||||
-rw-r--r-- | lgc.c | 4 | ||||
-rw-r--r-- | llimits.h | 34 | ||||
-rw-r--r-- | lmem.c | 8 | ||||
-rw-r--r-- | lmem.h | 13 | ||||
-rw-r--r-- | lobject.c | 12 | ||||
-rw-r--r-- | lobject.h | 10 | ||||
-rw-r--r-- | lparser.c | 6 | ||||
-rw-r--r-- | lstate.h | 8 | ||||
-rw-r--r-- | lstring.c | 10 | ||||
-rw-r--r-- | lstring.h | 10 | ||||
-rw-r--r-- | ltable.c | 38 | ||||
-rw-r--r-- | ltm.c | 4 | ||||
-rw-r--r-- | lua.c | 22 | ||||
-rw-r--r-- | lua.h | 5 | ||||
-rw-r--r-- | lvm.c | 5 |
19 files changed, 121 insertions, 92 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.129 2001/02/13 16:17:53 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.130 2001/02/14 17:04:11 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -549,7 +549,7 @@ LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { | |||
549 | 549 | ||
550 | /* GC values are expressed in Kbytes: #bytes/2^10 */ | 550 | /* GC values are expressed in Kbytes: #bytes/2^10 */ |
551 | #define GCscale(x) ((int)((x)>>10)) | 551 | #define GCscale(x) ((int)((x)>>10)) |
552 | #define GCunscale(x) ((mem_int)(x)<<10) | 552 | #define GCunscale(x) ((lu_mem)(x)<<10) |
553 | 553 | ||
554 | LUA_API int lua_getgcthreshold (lua_State *L) { | 554 | LUA_API int lua_getgcthreshold (lua_State *L) { |
555 | int threshold; | 555 | int threshold; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.h,v 1.18 2000/12/04 18:33:40 roberto Exp roberto $ | 2 | ** $Id: lcode.h,v 1.19 2001/01/29 15:26:40 roberto Exp roberto $ |
3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -39,9 +39,9 @@ enum Mode {iO, iU, iS, iAB}; /* instruction format */ | |||
39 | #define VD 100 /* flag for variable delta */ | 39 | #define VD 100 /* flag for variable delta */ |
40 | 40 | ||
41 | typedef struct OpProperties { | 41 | typedef struct OpProperties { |
42 | char mode; | 42 | lu_byte mode; |
43 | unsigned char push; | 43 | lu_byte push; |
44 | unsigned char pop; | 44 | lu_byte pop; |
45 | } OpProperties; | 45 | } OpProperties; |
46 | 46 | ||
47 | extern const OpProperties luaK_opproperties[]; | 47 | extern const OpProperties luaK_opproperties[]; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 1.63 2001/02/12 19:54:28 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.64 2001/02/16 17:58:27 roberto Exp roberto $ |
3 | ** Debug Interface | 3 | ** Debug Interface |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -347,7 +347,7 @@ static int precheck (const Proto *pt) { | |||
347 | 347 | ||
348 | #define checkjump(pt,sl,top,pc) if (!checkjump_aux(pt,sl,top,pc)) return 0; | 348 | #define checkjump(pt,sl,top,pc) if (!checkjump_aux(pt,sl,top,pc)) return 0; |
349 | 349 | ||
350 | static int checkjump_aux (const Proto *pt, unsigned char *sl, int top, int pc) { | 350 | static int checkjump_aux (const Proto *pt, lu_byte *sl, int top, int pc) { |
351 | check(0 <= pc && pc < pt->sizecode); | 351 | check(0 <= pc && pc < pt->sizecode); |
352 | if (sl == NULL) return 1; /* not full checking */ | 352 | if (sl == NULL) return 1; /* not full checking */ |
353 | if (sl[pc] == SL_EMPTY) | 353 | if (sl[pc] == SL_EMPTY) |
@@ -361,12 +361,12 @@ static int checkjump_aux (const Proto *pt, unsigned char *sl, int top, int pc) { | |||
361 | static Instruction luaG_symbexec (lua_State *L, const Proto *pt, | 361 | static Instruction luaG_symbexec (lua_State *L, const Proto *pt, |
362 | int lastpc, int stackpos) { | 362 | int lastpc, int stackpos) { |
363 | int stack[MAXSTACK]; /* stores last instruction that changed a stack entry */ | 363 | int stack[MAXSTACK]; /* stores last instruction that changed a stack entry */ |
364 | unsigned char *sl = NULL; | 364 | lu_byte *sl = NULL; |
365 | int top; | 365 | int top; |
366 | int pc; | 366 | int pc; |
367 | if (stackpos < 0) { /* full check? */ | 367 | if (stackpos < 0) { /* full check? */ |
368 | int i; | 368 | int i; |
369 | sl = (unsigned char *)luaO_openspace(L, pt->sizecode); | 369 | sl = (lu_byte *)luaO_openspace(L, pt->sizecode); |
370 | for (i=0; i<pt->sizecode; i++) /* initialize stack-level array */ | 370 | for (i=0; i<pt->sizecode; i++) /* initialize stack-level array */ |
371 | sl[i] = SL_EMPTY; | 371 | sl[i] = SL_EMPTY; |
372 | check(precheck(pt)); | 372 | check(precheck(pt)); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.122 2001/02/02 16:23:20 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.123 2001/02/07 18:13:49 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -240,7 +240,7 @@ static void f_parser (lua_State *L, void *ud) { | |||
240 | 240 | ||
241 | static int protectedparser (lua_State *L, ZIO *z, int bin) { | 241 | static int protectedparser (lua_State *L, ZIO *z, int bin) { |
242 | struct SParser p; | 242 | struct SParser p; |
243 | mem_int old_blocks; | 243 | lu_mem old_blocks; |
244 | int status; | 244 | int status; |
245 | LUA_LOCK(L); | 245 | LUA_LOCK(L); |
246 | p.z = z; p.bin = bin; | 246 | p.z = z; p.bin = bin; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.87 2001/02/02 16:32:00 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.88 2001/02/07 18:13:49 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -274,7 +274,7 @@ static void collecttable (lua_State *L) { | |||
274 | 274 | ||
275 | 275 | ||
276 | static void checktab (lua_State *L, stringtable *tb) { | 276 | static void checktab (lua_State *L, stringtable *tb) { |
277 | if (tb->nuse < (luint32)(tb->size/4) && tb->size > MINPOWER2) | 277 | if (tb->nuse < (ls_nstr)(tb->size/4) && tb->size > MINPOWER2) |
278 | luaS_resize(L, tb, tb->size/2); /* table is too big */ | 278 | luaS_resize(L, tb, tb->size/2); /* table is too big */ |
279 | } | 279 | } |
280 | 280 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llimits.h,v 1.21 2000/12/04 18:33:40 roberto Exp roberto $ | 2 | ** $Id: llimits.h,v 1.22 2001/02/09 16:24:44 roberto Exp roberto $ |
3 | ** Limits, basic types, and some other "installation-dependent" definitions | 3 | ** Limits, basic types, and some other "installation-dependent" definitions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -40,11 +40,27 @@ | |||
40 | 40 | ||
41 | 41 | ||
42 | 42 | ||
43 | typedef unsigned long luint32; /* unsigned int with at least 32 bits */ | 43 | /* |
44 | typedef long lint32; /* signed int with at least 32 bits */ | 44 | ** the following types define integer types for values that may not |
45 | ** fit in a "small int" (16 bits), but may waste space in a | ||
46 | ** "large long" (64 bits). The current definitions should work in | ||
47 | ** any machine, but may not be optimal. | ||
48 | */ | ||
49 | |||
50 | /* an unsigned integer to hold hash values */ | ||
51 | typedef unsigned int lu_hash; | ||
52 | /* its signed equivalent */ | ||
53 | typedef int ls_hash; | ||
45 | 54 | ||
46 | /* an unsigned integer big enough to count the total memory used by Lua */ | 55 | /* an unsigned integer big enough to count the total memory used by Lua */ |
47 | typedef unsigned long mem_int; | 56 | typedef unsigned long lu_mem; |
57 | |||
58 | /* an integer big enough to count the number of strings in use */ | ||
59 | typedef long ls_nstr; | ||
60 | |||
61 | |||
62 | /* chars used as small naturals (so that `char' is reserved for characteres) */ | ||
63 | typedef unsigned char lu_byte; | ||
48 | 64 | ||
49 | 65 | ||
50 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) | 66 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) |
@@ -53,10 +69,12 @@ typedef unsigned long mem_int; | |||
53 | #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ | 69 | #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ |
54 | 70 | ||
55 | /* | 71 | /* |
56 | ** conversion of pointer to int (for hashing only) | 72 | ** conversion of pointer to integer |
73 | ** this is for hashing only; there is no problem if the integer | ||
74 | ** cannot hold the whole pointer value | ||
57 | ** (the shift removes bits that are usually 0 because of alignment) | 75 | ** (the shift removes bits that are usually 0 because of alignment) |
58 | */ | 76 | */ |
59 | #define IntPoint(p) (((luint32)(p)) >> 3) | 77 | #define IntPoint(p) ((((lu_hash)(p)) >> 4) ^ (lu_hash)(p)) |
60 | 78 | ||
61 | 79 | ||
62 | 80 | ||
@@ -71,7 +89,7 @@ typedef unsigned long mem_int; | |||
71 | 89 | ||
72 | 90 | ||
73 | /* type to ensure maximum alignment */ | 91 | /* type to ensure maximum alignment */ |
74 | union L_Umaxalign { double d; char *s; long l; }; | 92 | union L_Umaxalign { double d; void *s; long l; }; |
75 | 93 | ||
76 | 94 | ||
77 | 95 | ||
@@ -81,7 +99,7 @@ union L_Umaxalign { double d; char *s; long l; }; | |||
81 | ** For a very small machine, you may change that to 2 bytes (and adjust | 99 | ** For a very small machine, you may change that to 2 bytes (and adjust |
82 | ** the following limits accordingly) | 100 | ** the following limits accordingly) |
83 | */ | 101 | */ |
84 | typedef luint32 Instruction; | 102 | typedef unsigned long Instruction; |
85 | 103 | ||
86 | 104 | ||
87 | /* | 105 | /* |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmem.c,v 1.45 2001/02/05 19:08:01 roberto Exp roberto $ | 2 | ** $Id: lmem.c,v 1.46 2001/02/06 16:01:29 roberto Exp roberto $ |
3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -33,8 +33,8 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems, | |||
33 | newsize = limit; /* still have at least MINPOWER2 free places */ | 33 | newsize = limit; /* still have at least MINPOWER2 free places */ |
34 | else luaD_error(L, errormsg); | 34 | else luaD_error(L, errormsg); |
35 | } | 35 | } |
36 | newblock = luaM_realloc(L, block, (luint32)(*size)*(luint32)size_elems, | 36 | newblock = luaM_realloc(L, block, (lu_mem)(*size)*(lu_mem)size_elems, |
37 | (luint32)newsize*(luint32)size_elems); | 37 | (lu_mem)newsize*(lu_mem)size_elems); |
38 | *size = newsize; /* update only when everything else is OK */ | 38 | *size = newsize; /* update only when everything else is OK */ |
39 | return newblock; | 39 | return newblock; |
40 | } | 40 | } |
@@ -43,7 +43,7 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems, | |||
43 | /* | 43 | /* |
44 | ** generic allocation routine. | 44 | ** generic allocation routine. |
45 | */ | 45 | */ |
46 | void *luaM_realloc (lua_State *L, void *block, luint32 oldsize, luint32 size) { | 46 | void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) { |
47 | if (size == 0) { | 47 | if (size == 0) { |
48 | l_free(block, oldsize); /* block may be NULL; that is OK for free */ | 48 | l_free(block, oldsize); /* block may be NULL; that is OK for free */ |
49 | block = NULL; | 49 | block = NULL; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmem.h,v 1.19 2000/12/28 12:55:41 roberto Exp roberto $ | 2 | ** $Id: lmem.h,v 1.20 2001/02/02 15:13:05 roberto Exp roberto $ |
3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -13,8 +13,7 @@ | |||
13 | #include "llimits.h" | 13 | #include "llimits.h" |
14 | #include "lua.h" | 14 | #include "lua.h" |
15 | 15 | ||
16 | void *luaM_realloc (lua_State *L, void *oldblock, luint32 oldsize, | 16 | void *luaM_realloc (lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size); |
17 | luint32 size); | ||
18 | 17 | ||
19 | void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem, | 18 | void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem, |
20 | int limit, const char *errormsg); | 19 | int limit, const char *errormsg); |
@@ -22,20 +21,20 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem, | |||
22 | #define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0) | 21 | #define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0) |
23 | #define luaM_freelem(L, b, t) luaM_realloc(L, (b), sizeof(t), 0) | 22 | #define luaM_freelem(L, b, t) luaM_realloc(L, (b), sizeof(t), 0) |
24 | #define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \ | 23 | #define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \ |
25 | ((luint32)(n)*(luint32)sizeof(t)), 0) | 24 | ((lu_mem)(n)*(lu_mem)sizeof(t)), 0) |
26 | 25 | ||
27 | #define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t)) | 26 | #define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t)) |
28 | #define luaM_new(L, t) ((t *)luaM_malloc(L, sizeof(t))) | 27 | #define luaM_new(L, t) ((t *)luaM_malloc(L, sizeof(t))) |
29 | #define luaM_newvector(L, n,t) ((t *)luaM_malloc(L, \ | 28 | #define luaM_newvector(L, n,t) ((t *)luaM_malloc(L, \ |
30 | (luint32)(n)*(luint32)sizeof(t))) | 29 | (lu_mem)(n)*(lu_mem)sizeof(t))) |
31 | 30 | ||
32 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ | 31 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ |
33 | if (((nelems)+1) > (size)) \ | 32 | if (((nelems)+1) > (size)) \ |
34 | ((v)=(t *)luaM_growaux(L,v,&(size),sizeof(t),limit,e)) | 33 | ((v)=(t *)luaM_growaux(L,v,&(size),sizeof(t),limit,e)) |
35 | 34 | ||
36 | #define luaM_reallocvector(L, v,oldn,n,t) \ | 35 | #define luaM_reallocvector(L, v,oldn,n,t) \ |
37 | ((v)=(t *)luaM_realloc(L, v,(luint32)(oldn)*(luint32)sizeof(t), \ | 36 | ((v)=(t *)luaM_realloc(L, v,(lu_mem)(oldn)*(lu_mem)sizeof(t), \ |
38 | (luint32)(n)*(luint32)sizeof(t))) | 37 | (lu_mem)(n)*(lu_mem)sizeof(t))) |
39 | 38 | ||
40 | 39 | ||
41 | #endif | 40 | #endif |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 1.63 2001/01/29 19:34:02 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.64 2001/02/02 15:13:05 roberto Exp roberto $ |
3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -22,16 +22,6 @@ | |||
22 | const TObject luaO_nilobject = {LUA_TNIL, {NULL}}; | 22 | const TObject luaO_nilobject = {LUA_TNIL, {NULL}}; |
23 | 23 | ||
24 | 24 | ||
25 | /* | ||
26 | ** returns smaller power of 2 larger than `n' (minimum is MINPOWER2) | ||
27 | */ | ||
28 | luint32 luaO_power2 (luint32 n) { | ||
29 | luint32 p = MINPOWER2; | ||
30 | while (p<=n) p<<=1; | ||
31 | return p; | ||
32 | } | ||
33 | |||
34 | |||
35 | int luaO_equalObj (const TObject *t1, const TObject *t2) { | 25 | int luaO_equalObj (const TObject *t1, const TObject *t2) { |
36 | if (ttype(t1) != ttype(t2)) return 0; | 26 | if (ttype(t1) != ttype(t2)) return 0; |
37 | switch (ttype(t1)) { | 27 | switch (ttype(t1)) { |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.94 2001/02/02 16:32:00 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.95 2001/02/09 20:22:29 roberto Exp roberto $ |
3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -93,7 +93,7 @@ typedef struct lua_TObject { | |||
93 | typedef struct TString { | 93 | typedef struct TString { |
94 | union { | 94 | union { |
95 | struct { /* for strings */ | 95 | struct { /* for strings */ |
96 | luint32 hash; | 96 | lu_hash hash; |
97 | int constindex; /* hint to reuse constants */ | 97 | int constindex; /* hint to reuse constants */ |
98 | } s; | 98 | } s; |
99 | struct { /* for userdata */ | 99 | struct { /* for userdata */ |
@@ -160,13 +160,13 @@ typedef struct LocVar { | |||
160 | */ | 160 | */ |
161 | typedef struct Closure { | 161 | typedef struct Closure { |
162 | int isC; /* 0 for Lua functions, 1 for C functions */ | 162 | int isC; /* 0 for Lua functions, 1 for C functions */ |
163 | int nupvalues; | ||
163 | union { | 164 | union { |
164 | lua_CFunction c; /* C functions */ | 165 | lua_CFunction c; /* C functions */ |
165 | struct Proto *l; /* Lua functions */ | 166 | struct Proto *l; /* Lua functions */ |
166 | } f; | 167 | } f; |
167 | struct Closure *next; | 168 | struct Closure *next; |
168 | struct Closure *mark; /* marked closures (point to itself when not marked) */ | 169 | struct Closure *mark; /* marked closures (point to itself when not marked) */ |
169 | int nupvalues; | ||
170 | TObject upvalue[1]; | 170 | TObject upvalue[1]; |
171 | } Closure; | 171 | } Closure; |
172 | 172 | ||
@@ -199,7 +199,8 @@ typedef struct Hash { | |||
199 | 199 | ||
200 | 200 | ||
201 | /* | 201 | /* |
202 | ** "module" operation (size is always a power of 2) */ | 202 | ** "module" operation for hashing (size is always a power of 2) |
203 | */ | ||
203 | #define lmod(s,size) ((int)((s) & ((size)-1))) | 204 | #define lmod(s,size) ((int)((s) & ((size)-1))) |
204 | 205 | ||
205 | 206 | ||
@@ -218,7 +219,6 @@ typedef struct CallInfo { | |||
218 | extern const TObject luaO_nilobject; | 219 | extern const TObject luaO_nilobject; |
219 | 220 | ||
220 | 221 | ||
221 | luint32 luaO_power2 (luint32 n); | ||
222 | char *luaO_openspace (lua_State *L, size_t n); | 222 | char *luaO_openspace (lua_State *L, size_t n); |
223 | 223 | ||
224 | int luaO_equalObj (const TObject *t1, const TObject *t2); | 224 | int luaO_equalObj (const TObject *t1, const TObject *t2); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.133 2001/02/14 17:19:28 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.134 2001/02/14 17:38:45 roberto Exp roberto $ |
3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -690,8 +690,8 @@ static BinOpr getbinopr (int op) { | |||
690 | 690 | ||
691 | 691 | ||
692 | static const struct { | 692 | static const struct { |
693 | unsigned char left; /* left priority for each binary operator */ | 693 | lu_byte left; /* left priority for each binary operator */ |
694 | unsigned char right; /* right priority */ | 694 | lu_byte right; /* right priority */ |
695 | } priority[] = { /* ORDER OPR */ | 695 | } priority[] = { /* ORDER OPR */ |
696 | {5, 5}, {5, 5}, {6, 6}, {6, 6}, /* arithmetic */ | 696 | {5, 5}, {5, 5}, {6, 6}, {6, 6}, /* arithmetic */ |
697 | {9, 8}, {4, 3}, /* power and concat (right associative) */ | 697 | {9, 8}, {4, 3}, /* power and concat (right associative) */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 1.49 2001/02/01 17:40:48 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 1.50 2001/02/02 15:13:05 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -55,7 +55,7 @@ struct TM; /* defined in ltm.h */ | |||
55 | 55 | ||
56 | typedef struct stringtable { | 56 | typedef struct stringtable { |
57 | int size; | 57 | int size; |
58 | luint32 nuse; /* number of elements */ | 58 | ls_nstr nuse; /* number of elements */ |
59 | TString **hash; | 59 | TString **hash; |
60 | } stringtable; | 60 | } stringtable; |
61 | 61 | ||
@@ -79,8 +79,8 @@ typedef struct global_State { | |||
79 | int nref; /* first unused element in refArray */ | 79 | int nref; /* first unused element in refArray */ |
80 | int sizeref; /* size of refArray */ | 80 | int sizeref; /* size of refArray */ |
81 | int refFree; /* list of free positions in refArray */ | 81 | int refFree; /* list of free positions in refArray */ |
82 | mem_int GCthreshold; | 82 | lu_mem GCthreshold; |
83 | mem_int nblocks; /* number of `bytes' currently allocated */ | 83 | lu_mem nblocks; /* number of `bytes' currently allocated */ |
84 | } global_State; | 84 | } global_State; |
85 | 85 | ||
86 | 86 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 1.57 2001/02/09 20:22:29 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.58 2001/02/09 20:29:33 roberto Exp roberto $ |
3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -39,7 +39,7 @@ void luaS_resize (lua_State *L, stringtable *tb, int newsize) { | |||
39 | TString *p = tb->hash[i]; | 39 | TString *p = tb->hash[i]; |
40 | while (p) { /* for each node in the list */ | 40 | while (p) { /* for each node in the list */ |
41 | TString *next = p->nexthash; /* save next */ | 41 | TString *next = p->nexthash; /* save next */ |
42 | luint32 h = (tb == &G(L)->strt) ? p->u.s.hash : IntPoint(p->u.d.value); | 42 | lu_hash h = (tb == &G(L)->strt) ? p->u.s.hash : IntPoint(p->u.d.value); |
43 | int h1 = lmod(h, newsize); /* new position */ | 43 | int h1 = lmod(h, newsize); /* new position */ |
44 | lua_assert((int)(h%newsize) == lmod(h, newsize)); | 44 | lua_assert((int)(h%newsize) == lmod(h, newsize)); |
45 | p->nexthash = newhash[h1]; /* chain it in new position */ | 45 | p->nexthash = newhash[h1]; /* chain it in new position */ |
@@ -57,7 +57,7 @@ static void newentry (lua_State *L, stringtable *tb, TString *ts, int h) { | |||
57 | ts->nexthash = tb->hash[h]; /* chain new entry */ | 57 | ts->nexthash = tb->hash[h]; /* chain new entry */ |
58 | tb->hash[h] = ts; | 58 | tb->hash[h] = ts; |
59 | tb->nuse++; | 59 | tb->nuse++; |
60 | if (tb->nuse > (luint32)tb->size && tb->size < MAX_INT/2) /* too crowded? */ | 60 | if (tb->nuse > (ls_nstr)tb->size && tb->size <= MAX_INT/2) /* too crowded? */ |
61 | luaS_resize(L, tb, tb->size*2); | 61 | luaS_resize(L, tb, tb->size*2); |
62 | } | 62 | } |
63 | 63 | ||
@@ -65,7 +65,7 @@ static void newentry (lua_State *L, stringtable *tb, TString *ts, int h) { | |||
65 | 65 | ||
66 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | 66 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { |
67 | TString *ts; | 67 | TString *ts; |
68 | luint32 h = l; /* seed */ | 68 | lu_hash h = l; /* seed */ |
69 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ | 69 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ |
70 | size_t l1; | 70 | size_t l1; |
71 | for (l1=l; l1>=step; l1-=step) /* compute hash */ | 71 | for (l1=l; l1>=step; l1-=step) /* compute hash */ |
@@ -81,7 +81,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
81 | ts->len = l; | 81 | ts->len = l; |
82 | ts->u.s.hash = h; | 82 | ts->u.s.hash = h; |
83 | ts->u.s.constindex = 0; | 83 | ts->u.s.constindex = 0; |
84 | memcpy(getstr(ts), str, l); | 84 | memcpy(getstr(ts), str, l*sizeof(char)); |
85 | getstr(ts)[l] = 0; /* ending 0 */ | 85 | getstr(ts)[l] = 0; /* ending 0 */ |
86 | newentry(L, &G(L)->strt, ts, lmod(h, G(L)->strt.size)); /* insert it */ | 86 | newentry(L, &G(L)->strt, ts, lmod(h, G(L)->strt.size)); /* insert it */ |
87 | return ts; | 87 | return ts; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.h,v 1.28 2001/02/09 19:53:16 roberto Exp roberto $ | 2 | ** $Id: lstring.h,v 1.29 2001/02/09 20:22:29 roberto Exp roberto $ |
3 | ** String table (keep all strings handled by Lua) | 3 | ** String table (keep all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -21,12 +21,14 @@ | |||
21 | #define RESERVEDMARK 3 | 21 | #define RESERVEDMARK 3 |
22 | 22 | ||
23 | 23 | ||
24 | #define sizestring(l) ((luint32)sizeof(union L_UTString)+(l)+1) | 24 | #define sizestring(l) ((lu_mem)sizeof(union L_UTString)+ \ |
25 | ((lu_mem)(l)+1)*sizeof(char)) | ||
25 | 26 | ||
26 | #define sizeudata(l) ((luint32)sizeof(union L_UTString)+(l)) | 27 | #define sizeudata(l) ((lu_mem)sizeof(union L_UTString)+(l)) |
27 | 28 | ||
28 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) | 29 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) |
29 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, (sizeof(s))-1)) | 30 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ |
31 | (sizeof(s)/sizeof(char))-1)) | ||
30 | 32 | ||
31 | void luaS_init (lua_State *L); | 33 | void luaS_init (lua_State *L); |
32 | void luaS_resize (lua_State *L, stringtable *tb, int newsize); | 34 | void luaS_resize (lua_State *L, stringtable *tb, int newsize); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 1.74 2001/01/30 19:48:37 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.75 2001/02/01 17:40:48 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 | #define TagDefault LUA_TTABLE | 31 | #define TagDefault LUA_TTABLE |
32 | 32 | ||
33 | 33 | ||
34 | #define hashnum(t,n) (&t->node[lmod((luint32)(lint32)(n), t->size)]) | 34 | #define hashnum(t,n) (&t->node[lmod((lu_hash)(ls_hash)(n), t->size)]) |
35 | #define hashstr(t,str) (&t->node[lmod((str)->u.s.hash, t->size)]) | 35 | #define hashstr(t,str) (&t->node[lmod((str)->u.s.hash, t->size)]) |
36 | #define hashpointer(t,p) (&t->node[lmod(IntPoint(p), t->size)]) | 36 | #define hashpointer(t,p) (&t->node[lmod(IntPoint(p), t->size)]) |
37 | 37 | ||
@@ -81,12 +81,26 @@ int luaH_nexti (Hash *t, int i) { | |||
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | ||
84 | static void setnodevector (lua_State *L, Hash *t, luint32 size) { | 84 | #define check_grow(L, p, n) \ |
85 | if ((p) >= MAX_INT/(n)) luaD_error(L, "table overflow"); | ||
86 | |||
87 | /* | ||
88 | ** returns smaller power of 2 larger than `n' (minimum is MINPOWER2) | ||
89 | */ | ||
90 | static int power2 (lua_State *L, int n) { | ||
91 | int p = MINPOWER2; | ||
92 | while (p <= n) { | ||
93 | check_grow(L, p, 2); | ||
94 | p *= 2; | ||
95 | } | ||
96 | return p; | ||
97 | } | ||
98 | |||
99 | |||
100 | static void setnodevector (lua_State *L, Hash *t, int size) { | ||
85 | int i; | 101 | int i; |
86 | if (size > MAX_INT) | ||
87 | luaD_error(L, "table overflow"); | ||
88 | t->node = luaM_newvector(L, size, Node); | 102 | t->node = luaM_newvector(L, size, Node); |
89 | for (i=0; i<(int)size; i++) { | 103 | for (i=0; i<size; i++) { |
90 | t->node[i].next = NULL; | 104 | t->node[i].next = NULL; |
91 | t->node[i].key_tt = LUA_TNIL; | 105 | t->node[i].key_tt = LUA_TNIL; |
92 | setnilvalue(&t->node[i].val); | 106 | setnilvalue(&t->node[i].val); |
@@ -104,7 +118,7 @@ Hash *luaH_new (lua_State *L, int size) { | |||
104 | t->mark = t; | 118 | t->mark = t; |
105 | t->size = 0; | 119 | t->size = 0; |
106 | t->node = NULL; | 120 | t->node = NULL; |
107 | setnodevector(L, t, luaO_power2(size)); | 121 | setnodevector(L, t, power2(L, size)); |
108 | return t; | 122 | return t; |
109 | } | 123 | } |
110 | 124 | ||
@@ -134,13 +148,15 @@ static void rehash (lua_State *L, Hash *t) { | |||
134 | int nelems = numuse(t); | 148 | int nelems = numuse(t); |
135 | int i; | 149 | int i; |
136 | lua_assert(nelems<=oldsize); | 150 | lua_assert(nelems<=oldsize); |
137 | if (nelems >= oldsize-oldsize/4) /* using more than 3/4? */ | 151 | if (nelems >= oldsize-oldsize/4) { /* using more than 3/4? */ |
138 | setnodevector(L, t, (luint32)oldsize*2); | 152 | check_grow(L, oldsize, 2); |
153 | setnodevector(L, t, oldsize*2); /* grow array */ | ||
154 | } | ||
139 | else if (nelems <= oldsize/4 && /* less than 1/4? */ | 155 | else if (nelems <= oldsize/4 && /* less than 1/4? */ |
140 | oldsize > MINPOWER2) | 156 | oldsize > MINPOWER2) |
141 | setnodevector(L, t, oldsize/2); | 157 | setnodevector(L, t, oldsize/2); /* shrink array */ |
142 | else | 158 | else |
143 | setnodevector(L, t, oldsize); | 159 | setnodevector(L, t, oldsize); /* just rehash; keep the same size */ |
144 | for (i=0; i<oldsize; i++) { | 160 | for (i=0; i<oldsize; i++) { |
145 | Node *old = nold+i; | 161 | Node *old = nold+i; |
146 | if (ttype(&old->val) != LUA_TNIL) { | 162 | if (ttype(&old->val) != LUA_TNIL) { |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 1.65 2001/02/02 15:13:05 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.66 2001/02/09 20:22:29 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -53,7 +53,7 @@ static int luaI_checkevent (lua_State *L, const char *name, int t) { | |||
53 | * 'placeholder' for "default" fallbacks | 53 | * 'placeholder' for "default" fallbacks |
54 | */ | 54 | */ |
55 | /* ORDER LUA_T, ORDER TM */ | 55 | /* ORDER LUA_T, ORDER TM */ |
56 | static const unsigned char luaT_validevents[NUM_TAGS][TM_N] = { | 56 | static const lu_byte luaT_validevents[NUM_TAGS][TM_N] = { |
57 | {1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_TUSERDATA */ | 57 | {1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_TUSERDATA */ |
58 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_TNIL */ | 58 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_TNIL */ |
59 | {1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, /* LUA_TNUMBER */ | 59 | {1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, /* LUA_TNUMBER */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.59 2001/02/06 18:18:58 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.60 2001/02/14 17:19:01 roberto Exp roberto $ |
3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -173,20 +173,24 @@ static int file_input (const char *argv) { | |||
173 | #endif | 173 | #endif |
174 | 174 | ||
175 | 175 | ||
176 | static void show_prompt (void) { | 176 | static const char *get_prompt (int prompt) { |
177 | const char *s; | 177 | if (!prompt) |
178 | lua_getglobal(L, "_PROMPT"); | 178 | return ""; |
179 | s = lua_tostring(L, -1); | 179 | else { |
180 | if (!s) s = PROMPT; | 180 | const char *s; |
181 | fputs(s, stdout); | 181 | lua_getglobal(L, "_PROMPT"); |
182 | lua_pop(L, 1); /* remove global */ | 182 | s = lua_tostring(L, -1); |
183 | if (!s) s = PROMPT; | ||
184 | lua_pop(L, 1); /* remove global */ | ||
185 | return s; | ||
186 | } | ||
183 | } | 187 | } |
184 | 188 | ||
185 | 189 | ||
186 | static void manual_input (int version, int prompt) { | 190 | static void manual_input (int version, int prompt) { |
187 | if (version) print_version(); | 191 | if (version) print_version(); |
188 | for (;;) { | 192 | for (;;) { |
189 | if (prompt) show_prompt(); | 193 | fputs(get_prompt(prompt), stdout); /* show prompt */ |
190 | for(;;) { | 194 | for(;;) { |
191 | char buffer[MAXINPUT]; | 195 | char buffer[MAXINPUT]; |
192 | size_t l; | 196 | size_t l; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.85 2001/01/26 11:45:51 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.86 2001/02/09 19:53:16 roberto Exp roberto $ |
3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil | 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil |
5 | ** e-mail: lua@tecgraf.puc-rio.br | 5 | ** e-mail: lua@tecgraf.puc-rio.br |
@@ -221,7 +221,8 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size); | |||
221 | 221 | ||
222 | #define lua_getregistry(L) lua_getref(L, LUA_REFREGISTRY) | 222 | #define lua_getregistry(L) lua_getref(L, LUA_REFREGISTRY) |
223 | 223 | ||
224 | #define lua_pushliteral(L, s) lua_pushlstring(L, "" s, (sizeof(s))-1) | 224 | #define lua_pushliteral(L, s) lua_pushlstring(L, "" s, \ |
225 | (sizeof(s)/sizeof(char))-1) | ||
225 | 226 | ||
226 | 227 | ||
227 | 228 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.168 2001/02/09 20:22:29 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.169 2001/02/12 13:04:19 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -273,8 +273,7 @@ void luaV_strconc (lua_State *L, int total, StkId top) { | |||
273 | } | 273 | } |
274 | else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ | 274 | else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ |
275 | /* at least two string values; get as many as possible */ | 275 | /* at least two string values; get as many as possible */ |
276 | luint32 tl = (luint32)tsvalue(top-1)->len + | 276 | lu_mem tl = (lu_mem)tsvalue(top-1)->len + (lu_mem)tsvalue(top-2)->len; |
277 | (luint32)tsvalue(top-2)->len; | ||
278 | char *buffer; | 277 | char *buffer; |
279 | int i; | 278 | int i; |
280 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ | 279 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ |