aboutsummaryrefslogtreecommitdiff
path: root/lparser.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-07-27 13:32:59 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-07-27 13:32:59 -0300
commit0acd55898d0aaae8dbc14c8a1bc1e3bdffc8701b (patch)
tree0ac634fed90877130b1f102bf4075af999de2158 /lparser.c
parent15231d4fb2f6984b25e0353ff46eda1a180b686d (diff)
downloadlua-0acd55898d0aaae8dbc14c8a1bc1e3bdffc8701b.tar.gz
lua-0acd55898d0aaae8dbc14c8a1bc1e3bdffc8701b.tar.bz2
lua-0acd55898d0aaae8dbc14c8a1bc1e3bdffc8701b.zip
Added gcc option '-Wconversion'
No warnings for standard numerical types. Still pending alternative numerical types.
Diffstat (limited to 'lparser.c')
-rw-r--r--lparser.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/lparser.c b/lparser.c
index 0ed9631a..452ab19e 100644
--- a/lparser.c
+++ b/lparser.c
@@ -172,7 +172,8 @@ static void codename (LexState *ls, expdesc *e) {
172** Register a new local variable in the active 'Proto' (for debug 172** Register a new local variable in the active 'Proto' (for debug
173** information). 173** information).
174*/ 174*/
175static int registerlocalvar (LexState *ls, FuncState *fs, TString *varname) { 175static short registerlocalvar (LexState *ls, FuncState *fs,
176 TString *varname) {
176 Proto *f = fs->f; 177 Proto *f = fs->f;
177 int oldsize = f->sizelocvars; 178 int oldsize = f->sizelocvars;
178 luaM_growvector(ls->L, f->locvars, fs->ndebugvars, f->sizelocvars, 179 luaM_growvector(ls->L, f->locvars, fs->ndebugvars, f->sizelocvars,
@@ -190,7 +191,7 @@ static int registerlocalvar (LexState *ls, FuncState *fs, TString *varname) {
190** Create a new local variable with the given 'name' and given 'kind'. 191** Create a new local variable with the given 'name' and given 'kind'.
191** Return its index in the function. 192** Return its index in the function.
192*/ 193*/
193static int new_localvarkind (LexState *ls, TString *name, int kind) { 194static int new_localvarkind (LexState *ls, TString *name, lu_byte kind) {
194 lua_State *L = ls->L; 195 lua_State *L = ls->L;
195 FuncState *fs = ls->fs; 196 FuncState *fs = ls->fs;
196 Dyndata *dyd = ls->dyd; 197 Dyndata *dyd = ls->dyd;
@@ -234,11 +235,11 @@ static Vardesc *getlocalvardesc (FuncState *fs, int vidx) {
234** register. For that, search for the highest variable below that level 235** register. For that, search for the highest variable below that level
235** that is in a register and uses its register index ('ridx') plus one. 236** that is in a register and uses its register index ('ridx') plus one.
236*/ 237*/
237static int reglevel (FuncState *fs, int nvar) { 238static lu_byte reglevel (FuncState *fs, int nvar) {
238 while (nvar-- > 0) { 239 while (nvar-- > 0) {
239 Vardesc *vd = getlocalvardesc(fs, nvar); /* get previous variable */ 240 Vardesc *vd = getlocalvardesc(fs, nvar); /* get previous variable */
240 if (vd->vd.kind != RDKCTC) /* is in a register? */ 241 if (vd->vd.kind != RDKCTC) /* is in a register? */
241 return vd->vd.ridx + 1; 242 return cast_byte(vd->vd.ridx + 1);
242 } 243 }
243 return 0; /* no variables in registers */ 244 return 0; /* no variables in registers */
244} 245}
@@ -248,7 +249,7 @@ static int reglevel (FuncState *fs, int nvar) {
248** Return the number of variables in the register stack for the given 249** Return the number of variables in the register stack for the given
249** function. 250** function.
250*/ 251*/
251int luaY_nvarstack (FuncState *fs) { 252lu_byte luaY_nvarstack (FuncState *fs) {
252 return reglevel(fs, fs->nactvar); 253 return reglevel(fs, fs->nactvar);
253} 254}
254 255
@@ -274,7 +275,7 @@ static LocVar *localdebuginfo (FuncState *fs, int vidx) {
274static void init_var (FuncState *fs, expdesc *e, int vidx) { 275static void init_var (FuncState *fs, expdesc *e, int vidx) {
275 e->f = e->t = NO_JUMP; 276 e->f = e->t = NO_JUMP;
276 e->k = VLOCAL; 277 e->k = VLOCAL;
277 e->u.var.vidx = vidx; 278 e->u.var.vidx = cast(unsigned short, vidx);
278 e->u.var.ridx = getlocalvardesc(fs, vidx)->vd.ridx; 279 e->u.var.ridx = getlocalvardesc(fs, vidx)->vd.ridx;
279} 280}
280 281
@@ -323,7 +324,7 @@ static void adjustlocalvars (LexState *ls, int nvars) {
323 for (i = 0; i < nvars; i++) { 324 for (i = 0; i < nvars; i++) {
324 int vidx = fs->nactvar++; 325 int vidx = fs->nactvar++;
325 Vardesc *var = getlocalvardesc(fs, vidx); 326 Vardesc *var = getlocalvardesc(fs, vidx);
326 var->vd.ridx = reglevel++; 327 var->vd.ridx = cast_byte(reglevel++);
327 var->vd.pidx = registerlocalvar(ls, fs, var->vd.name); 328 var->vd.pidx = registerlocalvar(ls, fs, var->vd.name);
328 } 329 }
329} 330}
@@ -505,7 +506,7 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
505 if (needed > 0) 506 if (needed > 0)
506 luaK_reserveregs(fs, needed); /* registers for extra values */ 507 luaK_reserveregs(fs, needed); /* registers for extra values */
507 else /* adding 'needed' is actually a subtraction */ 508 else /* adding 'needed' is actually a subtraction */
508 fs->freereg += needed; /* remove extra values */ 509 fs->freereg = cast_byte(fs->freereg + needed); /* remove extra values */
509} 510}
510 511
511 512
@@ -682,7 +683,7 @@ static void leaveblock (FuncState *fs) {
682 BlockCnt *bl = fs->bl; 683 BlockCnt *bl = fs->bl;
683 LexState *ls = fs->ls; 684 LexState *ls = fs->ls;
684 int hasclose = 0; 685 int hasclose = 0;
685 int stklevel = reglevel(fs, bl->nactvar); /* level outside the block */ 686 lu_byte stklevel = reglevel(fs, bl->nactvar); /* level outside the block */
686 removevars(fs, bl->nactvar); /* remove block locals */ 687 removevars(fs, bl->nactvar); /* remove block locals */
687 lua_assert(bl->nactvar == fs->nactvar); /* back to level on entry */ 688 lua_assert(bl->nactvar == fs->nactvar); /* back to level on entry */
688 if (bl->isloop) /* has to fix pending breaks? */ 689 if (bl->isloop) /* has to fix pending breaks? */
@@ -856,7 +857,7 @@ typedef struct ConsControl {
856static void recfield (LexState *ls, ConsControl *cc) { 857static void recfield (LexState *ls, ConsControl *cc) {
857 /* recfield -> (NAME | '['exp']') = exp */ 858 /* recfield -> (NAME | '['exp']') = exp */
858 FuncState *fs = ls->fs; 859 FuncState *fs = ls->fs;
859 int reg = ls->fs->freereg; 860 lu_byte reg = ls->fs->freereg;
860 expdesc tab, key, val; 861 expdesc tab, key, val;
861 if (ls->t.token == TK_NAME) { 862 if (ls->t.token == TK_NAME) {
862 checklimit(fs, cc->nh, INT_MAX, "items in a constructor"); 863 checklimit(fs, cc->nh, INT_MAX, "items in a constructor");
@@ -939,7 +940,7 @@ static void field (LexState *ls, ConsControl *cc) {
939static int maxtostore (FuncState *fs) { 940static int maxtostore (FuncState *fs) {
940 int numfreeregs = MAX_FSTACK - fs->freereg; 941 int numfreeregs = MAX_FSTACK - fs->freereg;
941 if (numfreeregs >= 160) /* "lots" of registers? */ 942 if (numfreeregs >= 160) /* "lots" of registers? */
942 return numfreeregs / 5u; /* use up to 1/5 of them */ 943 return numfreeregs / 5; /* use up to 1/5 of them */
943 else if (numfreeregs >= 80) /* still "enough" registers? */ 944 else if (numfreeregs >= 80) /* still "enough" registers? */
944 return 10; /* one 'SETLIST' instruction for each 10 values */ 945 return 10; /* one 'SETLIST' instruction for each 10 values */
945 else /* save registers for potential more nesting */ 946 else /* save registers for potential more nesting */
@@ -1090,8 +1091,9 @@ static void funcargs (LexState *ls, expdesc *f) {
1090 } 1091 }
1091 init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); 1092 init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));
1092 luaK_fixline(fs, line); 1093 luaK_fixline(fs, line);
1093 fs->freereg = base+1; /* call removes function and arguments and leaves 1094 /* call removes function and arguments and leaves one result (unless
1094 one result (unless changed later) */ 1095 changed later) */
1096 fs->freereg = cast_byte(base + 1);
1095} 1097}
1096 1098
1097 1099
@@ -1356,7 +1358,7 @@ struct LHS_assign {
1356*/ 1358*/
1357static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { 1359static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
1358 FuncState *fs = ls->fs; 1360 FuncState *fs = ls->fs;
1359 int extra = fs->freereg; /* eventual position to save local variable */ 1361 lu_byte extra = fs->freereg; /* eventual position to save local variable */
1360 int conflict = 0; 1362 int conflict = 0;
1361 for (; lh; lh = lh->prev) { /* check all previous assignments */ 1363 for (; lh; lh = lh->prev) { /* check all previous assignments */
1362 if (vkisindexed(lh->v.k)) { /* assignment to table field? */ 1364 if (vkisindexed(lh->v.k)) { /* assignment to table field? */
@@ -1723,7 +1725,7 @@ static void localfunc (LexState *ls) {
1723} 1725}
1724 1726
1725 1727
1726static int getlocalattribute (LexState *ls) { 1728static lu_byte getlocalattribute (LexState *ls) {
1727 /* ATTRIB -> ['<' Name '>'] */ 1729 /* ATTRIB -> ['<' Name '>'] */
1728 if (testnext(ls, '<')) { 1730 if (testnext(ls, '<')) {
1729 TString *ts = str_checkname(ls); 1731 TString *ts = str_checkname(ls);
@@ -1760,7 +1762,7 @@ static void localstat (LexState *ls) {
1760 expdesc e; 1762 expdesc e;
1761 do { 1763 do {
1762 TString *vname = str_checkname(ls); 1764 TString *vname = str_checkname(ls);
1763 int kind = getlocalattribute(ls); 1765 lu_byte kind = getlocalattribute(ls);
1764 vidx = new_localvarkind(ls, vname, kind); 1766 vidx = new_localvarkind(ls, vname, kind);
1765 if (kind == RDKTOCLOSE) { /* to-be-closed? */ 1767 if (kind == RDKTOCLOSE) { /* to-be-closed? */
1766 if (toclose != -1) /* one already present? */ 1768 if (toclose != -1) /* one already present? */