diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-04-28 16:26:16 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-04-28 16:26:16 -0300 |
| commit | 572a69df78b2636642e9c520ebc8c1d2efa16afe (patch) | |
| tree | 0e1e6f042e63f1d0e8aabc692692f2fcc42efb75 | |
| parent | 943c82b37622bd2321d4fbb361d99f4495ceed2f (diff) | |
| download | lua-572a69df78b2636642e9c520ebc8c1d2efa16afe.tar.gz lua-572a69df78b2636642e9c520ebc8c1d2efa16afe.tar.bz2 lua-572a69df78b2636642e9c520ebc8c1d2efa16afe.zip | |
Lua does not need all those different types...
| -rw-r--r-- | lgc.c | 4 | ||||
| -rw-r--r-- | llimits.h | 31 | ||||
| -rw-r--r-- | lobject.h | 4 | ||||
| -rw-r--r-- | lstate.h | 4 | ||||
| -rw-r--r-- | lstring.c | 11 | ||||
| -rw-r--r-- | ltable.c | 4 |
6 files changed, 32 insertions, 26 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 1.170 2003/03/18 12:50:04 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.171 2003/04/03 13:35:34 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 | */ |
| @@ -389,7 +389,7 @@ static void sweepstrings (lua_State *L, int all) { | |||
| 389 | 389 | ||
| 390 | static void checkSizes (lua_State *L) { | 390 | static void checkSizes (lua_State *L) { |
| 391 | /* check size of string hash */ | 391 | /* check size of string hash */ |
| 392 | if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) && | 392 | if (G(L)->strt.nuse < cast(lu_int32, G(L)->strt.size/4) && |
| 393 | G(L)->strt.size > MINSTRTABSIZE*2) | 393 | G(L)->strt.size > MINSTRTABSIZE*2) |
| 394 | luaS_resize(L, G(L)->strt.size/2); /* table is too big */ | 394 | luaS_resize(L, G(L)->strt.size/2); /* table is too big */ |
| 395 | /* check size of buffer */ | 395 | /* check size of buffer */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llimits.h,v 1.51 2002/11/25 17:47:13 roberto Exp roberto $ | 2 | ** $Id: llimits.h,v 1.52 2003/02/20 19:33:23 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,20 +40,25 @@ | |||
| 40 | ** any machine, but may not be optimal. | 40 | ** any machine, but may not be optimal. |
| 41 | */ | 41 | */ |
| 42 | 42 | ||
| 43 | /* an unsigned integer to hold hash values */ | ||
| 44 | typedef unsigned int lu_hash; | ||
| 45 | /* its signed equivalent */ | ||
| 46 | typedef int ls_hash; | ||
| 47 | 43 | ||
| 48 | /* an unsigned integer big enough to count the total memory used by Lua; */ | 44 | /* |
| 49 | /* it should be at least as large as size_t */ | 45 | ** an unsigned integer with at least 32 bits |
| 50 | typedef unsigned long lu_mem; | 46 | */ |
| 47 | #ifndef LUA_UINT32 | ||
| 48 | #define LUA_UINT32 unsigned long | ||
| 49 | #endif | ||
| 50 | |||
| 51 | typedef LUA_UINT32 lu_int32; | ||
| 51 | 52 | ||
| 52 | #define MAX_LUMEM ULONG_MAX | ||
| 53 | 53 | ||
| 54 | /* | ||
| 55 | ** an unsigned integer big enough to count the total memory used by Lua; | ||
| 56 | ** it should be at least as large as `size_t' | ||
| 57 | */ | ||
| 58 | typedef lu_int32 lu_mem; | ||
| 59 | |||
| 60 | #define MAX_LUMEM ULONG_MAX | ||
| 54 | 61 | ||
| 55 | /* an integer big enough to count the number of strings in use */ | ||
| 56 | typedef long ls_nstr; | ||
| 57 | 62 | ||
| 58 | /* chars used as small naturals (so that `char' is reserved for characters) */ | 63 | /* chars used as small naturals (so that `char' is reserved for characters) */ |
| 59 | typedef unsigned char lu_byte; | 64 | typedef unsigned char lu_byte; |
| @@ -69,7 +74,7 @@ typedef unsigned char lu_byte; | |||
| 69 | ** this is for hashing only; there is no problem if the integer | 74 | ** this is for hashing only; there is no problem if the integer |
| 70 | ** cannot hold the whole pointer value | 75 | ** cannot hold the whole pointer value |
| 71 | */ | 76 | */ |
| 72 | #define IntPoint(p) ((lu_hash)(p)) | 77 | #define IntPoint(p) ((unsigned int)(p)) |
| 73 | 78 | ||
| 74 | 79 | ||
| 75 | 80 | ||
| @@ -114,7 +119,7 @@ typedef LUA_UACNUMBER l_uacNumber; | |||
| 114 | ** type for virtual-machine instructions | 119 | ** type for virtual-machine instructions |
| 115 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) | 120 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) |
| 116 | */ | 121 | */ |
| 117 | typedef unsigned long Instruction; | 122 | typedef lu_int32 Instruction; |
| 118 | 123 | ||
| 119 | 124 | ||
| 120 | /* maximum depth for calls (unsigned short) */ | 125 | /* maximum depth for calls (unsigned short) */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 1.158 2003/02/18 16:02:56 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.159 2003/03/18 12:50:04 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 | */ |
| @@ -181,7 +181,7 @@ typedef union TString { | |||
| 181 | struct { | 181 | struct { |
| 182 | CommonHeader; | 182 | CommonHeader; |
| 183 | lu_byte reserved; | 183 | lu_byte reserved; |
| 184 | lu_hash hash; | 184 | unsigned int hash; |
| 185 | size_t len; | 185 | size_t len; |
| 186 | } tsv; | 186 | } tsv; |
| 187 | } TString; | 187 | } TString; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.h,v 1.108 2002/11/25 17:47:13 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 1.109 2003/02/27 11:52:30 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 | */ |
| @@ -64,7 +64,7 @@ struct lua_longjmp; /* defined in ldo.c */ | |||
| 64 | 64 | ||
| 65 | typedef struct stringtable { | 65 | typedef struct stringtable { |
| 66 | GCObject **hash; | 66 | GCObject **hash; |
| 67 | ls_nstr nuse; /* number of elements */ | 67 | lu_int32 nuse; /* number of elements */ |
| 68 | int size; | 68 | int size; |
| 69 | } stringtable; | 69 | } stringtable; |
| 70 | 70 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 1.77 2002/11/13 11:32:26 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.78 2002/12/04 17:38:31 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 | */ |
| @@ -34,7 +34,7 @@ void luaS_resize (lua_State *L, int newsize) { | |||
| 34 | GCObject *p = tb->hash[i]; | 34 | GCObject *p = tb->hash[i]; |
| 35 | while (p) { /* for each node in the list */ | 35 | while (p) { /* for each node in the list */ |
| 36 | GCObject *next = p->gch.next; /* save next */ | 36 | GCObject *next = p->gch.next; /* save next */ |
| 37 | lu_hash h = gcotots(p)->tsv.hash; | 37 | unsigned int h = gcotots(p)->tsv.hash; |
| 38 | int h1 = lmod(h, newsize); /* new position */ | 38 | int h1 = lmod(h, newsize); /* new position */ |
| 39 | lua_assert(cast(int, h%newsize) == lmod(h, newsize)); | 39 | lua_assert(cast(int, h%newsize) == lmod(h, newsize)); |
| 40 | p->gch.next = newhash[h1]; /* chain it */ | 40 | p->gch.next = newhash[h1]; /* chain it */ |
| @@ -48,7 +48,8 @@ void luaS_resize (lua_State *L, int newsize) { | |||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | 50 | ||
| 51 | static TString *newlstr (lua_State *L, const char *str, size_t l, lu_hash h) { | 51 | static TString *newlstr (lua_State *L, const char *str, size_t l, |
| 52 | unsigned int h) { | ||
| 52 | TString *ts = cast(TString *, luaM_malloc(L, sizestring(l))); | 53 | TString *ts = cast(TString *, luaM_malloc(L, sizestring(l))); |
| 53 | stringtable *tb; | 54 | stringtable *tb; |
| 54 | ts->tsv.len = l; | 55 | ts->tsv.len = l; |
| @@ -63,7 +64,7 @@ static TString *newlstr (lua_State *L, const char *str, size_t l, lu_hash h) { | |||
| 63 | ts->tsv.next = tb->hash[h]; /* chain new entry */ | 64 | ts->tsv.next = tb->hash[h]; /* chain new entry */ |
| 64 | tb->hash[h] = valtogco(ts); | 65 | tb->hash[h] = valtogco(ts); |
| 65 | tb->nuse++; | 66 | tb->nuse++; |
| 66 | if (tb->nuse > cast(ls_nstr, tb->size) && tb->size <= MAX_INT/2) | 67 | if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) |
| 67 | luaS_resize(L, tb->size*2); /* too crowded */ | 68 | luaS_resize(L, tb->size*2); /* too crowded */ |
| 68 | return ts; | 69 | return ts; |
| 69 | } | 70 | } |
| @@ -71,7 +72,7 @@ static TString *newlstr (lua_State *L, const char *str, size_t l, lu_hash h) { | |||
| 71 | 72 | ||
| 72 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | 73 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { |
| 73 | GCObject *o; | 74 | GCObject *o; |
| 74 | lu_hash h = (lu_hash)l; /* seed */ | 75 | unsigned int h = cast(unsigned int, l); /* seed */ |
| 75 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ | 76 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ |
| 76 | size_t l1; | 77 | size_t l1; |
| 77 | for (l1=l; l1>=step; l1-=step) /* compute hash */ | 78 | for (l1=l; l1>=step; l1-=step) /* compute hash */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 1.132 2003/04/03 13:35:34 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.133 2003/04/28 13:31:46 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 | */ |
| @@ -85,7 +85,7 @@ static Node *hashnum (const Table *t, lua_Number n) { | |||
| 85 | lua_assert(sizeof(a) <= sizeof(n)); | 85 | lua_assert(sizeof(a) <= sizeof(n)); |
| 86 | memcpy(a, &n, sizeof(a)); | 86 | memcpy(a, &n, sizeof(a)); |
| 87 | for (i = 1; i < numints; i++) a[0] += a[i]; | 87 | for (i = 1; i < numints; i++) a[0] += a[i]; |
| 88 | return hashmod(t, cast(lu_hash, a[0])); | 88 | return hashmod(t, a[0]); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | 91 | ||
