mirror of https://github.com/rusefi/lua.git
better separation between basic types
This commit is contained in:
parent
27600fe87a
commit
099442c41f
4
lapi.c
4
lapi.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lapi.c,v 1.129 2001/02/13 16:17:53 roberto Exp roberto $
|
||||
** $Id: lapi.c,v 1.130 2001/02/14 17:04:11 roberto Exp roberto $
|
||||
** Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -549,7 +549,7 @@ LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) {
|
|||
|
||||
/* GC values are expressed in Kbytes: #bytes/2^10 */
|
||||
#define GCscale(x) ((int)((x)>>10))
|
||||
#define GCunscale(x) ((mem_int)(x)<<10)
|
||||
#define GCunscale(x) ((lu_mem)(x)<<10)
|
||||
|
||||
LUA_API int lua_getgcthreshold (lua_State *L) {
|
||||
int threshold;
|
||||
|
|
8
lcode.h
8
lcode.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lcode.h,v 1.18 2000/12/04 18:33:40 roberto Exp roberto $
|
||||
** $Id: lcode.h,v 1.19 2001/01/29 15:26:40 roberto Exp roberto $
|
||||
** Code generator for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -39,9 +39,9 @@ enum Mode {iO, iU, iS, iAB}; /* instruction format */
|
|||
#define VD 100 /* flag for variable delta */
|
||||
|
||||
typedef struct OpProperties {
|
||||
char mode;
|
||||
unsigned char push;
|
||||
unsigned char pop;
|
||||
lu_byte mode;
|
||||
lu_byte push;
|
||||
lu_byte pop;
|
||||
} OpProperties;
|
||||
|
||||
extern const OpProperties luaK_opproperties[];
|
||||
|
|
8
ldebug.c
8
ldebug.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: ldebug.c,v 1.63 2001/02/12 19:54:28 roberto Exp roberto $
|
||||
** $Id: ldebug.c,v 1.64 2001/02/16 17:58:27 roberto Exp roberto $
|
||||
** Debug Interface
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -347,7 +347,7 @@ static int precheck (const Proto *pt) {
|
|||
|
||||
#define checkjump(pt,sl,top,pc) if (!checkjump_aux(pt,sl,top,pc)) return 0;
|
||||
|
||||
static int checkjump_aux (const Proto *pt, unsigned char *sl, int top, int pc) {
|
||||
static int checkjump_aux (const Proto *pt, lu_byte *sl, int top, int pc) {
|
||||
check(0 <= pc && pc < pt->sizecode);
|
||||
if (sl == NULL) return 1; /* not full checking */
|
||||
if (sl[pc] == SL_EMPTY)
|
||||
|
@ -361,12 +361,12 @@ static int checkjump_aux (const Proto *pt, unsigned char *sl, int top, int pc) {
|
|||
static Instruction luaG_symbexec (lua_State *L, const Proto *pt,
|
||||
int lastpc, int stackpos) {
|
||||
int stack[MAXSTACK]; /* stores last instruction that changed a stack entry */
|
||||
unsigned char *sl = NULL;
|
||||
lu_byte *sl = NULL;
|
||||
int top;
|
||||
int pc;
|
||||
if (stackpos < 0) { /* full check? */
|
||||
int i;
|
||||
sl = (unsigned char *)luaO_openspace(L, pt->sizecode);
|
||||
sl = (lu_byte *)luaO_openspace(L, pt->sizecode);
|
||||
for (i=0; i<pt->sizecode; i++) /* initialize stack-level array */
|
||||
sl[i] = SL_EMPTY;
|
||||
check(precheck(pt));
|
||||
|
|
4
ldo.c
4
ldo.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: ldo.c,v 1.122 2001/02/02 16:23:20 roberto Exp roberto $
|
||||
** $Id: ldo.c,v 1.123 2001/02/07 18:13:49 roberto Exp roberto $
|
||||
** Stack and Call structure of Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -240,7 +240,7 @@ static void f_parser (lua_State *L, void *ud) {
|
|||
|
||||
static int protectedparser (lua_State *L, ZIO *z, int bin) {
|
||||
struct SParser p;
|
||||
mem_int old_blocks;
|
||||
lu_mem old_blocks;
|
||||
int status;
|
||||
LUA_LOCK(L);
|
||||
p.z = z; p.bin = bin;
|
||||
|
|
4
lgc.c
4
lgc.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lgc.c,v 1.87 2001/02/02 16:32:00 roberto Exp roberto $
|
||||
** $Id: lgc.c,v 1.88 2001/02/07 18:13:49 roberto Exp roberto $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -274,7 +274,7 @@ static void collecttable (lua_State *L) {
|
|||
|
||||
|
||||
static void checktab (lua_State *L, stringtable *tb) {
|
||||
if (tb->nuse < (luint32)(tb->size/4) && tb->size > MINPOWER2)
|
||||
if (tb->nuse < (ls_nstr)(tb->size/4) && tb->size > MINPOWER2)
|
||||
luaS_resize(L, tb, tb->size/2); /* table is too big */
|
||||
}
|
||||
|
||||
|
|
34
llimits.h
34
llimits.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: llimits.h,v 1.21 2000/12/04 18:33:40 roberto Exp roberto $
|
||||
** $Id: llimits.h,v 1.22 2001/02/09 16:24:44 roberto Exp roberto $
|
||||
** Limits, basic types, and some other "installation-dependent" definitions
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -40,11 +40,27 @@
|
|||
|
||||
|
||||
|
||||
typedef unsigned long luint32; /* unsigned int with at least 32 bits */
|
||||
typedef long lint32; /* signed int with at least 32 bits */
|
||||
/*
|
||||
** the following types define integer types for values that may not
|
||||
** fit in a "small int" (16 bits), but may waste space in a
|
||||
** "large long" (64 bits). The current definitions should work in
|
||||
** any machine, but may not be optimal.
|
||||
*/
|
||||
|
||||
/* an unsigned integer to hold hash values */
|
||||
typedef unsigned int lu_hash;
|
||||
/* its signed equivalent */
|
||||
typedef int ls_hash;
|
||||
|
||||
/* an unsigned integer big enough to count the total memory used by Lua */
|
||||
typedef unsigned long mem_int;
|
||||
typedef unsigned long lu_mem;
|
||||
|
||||
/* an integer big enough to count the number of strings in use */
|
||||
typedef long ls_nstr;
|
||||
|
||||
|
||||
/* chars used as small naturals (so that `char' is reserved for characteres) */
|
||||
typedef unsigned char lu_byte;
|
||||
|
||||
|
||||
#define MAX_SIZET ((size_t)(~(size_t)0)-2)
|
||||
|
@ -53,10 +69,12 @@ typedef unsigned long mem_int;
|
|||
#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
|
||||
|
||||
/*
|
||||
** conversion of pointer to int (for hashing only)
|
||||
** conversion of pointer to integer
|
||||
** this is for hashing only; there is no problem if the integer
|
||||
** cannot hold the whole pointer value
|
||||
** (the shift removes bits that are usually 0 because of alignment)
|
||||
*/
|
||||
#define IntPoint(p) (((luint32)(p)) >> 3)
|
||||
#define IntPoint(p) ((((lu_hash)(p)) >> 4) ^ (lu_hash)(p))
|
||||
|
||||
|
||||
|
||||
|
@ -71,7 +89,7 @@ typedef unsigned long mem_int;
|
|||
|
||||
|
||||
/* type to ensure maximum alignment */
|
||||
union L_Umaxalign { double d; char *s; long l; };
|
||||
union L_Umaxalign { double d; void *s; long l; };
|
||||
|
||||
|
||||
|
||||
|
@ -81,7 +99,7 @@ union L_Umaxalign { double d; char *s; long l; };
|
|||
** For a very small machine, you may change that to 2 bytes (and adjust
|
||||
** the following limits accordingly)
|
||||
*/
|
||||
typedef luint32 Instruction;
|
||||
typedef unsigned long Instruction;
|
||||
|
||||
|
||||
/*
|
||||
|
|
8
lmem.c
8
lmem.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lmem.c,v 1.45 2001/02/05 19:08:01 roberto Exp roberto $
|
||||
** $Id: lmem.c,v 1.46 2001/02/06 16:01:29 roberto Exp roberto $
|
||||
** Interface to Memory Manager
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -33,8 +33,8 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems,
|
|||
newsize = limit; /* still have at least MINPOWER2 free places */
|
||||
else luaD_error(L, errormsg);
|
||||
}
|
||||
newblock = luaM_realloc(L, block, (luint32)(*size)*(luint32)size_elems,
|
||||
(luint32)newsize*(luint32)size_elems);
|
||||
newblock = luaM_realloc(L, block, (lu_mem)(*size)*(lu_mem)size_elems,
|
||||
(lu_mem)newsize*(lu_mem)size_elems);
|
||||
*size = newsize; /* update only when everything else is OK */
|
||||
return newblock;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems,
|
|||
/*
|
||||
** generic allocation routine.
|
||||
*/
|
||||
void *luaM_realloc (lua_State *L, void *block, luint32 oldsize, luint32 size) {
|
||||
void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) {
|
||||
if (size == 0) {
|
||||
l_free(block, oldsize); /* block may be NULL; that is OK for free */
|
||||
block = NULL;
|
||||
|
|
13
lmem.h
13
lmem.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lmem.h,v 1.19 2000/12/28 12:55:41 roberto Exp roberto $
|
||||
** $Id: lmem.h,v 1.20 2001/02/02 15:13:05 roberto Exp roberto $
|
||||
** Interface to Memory Manager
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -13,8 +13,7 @@
|
|||
#include "llimits.h"
|
||||
#include "lua.h"
|
||||
|
||||
void *luaM_realloc (lua_State *L, void *oldblock, luint32 oldsize,
|
||||
luint32 size);
|
||||
void *luaM_realloc (lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size);
|
||||
|
||||
void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem,
|
||||
int limit, const char *errormsg);
|
||||
|
@ -22,20 +21,20 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem,
|
|||
#define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0)
|
||||
#define luaM_freelem(L, b, t) luaM_realloc(L, (b), sizeof(t), 0)
|
||||
#define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \
|
||||
((luint32)(n)*(luint32)sizeof(t)), 0)
|
||||
((lu_mem)(n)*(lu_mem)sizeof(t)), 0)
|
||||
|
||||
#define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t))
|
||||
#define luaM_new(L, t) ((t *)luaM_malloc(L, sizeof(t)))
|
||||
#define luaM_newvector(L, n,t) ((t *)luaM_malloc(L, \
|
||||
(luint32)(n)*(luint32)sizeof(t)))
|
||||
(lu_mem)(n)*(lu_mem)sizeof(t)))
|
||||
|
||||
#define luaM_growvector(L,v,nelems,size,t,limit,e) \
|
||||
if (((nelems)+1) > (size)) \
|
||||
((v)=(t *)luaM_growaux(L,v,&(size),sizeof(t),limit,e))
|
||||
|
||||
#define luaM_reallocvector(L, v,oldn,n,t) \
|
||||
((v)=(t *)luaM_realloc(L, v,(luint32)(oldn)*(luint32)sizeof(t), \
|
||||
(luint32)(n)*(luint32)sizeof(t)))
|
||||
((v)=(t *)luaM_realloc(L, v,(lu_mem)(oldn)*(lu_mem)sizeof(t), \
|
||||
(lu_mem)(n)*(lu_mem)sizeof(t)))
|
||||
|
||||
|
||||
#endif
|
||||
|
|
12
lobject.c
12
lobject.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lobject.c,v 1.63 2001/01/29 19:34:02 roberto Exp roberto $
|
||||
** $Id: lobject.c,v 1.64 2001/02/02 15:13:05 roberto Exp roberto $
|
||||
** Some generic functions over Lua objects
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -22,16 +22,6 @@
|
|||
const TObject luaO_nilobject = {LUA_TNIL, {NULL}};
|
||||
|
||||
|
||||
/*
|
||||
** returns smaller power of 2 larger than `n' (minimum is MINPOWER2)
|
||||
*/
|
||||
luint32 luaO_power2 (luint32 n) {
|
||||
luint32 p = MINPOWER2;
|
||||
while (p<=n) p<<=1;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
int luaO_equalObj (const TObject *t1, const TObject *t2) {
|
||||
if (ttype(t1) != ttype(t2)) return 0;
|
||||
switch (ttype(t1)) {
|
||||
|
|
10
lobject.h
10
lobject.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lobject.h,v 1.94 2001/02/02 16:32:00 roberto Exp roberto $
|
||||
** $Id: lobject.h,v 1.95 2001/02/09 20:22:29 roberto Exp roberto $
|
||||
** Type definitions for Lua objects
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -93,7 +93,7 @@ typedef struct lua_TObject {
|
|||
typedef struct TString {
|
||||
union {
|
||||
struct { /* for strings */
|
||||
luint32 hash;
|
||||
lu_hash hash;
|
||||
int constindex; /* hint to reuse constants */
|
||||
} s;
|
||||
struct { /* for userdata */
|
||||
|
@ -160,13 +160,13 @@ typedef struct LocVar {
|
|||
*/
|
||||
typedef struct Closure {
|
||||
int isC; /* 0 for Lua functions, 1 for C functions */
|
||||
int nupvalues;
|
||||
union {
|
||||
lua_CFunction c; /* C functions */
|
||||
struct Proto *l; /* Lua functions */
|
||||
} f;
|
||||
struct Closure *next;
|
||||
struct Closure *mark; /* marked closures (point to itself when not marked) */
|
||||
int nupvalues;
|
||||
TObject upvalue[1];
|
||||
} Closure;
|
||||
|
||||
|
@ -199,7 +199,8 @@ typedef struct Hash {
|
|||
|
||||
|
||||
/*
|
||||
** "module" operation (size is always a power of 2) */
|
||||
** "module" operation for hashing (size is always a power of 2)
|
||||
*/
|
||||
#define lmod(s,size) ((int)((s) & ((size)-1)))
|
||||
|
||||
|
||||
|
@ -218,7 +219,6 @@ typedef struct CallInfo {
|
|||
extern const TObject luaO_nilobject;
|
||||
|
||||
|
||||
luint32 luaO_power2 (luint32 n);
|
||||
char *luaO_openspace (lua_State *L, size_t n);
|
||||
|
||||
int luaO_equalObj (const TObject *t1, const TObject *t2);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lparser.c,v 1.133 2001/02/14 17:19:28 roberto Exp roberto $
|
||||
** $Id: lparser.c,v 1.134 2001/02/14 17:38:45 roberto Exp roberto $
|
||||
** LL(1) Parser and code generator for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -690,8 +690,8 @@ static BinOpr getbinopr (int op) {
|
|||
|
||||
|
||||
static const struct {
|
||||
unsigned char left; /* left priority for each binary operator */
|
||||
unsigned char right; /* right priority */
|
||||
lu_byte left; /* left priority for each binary operator */
|
||||
lu_byte right; /* right priority */
|
||||
} priority[] = { /* ORDER OPR */
|
||||
{5, 5}, {5, 5}, {6, 6}, {6, 6}, /* arithmetic */
|
||||
{9, 8}, {4, 3}, /* power and concat (right associative) */
|
||||
|
|
8
lstate.h
8
lstate.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lstate.h,v 1.49 2001/02/01 17:40:48 roberto Exp roberto $
|
||||
** $Id: lstate.h,v 1.50 2001/02/02 15:13:05 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -55,7 +55,7 @@ struct TM; /* defined in ltm.h */
|
|||
|
||||
typedef struct stringtable {
|
||||
int size;
|
||||
luint32 nuse; /* number of elements */
|
||||
ls_nstr nuse; /* number of elements */
|
||||
TString **hash;
|
||||
} stringtable;
|
||||
|
||||
|
@ -79,8 +79,8 @@ typedef struct global_State {
|
|||
int nref; /* first unused element in refArray */
|
||||
int sizeref; /* size of refArray */
|
||||
int refFree; /* list of free positions in refArray */
|
||||
mem_int GCthreshold;
|
||||
mem_int nblocks; /* number of `bytes' currently allocated */
|
||||
lu_mem GCthreshold;
|
||||
lu_mem nblocks; /* number of `bytes' currently allocated */
|
||||
} global_State;
|
||||
|
||||
|
||||
|
|
10
lstring.c
10
lstring.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lstring.c,v 1.57 2001/02/09 20:22:29 roberto Exp roberto $
|
||||
** $Id: lstring.c,v 1.58 2001/02/09 20:29:33 roberto Exp roberto $
|
||||
** String table (keeps all strings handled by Lua)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -39,7 +39,7 @@ void luaS_resize (lua_State *L, stringtable *tb, int newsize) {
|
|||
TString *p = tb->hash[i];
|
||||
while (p) { /* for each node in the list */
|
||||
TString *next = p->nexthash; /* save next */
|
||||
luint32 h = (tb == &G(L)->strt) ? p->u.s.hash : IntPoint(p->u.d.value);
|
||||
lu_hash h = (tb == &G(L)->strt) ? p->u.s.hash : IntPoint(p->u.d.value);
|
||||
int h1 = lmod(h, newsize); /* new position */
|
||||
lua_assert((int)(h%newsize) == lmod(h, newsize));
|
||||
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) {
|
|||
ts->nexthash = tb->hash[h]; /* chain new entry */
|
||||
tb->hash[h] = ts;
|
||||
tb->nuse++;
|
||||
if (tb->nuse > (luint32)tb->size && tb->size < MAX_INT/2) /* too crowded? */
|
||||
if (tb->nuse > (ls_nstr)tb->size && tb->size <= MAX_INT/2) /* too crowded? */
|
||||
luaS_resize(L, tb, tb->size*2);
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ static void newentry (lua_State *L, stringtable *tb, TString *ts, int h) {
|
|||
|
||||
TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
|
||||
TString *ts;
|
||||
luint32 h = l; /* seed */
|
||||
lu_hash h = l; /* seed */
|
||||
size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
|
||||
size_t l1;
|
||||
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) {
|
|||
ts->len = l;
|
||||
ts->u.s.hash = h;
|
||||
ts->u.s.constindex = 0;
|
||||
memcpy(getstr(ts), str, l);
|
||||
memcpy(getstr(ts), str, l*sizeof(char));
|
||||
getstr(ts)[l] = 0; /* ending 0 */
|
||||
newentry(L, &G(L)->strt, ts, lmod(h, G(L)->strt.size)); /* insert it */
|
||||
return ts;
|
||||
|
|
10
lstring.h
10
lstring.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lstring.h,v 1.28 2001/02/09 19:53:16 roberto Exp roberto $
|
||||
** $Id: lstring.h,v 1.29 2001/02/09 20:22:29 roberto Exp roberto $
|
||||
** String table (keep all strings handled by Lua)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -21,12 +21,14 @@
|
|||
#define RESERVEDMARK 3
|
||||
|
||||
|
||||
#define sizestring(l) ((luint32)sizeof(union L_UTString)+(l)+1)
|
||||
#define sizestring(l) ((lu_mem)sizeof(union L_UTString)+ \
|
||||
((lu_mem)(l)+1)*sizeof(char))
|
||||
|
||||
#define sizeudata(l) ((luint32)sizeof(union L_UTString)+(l))
|
||||
#define sizeudata(l) ((lu_mem)sizeof(union L_UTString)+(l))
|
||||
|
||||
#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
|
||||
#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, (sizeof(s))-1))
|
||||
#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
|
||||
(sizeof(s)/sizeof(char))-1))
|
||||
|
||||
void luaS_init (lua_State *L);
|
||||
void luaS_resize (lua_State *L, stringtable *tb, int newsize);
|
||||
|
|
38
ltable.c
38
ltable.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: ltable.c,v 1.74 2001/01/30 19:48:37 roberto Exp roberto $
|
||||
** $Id: ltable.c,v 1.75 2001/02/01 17:40:48 roberto Exp roberto $
|
||||
** Lua tables (hash)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -31,7 +31,7 @@
|
|||
#define TagDefault LUA_TTABLE
|
||||
|
||||
|
||||
#define hashnum(t,n) (&t->node[lmod((luint32)(lint32)(n), t->size)])
|
||||
#define hashnum(t,n) (&t->node[lmod((lu_hash)(ls_hash)(n), t->size)])
|
||||
#define hashstr(t,str) (&t->node[lmod((str)->u.s.hash, t->size)])
|
||||
#define hashpointer(t,p) (&t->node[lmod(IntPoint(p), t->size)])
|
||||
|
||||
|
@ -81,12 +81,26 @@ int luaH_nexti (Hash *t, int i) {
|
|||
}
|
||||
|
||||
|
||||
static void setnodevector (lua_State *L, Hash *t, luint32 size) {
|
||||
#define check_grow(L, p, n) \
|
||||
if ((p) >= MAX_INT/(n)) luaD_error(L, "table overflow");
|
||||
|
||||
/*
|
||||
** returns smaller power of 2 larger than `n' (minimum is MINPOWER2)
|
||||
*/
|
||||
static int power2 (lua_State *L, int n) {
|
||||
int p = MINPOWER2;
|
||||
while (p <= n) {
|
||||
check_grow(L, p, 2);
|
||||
p *= 2;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
static void setnodevector (lua_State *L, Hash *t, int size) {
|
||||
int i;
|
||||
if (size > MAX_INT)
|
||||
luaD_error(L, "table overflow");
|
||||
t->node = luaM_newvector(L, size, Node);
|
||||
for (i=0; i<(int)size; i++) {
|
||||
for (i=0; i<size; i++) {
|
||||
t->node[i].next = NULL;
|
||||
t->node[i].key_tt = LUA_TNIL;
|
||||
setnilvalue(&t->node[i].val);
|
||||
|
@ -104,7 +118,7 @@ Hash *luaH_new (lua_State *L, int size) {
|
|||
t->mark = t;
|
||||
t->size = 0;
|
||||
t->node = NULL;
|
||||
setnodevector(L, t, luaO_power2(size));
|
||||
setnodevector(L, t, power2(L, size));
|
||||
return t;
|
||||
}
|
||||
|
||||
|
@ -134,13 +148,15 @@ static void rehash (lua_State *L, Hash *t) {
|
|||
int nelems = numuse(t);
|
||||
int i;
|
||||
lua_assert(nelems<=oldsize);
|
||||
if (nelems >= oldsize-oldsize/4) /* using more than 3/4? */
|
||||
setnodevector(L, t, (luint32)oldsize*2);
|
||||
if (nelems >= oldsize-oldsize/4) { /* using more than 3/4? */
|
||||
check_grow(L, oldsize, 2);
|
||||
setnodevector(L, t, oldsize*2); /* grow array */
|
||||
}
|
||||
else if (nelems <= oldsize/4 && /* less than 1/4? */
|
||||
oldsize > MINPOWER2)
|
||||
setnodevector(L, t, oldsize/2);
|
||||
setnodevector(L, t, oldsize/2); /* shrink array */
|
||||
else
|
||||
setnodevector(L, t, oldsize);
|
||||
setnodevector(L, t, oldsize); /* just rehash; keep the same size */
|
||||
for (i=0; i<oldsize; i++) {
|
||||
Node *old = nold+i;
|
||||
if (ttype(&old->val) != LUA_TNIL) {
|
||||
|
|
4
ltm.c
4
ltm.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: ltm.c,v 1.65 2001/02/02 15:13:05 roberto Exp roberto $
|
||||
** $Id: ltm.c,v 1.66 2001/02/09 20:22:29 roberto Exp roberto $
|
||||
** Tag methods
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -53,7 +53,7 @@ static int luaI_checkevent (lua_State *L, const char *name, int t) {
|
|||
* 'placeholder' for "default" fallbacks
|
||||
*/
|
||||
/* ORDER LUA_T, ORDER TM */
|
||||
static const unsigned char luaT_validevents[NUM_TAGS][TM_N] = {
|
||||
static const lu_byte luaT_validevents[NUM_TAGS][TM_N] = {
|
||||
{1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_TUSERDATA */
|
||||
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_TNIL */
|
||||
{1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, /* LUA_TNUMBER */
|
||||
|
|
22
lua.c
22
lua.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lua.c,v 1.59 2001/02/06 18:18:58 roberto Exp roberto $
|
||||
** $Id: lua.c,v 1.60 2001/02/14 17:19:01 roberto Exp roberto $
|
||||
** Lua stand-alone interpreter
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -173,20 +173,24 @@ static int file_input (const char *argv) {
|
|||
#endif
|
||||
|
||||
|
||||
static void show_prompt (void) {
|
||||
const char *s;
|
||||
lua_getglobal(L, "_PROMPT");
|
||||
s = lua_tostring(L, -1);
|
||||
if (!s) s = PROMPT;
|
||||
fputs(s, stdout);
|
||||
lua_pop(L, 1); /* remove global */
|
||||
static const char *get_prompt (int prompt) {
|
||||
if (!prompt)
|
||||
return "";
|
||||
else {
|
||||
const char *s;
|
||||
lua_getglobal(L, "_PROMPT");
|
||||
s = lua_tostring(L, -1);
|
||||
if (!s) s = PROMPT;
|
||||
lua_pop(L, 1); /* remove global */
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void manual_input (int version, int prompt) {
|
||||
if (version) print_version();
|
||||
for (;;) {
|
||||
if (prompt) show_prompt();
|
||||
fputs(get_prompt(prompt), stdout); /* show prompt */
|
||||
for(;;) {
|
||||
char buffer[MAXINPUT];
|
||||
size_t l;
|
||||
|
|
5
lua.h
5
lua.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lua.h,v 1.85 2001/01/26 11:45:51 roberto Exp roberto $
|
||||
** $Id: lua.h,v 1.86 2001/02/09 19:53:16 roberto Exp roberto $
|
||||
** Lua - An Extensible Extension Language
|
||||
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
|
||||
** e-mail: lua@tecgraf.puc-rio.br
|
||||
|
@ -221,7 +221,8 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size);
|
|||
|
||||
#define lua_getregistry(L) lua_getref(L, LUA_REFREGISTRY)
|
||||
|
||||
#define lua_pushliteral(L, s) lua_pushlstring(L, "" s, (sizeof(s))-1)
|
||||
#define lua_pushliteral(L, s) lua_pushlstring(L, "" s, \
|
||||
(sizeof(s)/sizeof(char))-1)
|
||||
|
||||
|
||||
|
||||
|
|
5
lvm.c
5
lvm.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lvm.c,v 1.168 2001/02/09 20:22:29 roberto Exp roberto $
|
||||
** $Id: lvm.c,v 1.169 2001/02/12 13:04:19 roberto Exp roberto $
|
||||
** Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -273,8 +273,7 @@ void luaV_strconc (lua_State *L, int total, StkId top) {
|
|||
}
|
||||
else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */
|
||||
/* at least two string values; get as many as possible */
|
||||
luint32 tl = (luint32)tsvalue(top-1)->len +
|
||||
(luint32)tsvalue(top-2)->len;
|
||||
lu_mem tl = (lu_mem)tsvalue(top-1)->len + (lu_mem)tsvalue(top-2)->len;
|
||||
char *buffer;
|
||||
int i;
|
||||
while (n < total && !tostring(L, top-n-1)) { /* collect total length */
|
||||
|
|
Loading…
Reference in New Issue