diff --git a/lapi.c b/lapi.c index a349c657..7c2f5d52 100644 --- a/lapi.c +++ b/lapi.c @@ -544,8 +544,8 @@ LUA_API int lua_dostring (lua_State *L, const l_char *str) { */ /* GC values are expressed in Kbytes: #bytes/2^10 */ -#define GCscale(x) ((int)((x)>>10)) -#define GCunscale(x) ((lu_mem)(x)<<10) +#define GCscale(x) (cast(int, (x)>>10)) +#define GCunscale(x) (cast(lu_mem, (x)<<10)) LUA_API int lua_getgcthreshold (lua_State *L) { int threshold; @@ -602,7 +602,7 @@ LUA_API int lua_name2tag (lua_State *L, const l_char *name) { tag = LUA_TNONE; else { lua_assert(ttype(v) == LUA_TNUMBER); - tag = (int)nvalue(v); + tag = cast(int, nvalue(v)); } lua_unlock(L); return tag; @@ -695,7 +695,7 @@ LUA_API int lua_getn (lua_State *L, int index) { api_check(L, ttype(t) == LUA_TTABLE); value = luaH_getstr(hvalue(t), luaS_newliteral(L, l_s("n"))); /* = t.n */ if (ttype(value) == LUA_TNUMBER) - n = (int)nvalue(value); + n = cast(int, nvalue(value)); else { lua_Number max = 0; int i = hvalue(t)->size; @@ -707,7 +707,7 @@ LUA_API int lua_getn (lua_State *L, int index) { max = nvalue(key(nd)); nd++; } - n = (int)max; + n = cast(int, max); } lua_unlock(L); return n; diff --git a/lbaselib.c b/lbaselib.c index 873820d3..8ab2f024 100644 --- a/lbaselib.c +++ b/lbaselib.c @@ -141,7 +141,7 @@ static int luaB_getglobal (lua_State *L) { static int gettag (lua_State *L, int narg) { switch (lua_rawtag(L, narg)) { case LUA_TNUMBER: - return (int)lua_tonumber(L, narg); + return (int)(lua_tonumber(L, narg)); case LUA_TSTRING: { const l_char *name = lua_tostring(L, narg); int tag = lua_name2tag(L, name); diff --git a/lcode.c b/lcode.c index 694a715d..d1b5355a 100644 --- a/lcode.c +++ b/lcode.c @@ -41,7 +41,7 @@ static Instruction previous_instruction (FuncState *fs) { if (fs->pc > fs->lasttarget) /* no jumps to current position? */ return fs->f->code[fs->pc-1]; /* returns previous instruction */ else - return (Instruction)(-1);/* no optimizations after an invalid instruction */ + return cast(Instruction, -1);/* invalid instruction avoids optimizations */ } @@ -203,7 +203,7 @@ void luaK_reserveregs (FuncState *fs, int n) { if (fs->freereg > fs->f->maxstacksize) { if (fs->freereg >= MAXSTACK) luaK_error(fs->ls, l_s("function or expression too complex")); - fs->f->maxstacksize = (short)fs->freereg; + fs->f->maxstacksize = cast(short, fs->freereg); } } @@ -225,8 +225,8 @@ static void freeexp (FuncState *fs, expdesc *e) { static int addk (FuncState *fs, TObject *k) { const TObject *index = luaH_get(fs->h, k); if (ttype(index) == LUA_TNUMBER) { - lua_assert(luaO_equalObj(&fs->f->k[(int)nvalue(index)], k)); - return (int)nvalue(index); + lua_assert(luaO_equalObj(&fs->f->k[cast(int, nvalue(index))], k)); + return cast(int, nvalue(index)); } else { /* constant not found; create a new entry */ TObject o; @@ -329,7 +329,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) { } case VNUMBER: { lua_Number f = e->u.n; - int i = (int)f; + int i = cast(int, f); if ((lua_Number)i == f && -MAXARG_sBc <= i && i <= MAXARG_sBc) luaK_codeAsBc(fs, OP_LOADINT, reg, i); /* f has a small int value */ else diff --git a/ldblib.c b/ldblib.c index d3f0bca3..f91bb551 100644 --- a/ldblib.c +++ b/ldblib.c @@ -1,5 +1,5 @@ /* -** $Id: ldblib.c,v 1.36 2001/03/26 14:31:49 roberto Exp roberto $ +** $Id: ldblib.c,v 1.37 2001/06/06 18:00:19 roberto Exp $ ** Interface from Lua to its debug API ** See Copyright Notice in lua.h */ @@ -37,7 +37,7 @@ static int getinfo (lua_State *L) { const l_char *options = luaL_opt_string(L, 2, l_s("flnSu")); l_char buff[20]; if (lua_isnumber(L, 1)) { - if (!lua_getstack(L, (int)lua_tonumber(L, 1), &ar)) { + if (!lua_getstack(L, (int)(lua_tonumber(L, 1)), &ar)) { lua_pushnil(L); /* level out of range */ return 1; } diff --git a/ldo.c b/ldo.c index ceda04d9..92953d92 100644 --- a/ldo.c +++ b/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 1.137 2001/07/12 19:34:03 roberto Exp roberto $ +** $Id: ldo.c,v 1.138 2001/07/16 20:24:48 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -176,7 +176,7 @@ struct CallS { /* data to `f_call' */ }; static void f_call (lua_State *L, void *ud) { - struct CallS *c = (struct CallS *)ud; + struct CallS *c = cast(struct CallS *, ud); luaD_call(L, c->func); if (c->nresults != LUA_MULTRET) luaD_adjusttop(L, c->func + c->nresults); @@ -207,7 +207,7 @@ struct SParser { /* data to `f_parser' */ }; static void f_parser (lua_State *L, void *ud) { - struct SParser *p = (struct SParser *)ud; + struct SParser *p = cast(struct SParser *, ud); Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z); luaV_Lclosure(L, tf, 0); } diff --git a/lfunc.c b/lfunc.c index 141d04a1..cece5a1b 100644 --- a/lfunc.c +++ b/lfunc.c @@ -1,5 +1,5 @@ /* -** $Id: lfunc.c,v 1.44 2001/06/05 18:17:01 roberto Exp roberto $ +** $Id: lfunc.c,v 1.45 2001/06/28 14:57:17 roberto Exp $ ** Auxiliary functions to manipulate prototypes and closures ** See Copyright Notice in lua.h */ @@ -15,11 +15,12 @@ #include "lstate.h" -#define sizeclosure(n) ((int)sizeof(Closure) + (int)sizeof(TObject)*((n)-1)) +#define sizeclosure(n) (cast(int, sizeof(Closure)) + \ + cast(int, sizeof(TObject)*((n)-1))) Closure *luaF_newclosure (lua_State *L, int nelems) { - Closure *c = (Closure *)luaM_malloc(L, sizeclosure(nelems)); + Closure *c = cast(Closure *, luaM_malloc(L, sizeclosure(nelems))); c->next = G(L)->rootcl; G(L)->rootcl = c; c->mark = c; diff --git a/lgc.c b/lgc.c index b0efaed3..17373f9a 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 1.108 2001/06/26 13:20:45 roberto Exp roberto $ +** $Id: lgc.c,v 1.109 2001/06/28 14:57:17 roberto Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -305,7 +305,7 @@ static void collectstrings (lua_State *L, int all) { } } } - if (G(L)->strt.nuse < (ls_nstr)(G(L)->strt.size/4) && + if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) && G(L)->strt.size > MINPOWER2) luaS_resize(L, G(L)->strt.size/2); /* table is too big */ } diff --git a/liolib.c b/liolib.c index 0d9c6b3e..8c64980f 100644 --- a/liolib.c +++ b/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 1.120 2001/07/16 18:48:31 roberto Exp roberto $ +** $Id: liolib.c,v 1.121 2001/07/22 00:59:36 roberto Exp $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -73,7 +73,7 @@ static int pushresult (lua_State *L, int i) { static FILE *getopthandle (lua_State *L, int inout) { - FILE *p = (FILE *)lua_touserdata(L, 1); + FILE *p = (FILE *)(lua_touserdata(L, 1)); if (p != NULL) { /* is it a userdata ? */ if (!checkfile(L, 1)) { /* not a valid file handle? */ if (strcmp(lua_type(L, 1), CLOSEDFILEHANDLE) == 0) @@ -88,7 +88,7 @@ static FILE *getopthandle (lua_State *L, int inout) { if (!checkfile(L,-1)) luaL_verror(L, l_s("global variable `%.10s' is not a valid file handle"), filenames[inout]); - p = (FILE *)lua_touserdata(L, -1); + p = (FILE *)(lua_touserdata(L, -1)); } return p; /* leave handle at stack top to avoid GC */ } @@ -127,7 +127,7 @@ static void resetfile (lua_State *L, int inout) { static int io_close (lua_State *L) { - FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE); + FILE *f = (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE)); int status = 1; if (f != stdin && f != stdout && f != stderr) { lua_settop(L, 1); /* make sure file is on top */ @@ -139,7 +139,7 @@ static int io_close (lua_State *L) { static int file_collect (lua_State *L) { - FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE); + FILE *f = (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE)); if (f != stdin && f != stdout && f != stderr) CLOSEFILE(L, f); return 0; @@ -328,7 +328,7 @@ static int io_read (lua_State *L) { size_t pl = lua_strlen(L, n) - 2; luaL_arg_check(L, 0 < pl && pl <= LUA_MAXUNTIL, n, l_s("invalid read-until length")); - success = read_until(L, f, p+2, (int)pl); + success = read_until(L, f, p+2, (int)(pl)); break; } default: @@ -373,7 +373,7 @@ static int io_write (lua_State *L) { static int io_seek (lua_State *L) { static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; static const l_char *const modenames[] = {l_s("set"), l_s("cur"), l_s("end"), NULL}; - FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE); + FILE *f = (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE)); int op = luaL_findstring(luaL_opt_string(L, 2, l_s("cur")), modenames); long offset = luaL_opt_long(L, 3, 0); luaL_arg_check(L, op != -1, 2, l_s("invalid mode")); @@ -388,8 +388,8 @@ static int io_seek (lua_State *L) { static int io_flush (lua_State *L) { - FILE *f = (lua_isnull(L, 1)) ? (FILE *)NULL : - (FILE *)luaL_check_userdata(L, 1, FILEHANDLE); + FILE *f = (lua_isnull(L, 1)) ? (FILE *)(NULL) : + (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE)); return pushresult(L, fflush(f) == 0); } @@ -461,7 +461,7 @@ static int getfield (lua_State *L, const l_char *key, int d) { lua_pushstring(L, key); lua_rawget(L, -2); if (lua_isnumber(L, -1)) - res = (int)lua_tonumber(L, -1); + res = (int)(lua_tonumber(L, -1)); else { if (d == -2) luaL_verror(L, l_s("field `%.20s' missing in date table"), key); @@ -474,9 +474,9 @@ static int getfield (lua_State *L, const l_char *key, int d) { static int io_date (lua_State *L) { const l_char *s = luaL_opt_string(L, 1, l_s("%c")); - time_t t = (time_t)luaL_opt_number(L, 2, -1); + time_t t = (time_t)(luaL_opt_number(L, 2, -1)); struct tm *stm; - if (t == (time_t)-1) /* no time given? */ + if (t == (time_t)(-1)) /* no time given? */ t = time(NULL); /* use current time */ if (*s == l_c('!')) { /* UTC? */ stm = gmtime(&t); @@ -525,7 +525,7 @@ static int io_time (lua_State *L) { ts.tm_year = getfield(L, l_s("year"), -2)-1900; ts.tm_isdst = getfield(L, l_s("isdst"), -1); t = mktime(&ts); - if (t == (time_t)-1) + if (t == (time_t)(-1)) lua_pushnil(L); else lua_pushnumber(L, t); @@ -535,8 +535,8 @@ static int io_time (lua_State *L) { static int io_difftime (lua_State *L) { - lua_pushnumber(L, difftime((time_t)luaL_check_number(L, 1), - (time_t)luaL_opt_number(L, 2, 0))); + lua_pushnumber(L, difftime((time_t)(luaL_check_number(L, 1)), + (time_t)(luaL_opt_number(L, 2, 0)))); return 1; } diff --git a/llex.c b/llex.c index 2680e6b1..4f5dbb3b 100644 --- a/llex.c +++ b/llex.c @@ -41,7 +41,7 @@ void luaX_init (lua_State *L) { for (i=0; itsv.marked = (unsigned short)(RESERVEDMARK+i); /* reserved word */ + ts->tsv.marked = cast(unsigned short, RESERVEDMARK+i); /* reserved word */ } } @@ -71,7 +71,7 @@ void luaX_error (LexState *ls, const l_char *s, int token) { l_char buff[TOKEN_LEN]; luaX_token2str(token, buff); if (buff[0] == l_c('\0')) - luaX_syntaxerror(ls, s, (l_char *)G(ls->L)->Mbuffer); + luaX_syntaxerror(ls, s, cast(l_char *, G(ls->L)->Mbuffer)); else luaX_syntaxerror(ls, s, buff); } @@ -134,7 +134,7 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source) { if (((len)+(n))*sizeof(l_char) > G(L)->Mbuffsize) \ luaO_openspace(L, (len)+(n)+EXTRABUFF, l_char) -#define save(L, c, l) (((l_char *)G(L)->Mbuffer)[l++] = (l_char)c) +#define save(L, c, l) (cast(l_char *, G(L)->Mbuffer)[l++] = (l_char)c) #define save_and_next(L, LS, l) (save(L, LS->current, l), next(LS)) @@ -185,7 +185,7 @@ static void read_number (LexState *LS, int comma, SemInfo *seminfo) { } } save(L, l_c('\0'), l); - if (!luaO_str2d((l_char *)G(L)->Mbuffer, &seminfo->r)) + if (!luaO_str2d(cast(l_char *, G(L)->Mbuffer), &seminfo->r)) luaX_error(LS, l_s("malformed number"), TK_NUMBER); } @@ -231,7 +231,7 @@ static void read_long_string (LexState *LS, SemInfo *seminfo) { } endloop: save_and_next(L, LS, l); /* skip the second `]' */ save(L, l_c('\0'), l); - seminfo->ts = luaS_newlstr(L, (l_char *)G(L)->Mbuffer+2, l-5); + seminfo->ts = luaS_newlstr(L, cast(l_char *, G(L)->Mbuffer)+2, l-5); } @@ -283,7 +283,7 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) { } save_and_next(L, LS, l); /* skip delimiter */ save(L, l_c('\0'), l); - seminfo->ts = luaS_newlstr(L, (l_char *)G(L)->Mbuffer+1, l-3); + seminfo->ts = luaS_newlstr(L, cast(l_char *, G(L)->Mbuffer)+1, l-3); } @@ -371,7 +371,7 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) { else if (isalpha(LS->current) || LS->current == l_c('_')) { /* identifier or reserved word */ size_t l = readname(LS); - TString *ts = luaS_newlstr(LS->L, (l_char *)G(LS->L)->Mbuffer, l); + TString *ts = luaS_newlstr(LS->L, cast(l_char *, G(LS->L)->Mbuffer), l); if (ts->tsv.marked >= RESERVEDMARK) /* reserved word? */ return ts->tsv.marked-RESERVEDMARK+FIRST_RESERVED; seminfo->ts = ts; diff --git a/llex.h b/llex.h index f4577551..fbfe092d 100644 --- a/llex.h +++ b/llex.h @@ -1,5 +1,5 @@ /* -** $Id: llex.h,v 1.36 2001/06/20 21:07:57 roberto Exp roberto $ +** $Id: llex.h,v 1.37 2001/07/22 00:59:36 roberto Exp $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ @@ -33,7 +33,7 @@ enum RESERVED { }; /* number of reserved words */ -#define NUM_RESERVED ((int)(TK_WHILE-FIRST_RESERVED+1)) +#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) typedef union { diff --git a/lmem.c b/lmem.c index 189986a5..1b7be9fc 100644 --- a/lmem.c +++ b/lmem.c @@ -1,5 +1,5 @@ /* -** $Id: lmem.c,v 1.48 2001/02/23 17:17:25 roberto Exp roberto $ +** $Id: lmem.c,v 1.49 2001/03/26 14:31:49 roberto Exp $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ @@ -34,8 +34,9 @@ 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, (lu_mem)(*size)*(lu_mem)size_elems, - (lu_mem)newsize*(lu_mem)size_elems); + newblock = luaM_realloc(L, block, + cast(lu_mem, *size)*cast(lu_mem, size_elems), + cast(lu_mem, newsize)*cast(lu_mem, size_elems)); *size = newsize; /* update only when everything else is OK */ return newblock; } diff --git a/lmem.h b/lmem.h index bf1d6836..5e33095c 100644 --- a/lmem.h +++ b/lmem.h @@ -1,5 +1,5 @@ /* -** $Id: lmem.h,v 1.21 2001/02/20 18:15:33 roberto Exp roberto $ +** $Id: lmem.h,v 1.22 2001/02/23 17:17:25 roberto Exp $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ @@ -21,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), \ - ((lu_mem)(n)*(lu_mem)sizeof(t)), 0) + cast(lu_mem, n)*cast(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, \ - (lu_mem)(n)*(lu_mem)sizeof(t))) +#define luaM_new(L, t) cast(t *, luaM_malloc(L, sizeof(t))) +#define luaM_newvector(L, n,t) cast(t *, luaM_malloc(L, \ + cast(lu_mem, n)*cast(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)) + ((v)=cast(t *, luaM_growaux(L,v,&(size),sizeof(t),limit,e))) #define luaM_reallocvector(L, v,oldn,n,t) \ - ((v)=(t *)luaM_realloc(L, v,(lu_mem)(oldn)*(lu_mem)sizeof(t), \ - (lu_mem)(n)*(lu_mem)sizeof(t))) + ((v)=cast(t *, luaM_realloc(L, v,cast(lu_mem, oldn)*cast(lu_mem, sizeof(t)), \ + cast(lu_mem, n)*cast(lu_mem, sizeof(t))))) #endif diff --git a/lobject.h b/lobject.h index 9170d81b..415f8080 100644 --- a/lobject.h +++ b/lobject.h @@ -1,5 +1,5 @@ /* -** $Id: lobject.h,v 1.109 2001/06/28 14:56:25 roberto Exp roberto $ +** $Id: lobject.h,v 1.110 2001/08/27 15:16:28 roberto Exp $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ @@ -22,6 +22,10 @@ #endif +#ifndef cast +#define cast(t, exp) ((t)(exp)) +#endif + /* tags for values visible from Lua == first user-created tag */ #define NUM_TAGS 6 @@ -96,7 +100,7 @@ typedef union TString { } TString; -#define getstr(ts) ((l_char *)((ts) + 1)) +#define getstr(ts) cast(l_char *, (ts) + 1) #define svalue(o) getstr(tsvalue(o)) @@ -196,7 +200,7 @@ typedef struct Hash { /* ** `module' operation for hashing (size is always a power of 2) */ -#define lmod(s,size) ((int)((s) & ((size)-1))) +#define lmod(s,size) (cast(int, (s) & ((size)-1))) /* @@ -217,7 +221,7 @@ typedef struct CallInfo { extern const TObject luaO_nilobject; -#define luaO_openspace(L,n,t) ((t *)luaO_openspaceaux(L,(n)*sizeof(t))) +#define luaO_openspace(L,n,t) cast(t *, luaO_openspaceaux(L,(n)*sizeof(t))) void *luaO_openspaceaux (lua_State *L, size_t n); int luaO_equalObj (const TObject *t1, const TObject *t2); diff --git a/lopcodes.c b/lopcodes.c index e2169830..932ac073 100644 --- a/lopcodes.c +++ b/lopcodes.c @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.c,v 1.2 2001/07/03 17:02:02 roberto Exp roberto $ +** $Id: lopcodes.c,v 1.3 2001/08/27 15:14:57 roberto Exp $ ** extracted automatically from lopcodes.h by mkprint.lua ** DO NOT EDIT ** See Copyright Notice in lua.h @@ -9,6 +9,7 @@ #define LUA_PRIVATE #include "lua.h" +#include "lobject.h" #include "lopcodes.h" diff --git a/lopcodes.h b/lopcodes.h index 1fba78f3..f581dd1d 100644 --- a/lopcodes.h +++ b/lopcodes.h @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.h,v 1.78 2001/07/24 17:19:07 roberto Exp roberto $ +** $Id: lopcodes.h,v 1.79 2001/08/27 15:14:57 roberto Exp $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ @@ -76,37 +76,37 @@ enum OpMode {iABC, iABc, iAsBc}; /* basic instruction format */ ** the following macros help to manipulate instructions */ -#define GET_OPCODE(i) ((OpCode)((i)&MASK1(SIZE_OP,0))) -#define SET_OPCODE(i,o) (((i)&MASK0(SIZE_OP,0)) | (Instruction)(o)) +#define GET_OPCODE(i) (cast(OpCode, (i)&MASK1(SIZE_OP,0))) +#define SET_OPCODE(i,o) (((i)&MASK0(SIZE_OP,0)) | cast(Instruction, o)) -#define GETARG_A(i) ((int)((i)>>POS_A)) +#define GETARG_A(i) (cast(int, (i)>>POS_A)) #define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ - ((Instruction)(u)<>POS_B) & MASK1(SIZE_B,0))) +#define GETARG_B(i) (cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0))) #define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ - ((Instruction)(b)<>POS_C) & MASK1(SIZE_C,0))) +#define GETARG_C(i) (cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0))) #define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ - ((Instruction)(b)<>POS_Bc) & MASK1(SIZE_Bc,0))) +#define GETARG_Bc(i) (cast(int, ((i)>>POS_Bc) & MASK1(SIZE_Bc,0))) #define SETARG_Bc(i,b) ((i) = (((i)&MASK0(SIZE_Bc,POS_Bc)) | \ - ((Instruction)(b)<fs; adjustlocalvars(ls, nparams); luaX_checklimit(ls, fs->nactloc, MAXPARAMS, l_s("parameters")); - fs->f->numparams = (short)fs->nactloc; /* `self' could be there already */ + fs->f->numparams = cast(short, fs->nactloc); /* `self' could be there already */ fs->f->is_vararg = dots; if (dots) { new_localvarstr(ls, l_s("arg"), 0); @@ -758,13 +758,13 @@ static BinOpr subexpr (LexState *ls, expdesc *v, int limit) { else simpleexp(ls, v); /* expand while operators have priorities higher than `limit' */ op = getbinopr(ls->t.token); - while (op != OPR_NOBINOPR && (int)priority[op].left > limit) { + while (op != OPR_NOBINOPR && cast(int, priority[op].left) > limit) { expdesc v2; BinOpr nextop; next(ls); luaK_infix(ls->fs, op, v); /* read sub-expression with higher priority */ - nextop = subexpr(ls, &v2, (int)priority[op].right); + nextop = subexpr(ls, &v2, cast(int, priority[op].right)); luaK_posfix(ls->fs, op, v, &v2); op = nextop; } diff --git a/lstate.c b/lstate.c index 90b395d8..456f1d6e 100644 --- a/lstate.c +++ b/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 1.65 2001/06/21 16:41:34 roberto Exp roberto $ +** $Id: lstate.c,v 1.66 2001/07/17 17:54:46 roberto Exp $ ** Global State ** See Copyright Notice in lua.h */ @@ -33,7 +33,7 @@ static void close_state (lua_State *L, lua_State *OL); ** open parts that may cause memory-allocation errors */ static void f_luaopen (lua_State *L, void *ud) { - struct Sopen *so = (struct Sopen *)ud; + struct Sopen *so = cast(struct Sopen *, ud); if (so->stacksize == 0) so->stacksize = DEFAULT_STACK_SIZE; else diff --git a/lstring.c b/lstring.c index 1454dc17..a5e0205d 100644 --- a/lstring.c +++ b/lstring.c @@ -1,5 +1,5 @@ /* -** $Id: lstring.c,v 1.65 2001/06/15 20:36:57 roberto Exp roberto $ +** $Id: lstring.c,v 1.66 2001/08/27 15:16:28 roberto Exp $ ** String table (keeps all strings handled by Lua) ** See Copyright Notice in lua.h */ @@ -35,7 +35,7 @@ void luaS_resize (lua_State *L, int newsize) { TString *next = p->tsv.nexthash; /* save next */ lu_hash h = p->tsv.hash; int h1 = lmod(h, newsize); /* new position */ - lua_assert((int)(h%newsize) == lmod(h, newsize)); + lua_assert(cast(int, h%newsize) == lmod(h, newsize)); p->tsv.nexthash = newhash[h1]; /* chain it in new position */ newhash[h1] = p; p = next; @@ -48,7 +48,7 @@ void luaS_resize (lua_State *L, int newsize) { static TString *newlstr (lua_State *L, const l_char *str, size_t l, lu_hash h) { - TString *ts = (TString *)luaM_malloc(L, sizestring(l)); + TString *ts = cast(TString *, luaM_malloc(L, sizestring(l))); stringtable *tb; ts->tsv.nexthash = NULL; ts->tsv.len = l; @@ -61,7 +61,7 @@ static TString *newlstr (lua_State *L, const l_char *str, size_t l, lu_hash h) { ts->tsv.nexthash = tb->hash[h]; /* chain new entry */ tb->hash[h] = ts; tb->nuse++; - if (tb->nuse > (ls_nstr)tb->size && tb->size <= MAX_INT/2) + if (tb->nuse > cast(ls_nstr, tb->size) && tb->size <= MAX_INT/2) luaS_resize(L, tb->size*2); /* too crowded */ return ts; } @@ -85,7 +85,7 @@ TString *luaS_newlstr (lua_State *L, const l_char *str, size_t l) { Udata *luaS_newudata (lua_State *L, size_t s) { - Udata *u = (Udata *)luaM_malloc(L, sizeudata(s)); + Udata *u = cast(Udata *, luaM_malloc(L, sizeudata(s))); u->uv.len = s; u->uv.tag = 0; u->uv.value = u + 1; diff --git a/lstring.h b/lstring.h index 02cbc1ab..f8fb0b60 100644 --- a/lstring.h +++ b/lstring.h @@ -1,5 +1,5 @@ /* -** $Id: lstring.h,v 1.32 2001/06/06 18:00:19 roberto Exp roberto $ +** $Id: lstring.h,v 1.33 2001/06/15 20:36:57 roberto Exp $ ** String table (keep all strings handled by Lua) ** See Copyright Notice in lua.h */ @@ -21,10 +21,10 @@ #define RESERVEDMARK 3 -#define sizestring(l) ((lu_mem)sizeof(union TString)+ \ - ((lu_mem)(l)+1)*sizeof(l_char)) +#define sizestring(l) (cast(lu_mem, sizeof(union TString))+ \ + (cast(lu_mem, l)+1)*sizeof(l_char)) -#define sizeudata(l) ((lu_mem)sizeof(union Udata)+(l)) +#define sizeudata(l) (cast(lu_mem, sizeof(union Udata))+(l)) #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) #define luaS_newliteral(L, s) (luaS_newlstr(L, l_s("") s, \ diff --git a/lstrlib.c b/lstrlib.c index 88f61547..8c3892b0 100644 --- a/lstrlib.c +++ b/lstrlib.c @@ -91,7 +91,7 @@ static int str_byte (lua_State *L) { size_t l; const l_char *s = luaL_check_lstr(L, 1, &l); sint32 pos = posrelat(luaL_opt_long(L, 2, 1), l); - luaL_arg_check(L, 0 3 || /* extra argument? */ strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ const l_char *s2 = lmemfind(s+init, l1-init, p, l2); @@ -603,7 +603,7 @@ static int str_format (lua_State *L) { sprintf(buff, form, luaL_check_int(L, arg)); break; case l_c('o'): case l_c('u'): case l_c('x'): case l_c('X'): - sprintf(buff, form, (unsigned int)luaL_check_number(L, arg)); + sprintf(buff, form, (unsigned int)(luaL_check_number(L, arg))); break; case l_c('e'): case l_c('E'): case l_c('f'): case l_c('g'): case l_c('G'): diff --git a/ltable.c b/ltable.c index 2cafc51b..e29e1819 100644 --- a/ltable.c +++ b/ltable.c @@ -32,9 +32,9 @@ #define TagDefault LUA_TTABLE -#define hashnum(t,n) (node(t, lmod((lu_hash)(ls_hash)(n), t->size))) -#define hashstr(t,str) (node(t, lmod((str)->tsv.hash, t->size))) -#define hashpointer(t,p) (node(t, lmod(IntPoint(p), t->size))) +#define hashnum(t,n) (node(t, lmod(cast(lu_hash, cast(ls_hash, n)), t->size))) +#define hashstr(t,str) (node(t, lmod((str)->tsv.hash, t->size))) +#define hashpointer(t,p) (node(t, lmod(IntPoint(p), t->size))) /* @@ -61,8 +61,8 @@ Node *luaH_next (lua_State *L, Hash *t, const TObject *key) { const TObject *v = luaH_get(t, key); if (v == &luaO_nilobject) luaD_error(L, l_s("invalid key for `next'")); - i = (int)(((const lu_byte *)v - - (const lu_byte *)(val(node(t, 0)))) / sizeof(Node)) + 1; + i = cast(int, (cast(const lu_byte *, v) - + cast(const lu_byte *, val(node(t, 0)))) / sizeof(Node)) + 1; } for (; isize; i++) { Node *n = node(t, i); @@ -259,8 +259,8 @@ const TObject *luaH_get (Hash *t, const TObject *key) { switch (ttype(key)) { case LUA_TSTRING: return luaH_getstr(t, tsvalue(key)); case LUA_TNUMBER: { - int k = (int)nvalue(key); - if ((lua_Number)k == nvalue(key)) /* is an integer index? */ + int k = cast(int, nvalue(key)); + if (cast(lua_Number, k) == nvalue(key)) /* is an integer index? */ return luaH_getnum(t, k); /* use specialized version */ /* else go through */ } diff --git a/ltable.h b/ltable.h index 24ec0355..f342a6f0 100644 --- a/ltable.h +++ b/ltable.h @@ -14,7 +14,7 @@ #define key(_n) (&(_n)->key) #define val(_n) (&(_n)->val) -#define settableval(p,v) setobj((TObject *)p, v) +#define settableval(p,v) setobj(cast(TObject *, p), v) const TObject *luaH_getnum (Hash *t, int key); diff --git a/ltests.c b/ltests.c index 3eb0ec1b..35c6f027 100644 --- a/ltests.c +++ b/ltests.c @@ -64,7 +64,7 @@ static void setnameval (lua_State *L, const l_char *name, int val) { #define MARK 0x55 /* 01010101 (a nice pattern) */ -#define blocksize(b) ((size_t *)(b) - HEADER/sizeof(size_t)) +#define blocksize(b) (cast(size_t *, b) - HEADER/sizeof(size_t)) unsigned long memdebug_numblocks = 0; unsigned long memdebug_total = 0; @@ -77,7 +77,7 @@ static void *checkblock (void *block) { size_t size = *b; int i; for (i=0;i size) oldsize = size; if (block) { - memcpy((char *)newblock+HEADER, block, oldsize); + memcpy(cast(char *, newblock)+HEADER, block, oldsize); freeblock(block); /* erase (and check) old copy */ } /* initialize new part of the block with something `weird' */ - memset((char *)newblock+HEADER+oldsize, -MARK, size-oldsize); + memset(cast(char *, newblock)+HEADER+oldsize, -MARK, size-oldsize); memdebug_total += size; if (memdebug_total > memdebug_maxmem) memdebug_maxmem = memdebug_total; memdebug_numblocks++; - *(size_t *)newblock = size; + *cast(size_t *, newblock) = size; for (i=0;i= NUM_TAGS) ? 1 : (int)luaT_validevents[t][e]; + return (t >= NUM_TAGS) ? 1 : cast(int, luaT_validevents[t][e]); } @@ -88,7 +88,7 @@ int luaT_newtag (lua_State *L, const l_char *name, int basictype) { TObject otag; ts = luaS_new(L, name); v = luaH_getstr(G(L)->type2tag, ts); - if (ttype(v) == LUA_TNUMBER) return (int)nvalue(v); + if (ttype(v) == LUA_TNUMBER) return cast(int, nvalue(v)); setnvalue(&otag, tag); luaH_setstr(L, G(L)->type2tag, ts, &otag); } diff --git a/lvm.c b/lvm.c index b043c916..b9d36938 100644 --- a/lvm.c +++ b/lvm.c @@ -293,8 +293,8 @@ void luaV_strconc (lua_State *L, int total, StkId top) { luaG_concaterror(L, top-2, top-1); } else if (tsvalue(top-1)->tsv.len > 0) { /* if len=0, do nothing */ /* at least two string values; get as many as possible */ - lu_mem tl = (lu_mem)tsvalue(top-1)->tsv.len + - (lu_mem)tsvalue(top-2)->tsv.len; + lu_mem tl = cast(lu_mem, tsvalue(top-1)->tsv.len) + + cast(lu_mem, tsvalue(top-2)->tsv.len); l_char *buffer; int i; while (n < total && !tostring(L, top-n-1)) { /* collect total length */ @@ -618,7 +618,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { runtime_check(L, ttype(ra) == LUA_TTABLE && ttype(ra+1) == LUA_TNUMBER); t = hvalue(ra); - n = (int)nvalue(ra+1); + n = cast(int, nvalue(ra+1)); n = luaH_nexti(t, n); if (n != -1) { /* repeat loop? */ Node *node = node(t, n);