small changes in casts

This commit is contained in:
Roberto Ierusalimschy 2005-12-22 14:19:56 -02:00
parent 428325baec
commit c505f341d6
16 changed files with 77 additions and 75 deletions

12
lapi.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lapi.c,v 2.50 2005/09/20 17:55:10 roberto Exp roberto $ ** $Id: lapi.c,v 2.51 2005/10/20 11:35:50 roberto Exp roberto $
** Lua API ** Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -153,7 +153,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
LUA_API int lua_gettop (lua_State *L) { LUA_API int lua_gettop (lua_State *L) {
return cast(int, L->top - L->base); return cast_int(L->top - L->base);
} }
@ -430,7 +430,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
lua_lock(L); lua_lock(L);
setnvalue(L->top, cast(lua_Number, n)); setnvalue(L->top, cast_num(n));
api_incr_top(L); api_incr_top(L);
lua_unlock(L); lua_unlock(L);
} }
@ -910,11 +910,11 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
} }
case LUA_GCCOUNT: { case LUA_GCCOUNT: {
/* GC values are expressed in Kbytes: #bytes/2^10 */ /* GC values are expressed in Kbytes: #bytes/2^10 */
res = cast(int, g->totalbytes >> 10); res = cast_int(g->totalbytes >> 10);
break; break;
} }
case LUA_GCCOUNTB: { case LUA_GCCOUNTB: {
res = cast(int, g->totalbytes & 0x3ff); res = cast_int(g->totalbytes & 0x3ff);
break; break;
} }
case LUA_GCSTEP: { case LUA_GCSTEP: {
@ -983,7 +983,7 @@ LUA_API void lua_concat (lua_State *L, int n) {
api_checknelems(L, n); api_checknelems(L, n);
if (n >= 2) { if (n >= 2) {
luaC_checkGC(L); luaC_checkGC(L);
luaV_concat(L, n, cast(int, L->top - L->base) - 1); luaV_concat(L, n, cast_int(L->top - L->base) - 1);
L->top -= (n-1); L->top -= (n-1);
} }
else if (n == 0) { /* push empty string */ else if (n == 0) { /* push empty string */

10
lcode.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lcode.c,v 2.22 2005/11/16 11:55:27 roberto Exp roberto $ ** $Id: lcode.c,v 2.23 2005/11/25 13:29:32 roberto Exp roberto $
** Code generator for Lua ** Code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -196,7 +196,7 @@ void luaK_checkstack (FuncState *fs, int n) {
if (newstack > fs->f->maxstacksize) { if (newstack > fs->f->maxstacksize) {
if (newstack >= MAXSTACK) if (newstack >= MAXSTACK)
luaX_syntaxerror(fs->ls, "function or expression too complex"); luaX_syntaxerror(fs->ls, "function or expression too complex");
fs->f->maxstacksize = cast(lu_byte, newstack); fs->f->maxstacksize = cast_byte(newstack);
} }
} }
@ -227,11 +227,11 @@ static int addk (FuncState *fs, TValue *k, TValue *v) {
Proto *f = fs->f; Proto *f = fs->f;
int oldsize = f->sizek; int oldsize = f->sizek;
if (ttisnumber(idx)) { if (ttisnumber(idx)) {
lua_assert(luaO_rawequalObj(&fs->f->k[cast(int, nvalue(idx))], v)); lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v));
return cast(int, nvalue(idx)); return cast_int(nvalue(idx));
} }
else { /* constant not found; create a new entry */ else { /* constant not found; create a new entry */
setnvalue(idx, cast(lua_Number, fs->nk)); setnvalue(idx, cast_num(fs->nk));
luaM_growvector(L, f->k, fs->nk, f->sizek, TValue, luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,
MAXARG_Bx, "constant table overflow"); MAXARG_Bx, "constant table overflow");
while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldebug.c,v 2.27 2005/10/06 20:43:44 roberto Exp roberto $ ** $Id: ldebug.c,v 2.28 2005/11/01 16:08:52 roberto Exp roberto $
** Debug Interface ** Debug Interface
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -61,7 +61,7 @@ LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {
L->hook = func; L->hook = func;
L->basehookcount = count; L->basehookcount = count;
resethookcount(L); resethookcount(L);
L->hookmask = cast(lu_byte, mask); L->hookmask = cast_byte(mask);
return 1; return 1;
} }
@ -92,7 +92,7 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
} }
if (level == 0 && ci > L->base_ci) { /* level found? */ if (level == 0 && ci > L->base_ci) { /* level found? */
status = 1; status = 1;
ar->i_ci = cast(int, ci - L->base_ci); ar->i_ci = cast_int(ci - L->base_ci);
} }
else if (level < 0) { /* level is of a lost tail call? */ else if (level < 0) { /* level is of a lost tail call? */
status = 1; status = 1;
@ -550,7 +550,7 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
const char *name = NULL; const char *name = NULL;
const char *t = luaT_typenames[ttype(o)]; const char *t = luaT_typenames[ttype(o)];
const char *kind = (isinstack(L->ci, o)) ? const char *kind = (isinstack(L->ci, o)) ?
getobjname(L, L->ci, cast(int, o - L->base), &name) : getobjname(L, L->ci, cast_int(o - L->base), &name) :
NULL; NULL;
if (kind) if (kind)
luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)",

17
ldo.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldo.c,v 2.35 2005/10/14 16:23:33 roberto Exp roberto $ ** $Id: ldo.c,v 2.36 2005/10/23 17:52:42 roberto Exp roberto $
** Stack and Call structure of Lua ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -71,7 +71,7 @@ void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {
static void restore_stack_limit (lua_State *L) { static void restore_stack_limit (lua_State *L) {
lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);
if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */ if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */
int inuse = cast(int, L->ci - L->base_ci); int inuse = cast_int(L->ci - L->base_ci);
if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */ if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */
luaD_reallocCI(L, LUAI_MAXCALLS); luaD_reallocCI(L, LUAI_MAXCALLS);
} }
@ -97,7 +97,7 @@ void luaD_throw (lua_State *L, int errcode) {
LUAI_THROW(L, L->errorJmp); LUAI_THROW(L, L->errorJmp);
} }
else { else {
L->status = cast(lu_byte, errcode); L->status = cast_byte(errcode);
if (G(L)->panic) { if (G(L)->panic) {
resetstack(L, errcode); resetstack(L, errcode);
lua_unlock(L); lua_unlock(L);
@ -189,7 +189,7 @@ void luaD_callhook (lua_State *L, int event, int line) {
if (event == LUA_HOOKTAILRET) if (event == LUA_HOOKTAILRET)
ar.i_ci = 0; /* tail call; no debug information about it */ ar.i_ci = 0; /* tail call; no debug information about it */
else else
ar.i_ci = cast(int, L->ci - L->base_ci); ar.i_ci = cast_int(L->ci - L->base_ci);
luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
L->ci->top = L->top + LUA_MINSTACK; L->ci->top = L->top + LUA_MINSTACK;
lua_assert(L->ci->top <= L->stack_last); lua_assert(L->ci->top <= L->stack_last);
@ -221,8 +221,7 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) {
for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */
setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i); setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i);
/* store counter in field `n' */ /* store counter in field `n' */
setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar));
cast(lua_Number, nvar));
} }
#endif #endif
/* move fixed parameters to final position */ /* move fixed parameters to final position */
@ -282,7 +281,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
L->top = base + p->numparams; L->top = base + p->numparams;
} }
else { /* vararg function */ else { /* vararg function */
int nargs = cast(int, L->top - func) - 1; int nargs = cast_int(L->top - func) - 1;
base = adjust_varargs(L, p, nargs); base = adjust_varargs(L, p, nargs);
func = restorestack(L, funcr); /* previous call may change the stack */ func = restorestack(L, funcr); /* previous call may change the stack */
} }
@ -401,7 +400,7 @@ static void resume (lua_State *L, void *ud) {
L->base = L->ci->base; L->base = L->ci->base;
} }
L->status = 0; L->status = 0;
luaV_execute(L, cast(int, L->ci - L->base_ci)); luaV_execute(L, cast_int(L->ci - L->base_ci));
} }
@ -427,7 +426,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) {
lua_assert(L->errfunc == 0 && L->nCcalls == 0); lua_assert(L->errfunc == 0 && L->nCcalls == 0);
status = luaD_rawrunprotected(L, resume, L->top - nargs); status = luaD_rawrunprotected(L, resume, L->top - nargs);
if (status != 0) { /* error? */ if (status != 0) { /* error? */
L->status = cast(lu_byte, status); /* mark thread as `dead' */ L->status = cast_byte(status); /* mark thread as `dead' */
luaD_seterrorobj(L, status, L->top); luaD_seterrorobj(L, status, L->top);
L->ci->top = L->top; L->ci->top = L->top;
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lfunc.c,v 2.10 2005/04/29 13:54:05 roberto Exp roberto $ ** $Id: lfunc.c,v 2.11 2005/05/05 20:47:02 roberto Exp roberto $
** Auxiliary functions to manipulate prototypes and closures ** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -25,7 +25,7 @@ Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) {
luaC_link(L, obj2gco(c), LUA_TFUNCTION); luaC_link(L, obj2gco(c), LUA_TFUNCTION);
c->c.isC = 1; c->c.isC = 1;
c->c.env = e; c->c.env = e;
c->c.nupvalues = cast(lu_byte, nelems); c->c.nupvalues = cast_byte(nelems);
return c; return c;
} }
@ -35,7 +35,7 @@ Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) {
luaC_link(L, obj2gco(c), LUA_TFUNCTION); luaC_link(L, obj2gco(c), LUA_TFUNCTION);
c->l.isC = 0; c->l.isC = 0;
c->l.env = e; c->l.env = e;
c->l.nupvalues = cast(lu_byte, nelems); c->l.nupvalues = cast_byte(nelems);
while (nelems--) c->l.upvals[nelems] = NULL; while (nelems--) c->l.upvals[nelems] = NULL;
return c; return c;
} }

17
lgc.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lgc.c,v 2.35 2005/08/04 13:37:38 roberto Exp roberto $ ** $Id: lgc.c,v 2.36 2005/08/24 17:06:36 roberto Exp roberto $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -29,11 +29,10 @@
#define GCFINALIZECOST 100 #define GCFINALIZECOST 100
#define maskmarks \ #define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS))
cast(lu_byte, ~(bitmask(BLACKBIT)|WHITEBITS))
#define makewhite(g,x) \ #define makewhite(g,x) \
((x)->gch.marked = ((x)->gch.marked & maskmarks) | luaC_white(g)) ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g)))
#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) #define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT) #define black2gray(x) resetbit((x)->gch.marked, BLACKBIT)
@ -169,8 +168,8 @@ static int traversetable (global_State *g, Table *h) {
weakvalue = (strchr(svalue(mode), 'v') != NULL); weakvalue = (strchr(svalue(mode), 'v') != NULL);
if (weakkey || weakvalue) { /* is really weak? */ if (weakkey || weakvalue) { /* is really weak? */
h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */ h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */
h->marked |= cast(lu_byte, (weakkey << KEYWEAKBIT) | h->marked |= cast_byte((weakkey << KEYWEAKBIT) |
(weakvalue << VALUEWEAKBIT)); (weakvalue << VALUEWEAKBIT));
h->gclist = g->weak; /* must be cleared after GC, ... */ h->gclist = g->weak; /* must be cleared after GC, ... */
g->weak = obj2gco(h); /* ... so put in the appropriate list */ g->weak = obj2gco(h); /* ... so put in the appropriate list */
} }
@ -240,8 +239,8 @@ static void traverseclosure (global_State *g, Closure *cl) {
static void checkstacksizes (lua_State *L, StkId max) { static void checkstacksizes (lua_State *L, StkId max) {
int ci_used = cast(int, L->ci - L->base_ci); /* number of `ci' in use */ int ci_used = cast_int(L->ci - L->base_ci); /* number of `ci' in use */
int s_used = cast(int, max - L->stack); /* part of stack in use */ int s_used = cast_int(max - L->stack); /* part of stack in use */
if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */ if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */
return; /* do not touch the stacks */ return; /* do not touch the stacks */
if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)
@ -544,7 +543,7 @@ static void atomic (lua_State *L) {
propagateall(g); /* remark, to propagate `preserveness' */ propagateall(g); /* remark, to propagate `preserveness' */
cleartable(g->weak); /* remove collected objects from weak tables */ cleartable(g->weak); /* remove collected objects from weak tables */
/* flip current white */ /* flip current white */
g->currentwhite = cast(lu_byte, otherwhite(g)); g->currentwhite = cast_byte(otherwhite(g));
g->sweepstrgc = 0; g->sweepstrgc = 0;
g->sweepgc = &g->rootgc; g->sweepgc = &g->rootgc;
g->gcstate = GCSsweepstring; g->gcstate = GCSsweepstring;

4
llex.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: llex.c,v 2.15 2005/12/07 15:43:05 roberto Exp roberto $ ** $Id: llex.c,v 2.16 2005/12/08 15:50:54 roberto Exp roberto $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -66,7 +66,7 @@ void luaX_init (lua_State *L) {
TString *ts = luaS_new(L, luaX_tokens[i]); TString *ts = luaS_new(L, luaX_tokens[i]);
luaS_fix(ts); /* reserved words are never collected */ luaS_fix(ts); /* reserved words are never collected */
lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN); lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN);
ts->tsv.reserved = cast(lu_byte, i+1); /* reserved word */ ts->tsv.reserved = cast_byte(i+1); /* reserved word */
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: llimits.h,v 1.66 2005/08/04 13:37:10 roberto Exp roberto $ ** $Id: llimits.h,v 1.67 2005/08/24 16:15:49 roberto Exp roberto $
** Limits, basic types, and some other `installation-dependent' definitions ** Limits, basic types, and some other `installation-dependent' definitions
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -66,6 +66,10 @@ typedef LUAI_UACNUMBER l_uacNumber;
#define cast(t, exp) ((t)(exp)) #define cast(t, exp) ((t)(exp))
#endif #endif
#define cast_byte(i) cast(lu_byte, (i))
#define cast_num(i) cast(lua_Number, (i))
#define cast_int(i) cast(int, (i))
/* /*

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lobject.c,v 2.18 2005/08/01 04:22:23 roberto Exp roberto $ ** $Id: lobject.c,v 2.19 2005/10/24 17:37:52 roberto Exp roberto $
** Some generic functions over Lua objects ** Some generic functions over Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -39,7 +39,7 @@ int luaO_int2fb (unsigned int x) {
e++; e++;
} }
if (x < 8) return x; if (x < 8) return x;
else return ((e+1) << 3) | (cast(int, x) - 8); else return ((e+1) << 3) | (cast_int(x) - 8);
} }
@ -129,12 +129,12 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
break; break;
} }
case 'd': { case 'd': {
setnvalue(L->top, cast(lua_Number, va_arg(argp, int))); setnvalue(L->top, cast_num(va_arg(argp, int)));
incr_top(L); incr_top(L);
break; break;
} }
case 'f': { case 'f': {
setnvalue(L->top, cast(lua_Number, va_arg(argp, l_uacNumber))); setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));
incr_top(L); incr_top(L);
break; break;
} }
@ -161,7 +161,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
fmt = e+2; fmt = e+2;
} }
pushstr(L, fmt); pushstr(L, fmt);
luaV_concat(L, n+1, cast(int, L->top - L->base) - 1); luaV_concat(L, n+1, cast_int(L->top - L->base) - 1);
L->top -= n; L->top -= n;
return svalue(L->top - 1); return svalue(L->top - 1);
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: loslib.c,v 1.14 2005/10/21 13:47:42 roberto Exp roberto $ ** $Id: loslib.c,v 1.15 2005/12/15 18:17:49 roberto Exp roberto $
** Standard Operating System library ** Standard Operating System library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -179,7 +179,7 @@ static int os_time (lua_State *L) {
if (t == (time_t)(-1)) if (t == (time_t)(-1))
lua_pushnil(L); lua_pushnil(L);
else else
lua_pushnumber(L, t); lua_pushnumber(L, (lua_Number)t);
return 1; return 1;
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lparser.c,v 2.38 2005/10/24 17:38:47 roberto Exp roberto $ ** $Id: lparser.c,v 2.39 2005/12/07 15:43:05 roberto Exp roberto $
** Lua Parser ** Lua Parser
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -166,7 +166,7 @@ static void new_localvar (LexState *ls, TString *name, int n) {
static void adjustlocalvars (LexState *ls, int nvars) { static void adjustlocalvars (LexState *ls, int nvars) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
fs->nactvar = cast(lu_byte, fs->nactvar + nvars); fs->nactvar = cast_byte(fs->nactvar + nvars);
for (; nvars; nvars--) { for (; nvars; nvars--) {
getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc; getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc;
} }
@ -198,8 +198,8 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) {
f->upvalues[f->nups] = name; f->upvalues[f->nups] = name;
luaC_objbarrier(fs->L, f, name); luaC_objbarrier(fs->L, f, name);
lua_assert(v->k == VLOCAL || v->k == VUPVAL); lua_assert(v->k == VLOCAL || v->k == VUPVAL);
fs->upvalues[f->nups].k = cast(lu_byte, v->k); fs->upvalues[f->nups].k = cast_byte(v->k);
fs->upvalues[f->nups].info = cast(lu_byte, v->u.s.info); fs->upvalues[f->nups].info = cast_byte(v->u.s.info);
return f->nups++; return f->nups++;
} }
@ -567,7 +567,7 @@ static void parlist (LexState *ls) {
} while (!f->is_vararg && testnext(ls, ',')); } while (!f->is_vararg && testnext(ls, ','));
} }
adjustlocalvars(ls, nparams); adjustlocalvars(ls, nparams);
f->numparams = fs->nactvar - (f->is_vararg & VARARG_HASARG); f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG));
luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lstring.c,v 2.6 2005/01/18 17:18:09 roberto Exp roberto $ ** $Id: lstring.c,v 2.7 2005/02/18 12:40:02 roberto Exp roberto $
** String table (keeps all strings handled by Lua) ** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -35,7 +35,7 @@ void luaS_resize (lua_State *L, int newsize) {
GCObject *next = p->gch.next; /* save next */ GCObject *next = p->gch.next; /* save next */
unsigned int h = gco2ts(p)->hash; unsigned int h = gco2ts(p)->hash;
int h1 = lmod(h, newsize); /* new position */ int h1 = lmod(h, newsize); /* new position */
lua_assert(cast(int, h%newsize) == lmod(h, newsize)); lua_assert(cast_int(h%newsize) == lmod(h, newsize));
p->gch.next = newhash[h1]; /* chain it */ p->gch.next = newhash[h1]; /* chain it */
newhash[h1] = p; newhash[h1] = p;
p = next; p = next;

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltable.c,v 2.27 2005/10/24 17:37:52 roberto Exp roberto $ ** $Id: ltable.c,v 2.28 2005/11/25 13:29:32 roberto Exp roberto $
** Lua tables (hash) ** Lua tables (hash)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -66,7 +66,7 @@
/* /*
** number of ints inside a lua_Number ** number of ints inside a lua_Number
*/ */
#define numints cast(int, sizeof(lua_Number)/sizeof(int)) #define numints cast_int(sizeof(lua_Number)/sizeof(int))
@ -120,7 +120,7 @@ static int arrayindex (const TValue *key) {
lua_Number n = nvalue(key); lua_Number n = nvalue(key);
int k; int k;
lua_number2int(k, n); lua_number2int(k, n);
if (luai_numeq(cast(lua_Number, k), nvalue(key))) if (luai_numeq(cast_num(k), nvalue(key)))
return k; return k;
} }
return -1; /* `key' did not match some condition */ return -1; /* `key' did not match some condition */
@ -145,7 +145,7 @@ static int findindex (lua_State *L, Table *t, StkId key) {
if (luaO_rawequalObj(key2tval(n), key) || if (luaO_rawequalObj(key2tval(n), key) ||
(ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) && (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) &&
gcvalue(gkey(n)) == gcvalue(key))) { gcvalue(gkey(n)) == gcvalue(key))) {
i = cast(int, n - gnode(t, 0)); /* key index in hash table */ i = cast_int(n - gnode(t, 0)); /* key index in hash table */
/* hash elements are numbered after array ones */ /* hash elements are numbered after array ones */
return i + t->sizearray; return i + t->sizearray;
} }
@ -161,7 +161,7 @@ int luaH_next (lua_State *L, Table *t, StkId key) {
int i = findindex(L, t, key); /* find original element */ int i = findindex(L, t, key); /* find original element */
for (i++; i < t->sizearray; i++) { /* try first array part */ for (i++; i < t->sizearray; i++) { /* try first array part */
if (!ttisnil(&t->array[i])) { /* a non-nil value? */ if (!ttisnil(&t->array[i])) { /* a non-nil value? */
setnvalue(key, cast(lua_Number, i+1)); setnvalue(key, cast_num(i+1));
setobj2s(L, key+1, &t->array[i]); setobj2s(L, key+1, &t->array[i]);
return 1; return 1;
} }
@ -286,7 +286,7 @@ static void setnodevector (lua_State *L, Table *t, int size) {
setnilvalue(gval(gnode(t, i))); setnilvalue(gval(gnode(t, i)));
} }
} }
t->lsizenode = cast(lu_byte, lsize); t->lsizenode = cast_byte(lsize);
t->lastfree = gnode(t, size); /* all positions are free */ t->lastfree = gnode(t, size); /* all positions are free */
} }
@ -356,7 +356,7 @@ Table *luaH_new (lua_State *L, int narray, int nhash) {
Table *t = luaM_new(L, Table); Table *t = luaM_new(L, Table);
luaC_link(L, obj2gco(t), LUA_TTABLE); luaC_link(L, obj2gco(t), LUA_TTABLE);
t->metatable = NULL; t->metatable = NULL;
t->flags = cast(lu_byte, ~0); t->flags = cast_byte(~0);
/* temporary values (kept only if some malloc fails) */ /* temporary values (kept only if some malloc fails) */
t->array = NULL; t->array = NULL;
t->sizearray = 0; t->sizearray = 0;
@ -434,7 +434,7 @@ const TValue *luaH_getnum (Table *t, int key) {
if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
return &t->array[key-1]; return &t->array[key-1];
else { else {
lua_Number nk = cast(lua_Number, key); lua_Number nk = cast_num(key);
Node *n = hashnum(t, nk); Node *n = hashnum(t, nk);
do { /* check whether `key' is somewhere in the chain */ do { /* check whether `key' is somewhere in the chain */
if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk)) if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))
@ -471,7 +471,7 @@ const TValue *luaH_get (Table *t, const TValue *key) {
int k; int k;
lua_Number n = nvalue(key); lua_Number n = nvalue(key);
lua_number2int(k, n); lua_number2int(k, n);
if (luai_numeq(cast(lua_Number, k), nvalue(key))) /* index is int? */ if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */
return luaH_getnum(t, k); /* use specialized version */ return luaH_getnum(t, k); /* use specialized version */
/* else go through */ /* else go through */
} }
@ -508,7 +508,7 @@ TValue *luaH_setnum (lua_State *L, Table *t, int key) {
return cast(TValue *, p); return cast(TValue *, p);
else { else {
TValue k; TValue k;
setnvalue(&k, cast(lua_Number, key)); setnvalue(&k, cast_num(key));
return newkey(L, t, &k); return newkey(L, t, &k);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltests.c,v 2.32 2005/09/20 17:55:10 roberto Exp roberto $ ** $Id: ltests.c,v 2.33 2005/10/06 20:47:32 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation ** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -798,7 +798,7 @@ static int getnum_aux (lua_State *L, const char **pc) {
int sig = 1; int sig = 1;
skip(pc); skip(pc);
if (**pc == '.') { if (**pc == '.') {
res = cast(int, lua_tonumber(L, -1)); res = cast_int(lua_tonumber(L, -1));
lua_pop(L, 1); lua_pop(L, 1);
(*pc)++; (*pc)++;
return res; return res;
@ -807,7 +807,7 @@ static int getnum_aux (lua_State *L, const char **pc) {
sig = -1; sig = -1;
(*pc)++; (*pc)++;
} }
while (isdigit(cast(int, **pc))) res = res*10 + (*(*pc)++) - '0'; while (isdigit(cast_int(**pc))) res = res*10 + (*(*pc)++) - '0';
return sig*res; return sig*res;
} }
@ -994,7 +994,7 @@ static int testC (lua_State *L) {
#ifndef luaL_setn #ifndef luaL_setn
else if EQ("setn") { else if EQ("setn") {
int i = getindex; int i = getindex;
int n = cast(int, lua_tonumber(L1, -1)); int n = cast_int(lua_tonumber(L1, -1));
luaL_setn(L1, i, n); luaL_setn(L1, i, n);
lua_pop(L1, 1); lua_pop(L1, 1);
} }

4
ltm.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltm.c,v 2.5 2005/05/05 15:34:03 roberto Exp roberto $ ** $Id: ltm.c,v 2.6 2005/05/20 15:53:42 roberto Exp roberto $
** Tag methods ** Tag methods
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -51,7 +51,7 @@ const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
const TValue *tm = luaH_getstr(events, ename); const TValue *tm = luaH_getstr(events, ename);
lua_assert(event <= TM_EQ); lua_assert(event <= TM_EQ);
if (ttisnil(tm)) { /* no tag method? */ if (ttisnil(tm)) { /* no tag method? */
events->flags |= cast(lu_byte, 1u<<event); /* cache this fact */ events->flags |= cast_byte(1u<<event); /* cache this fact */
return NULL; return NULL;
} }
else return tm; else return tm;

12
lvm.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lvm.c,v 2.58 2005/10/24 17:37:52 roberto Exp roberto $ ** $Id: lvm.c,v 2.59 2005/11/01 16:08:45 roberto Exp roberto $
** Lua virtual machine ** Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -509,11 +509,11 @@ void luaV_execute (lua_State *L, int nexeccalls) {
const TValue *rb = RB(i); const TValue *rb = RB(i);
switch (ttype(rb)) { switch (ttype(rb)) {
case LUA_TTABLE: { case LUA_TTABLE: {
setnvalue(ra, cast(lua_Number, luaH_getn(hvalue(rb)))); setnvalue(ra, cast_num(luaH_getn(hvalue(rb))));
break; break;
} }
case LUA_TSTRING: { case LUA_TSTRING: {
setnvalue(ra, cast(lua_Number, tsvalue(rb)->len)); setnvalue(ra, cast_num(tsvalue(rb)->len));
break; break;
} }
default: { /* try metamethod */ default: { /* try metamethod */
@ -693,10 +693,10 @@ void luaV_execute (lua_State *L, int nexeccalls) {
int last; int last;
Table *h; Table *h;
if (n == 0) { if (n == 0) {
n = cast(int, L->top - ra) - 1; n = cast_int(L->top - ra) - 1;
L->top = L->ci->top; L->top = L->ci->top;
} }
if (c == 0) c = cast(int, *pc++); if (c == 0) c = cast_int(*pc++);
runtime_check(L, ttistable(ra)); runtime_check(L, ttistable(ra));
h = hvalue(ra); h = hvalue(ra);
last = ((c-1)*LFIELDS_PER_FLUSH) + n; last = ((c-1)*LFIELDS_PER_FLUSH) + n;
@ -737,7 +737,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
int b = GETARG_B(i) - 1; int b = GETARG_B(i) - 1;
int j; int j;
CallInfo *ci = L->ci; CallInfo *ci = L->ci;
int n = cast(int, ci->base - ci->func) - cl->p->numparams - 1; int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1;
if (b == LUA_MULTRET) { if (b == LUA_MULTRET) {
Protect(luaD_checkstack(L, n)); Protect(luaD_checkstack(L, n));
ra = RA(i); /* previous call may change the stack */ ra = RA(i); /* previous call may change the stack */