diff options
Diffstat (limited to 'lparser.c')
-rw-r--r-- | lparser.c | 46 |
1 files changed, 23 insertions, 23 deletions
@@ -222,26 +222,26 @@ static Vardesc *getlocalvardesc (FuncState *fs, int vidx) { | |||
222 | 222 | ||
223 | 223 | ||
224 | /* | 224 | /* |
225 | ** Convert 'nvar', a compiler index level, to it corresponding | 225 | ** Convert 'nvar', a compiler index level, to its corresponding |
226 | ** stack index level. For that, search for the highest variable | 226 | ** register. For that, search for the highest variable below that level |
227 | ** below that level that is in the stack and uses its stack | 227 | ** that is in a register and uses its register index ('ridx') plus one. |
228 | ** index ('sidx'). | ||
229 | */ | 228 | */ |
230 | static int stacklevel (FuncState *fs, int nvar) { | 229 | static int reglevel (FuncState *fs, int nvar) { |
231 | while (nvar-- > 0) { | 230 | while (nvar-- > 0) { |
232 | Vardesc *vd = getlocalvardesc(fs, nvar); /* get variable */ | 231 | Vardesc *vd = getlocalvardesc(fs, nvar); /* get previous variable */ |
233 | if (vd->vd.kind != RDKCTC) /* is in the stack? */ | 232 | if (vd->vd.kind != RDKCTC) /* is in a register? */ |
234 | return vd->vd.sidx + 1; | 233 | return vd->vd.ridx + 1; |
235 | } | 234 | } |
236 | return 0; /* no variables in the stack */ | 235 | return 0; /* no variables in registers */ |
237 | } | 236 | } |
238 | 237 | ||
239 | 238 | ||
240 | /* | 239 | /* |
241 | ** Return the number of variables in the stack for function 'fs' | 240 | ** Return the number of variables in the register stack for the given |
241 | ** function. | ||
242 | */ | 242 | */ |
243 | int luaY_nvarstack (FuncState *fs) { | 243 | int luaY_nvarstack (FuncState *fs) { |
244 | return stacklevel(fs, fs->nactvar); | 244 | return reglevel(fs, fs->nactvar); |
245 | } | 245 | } |
246 | 246 | ||
247 | 247 | ||
@@ -267,7 +267,7 @@ static void init_var (FuncState *fs, expdesc *e, int vidx) { | |||
267 | e->f = e->t = NO_JUMP; | 267 | e->f = e->t = NO_JUMP; |
268 | e->k = VLOCAL; | 268 | e->k = VLOCAL; |
269 | e->u.var.vidx = vidx; | 269 | e->u.var.vidx = vidx; |
270 | e->u.var.sidx = getlocalvardesc(fs, vidx)->vd.sidx; | 270 | e->u.var.ridx = getlocalvardesc(fs, vidx)->vd.ridx; |
271 | } | 271 | } |
272 | 272 | ||
273 | 273 | ||
@@ -310,12 +310,12 @@ static void check_readonly (LexState *ls, expdesc *e) { | |||
310 | */ | 310 | */ |
311 | static void adjustlocalvars (LexState *ls, int nvars) { | 311 | static void adjustlocalvars (LexState *ls, int nvars) { |
312 | FuncState *fs = ls->fs; | 312 | FuncState *fs = ls->fs; |
313 | int stklevel = luaY_nvarstack(fs); | 313 | int reglevel = luaY_nvarstack(fs); |
314 | int i; | 314 | int i; |
315 | for (i = 0; i < nvars; i++) { | 315 | for (i = 0; i < nvars; i++) { |
316 | int vidx = fs->nactvar++; | 316 | int vidx = fs->nactvar++; |
317 | Vardesc *var = getlocalvardesc(fs, vidx); | 317 | Vardesc *var = getlocalvardesc(fs, vidx); |
318 | var->vd.sidx = stklevel++; | 318 | var->vd.ridx = reglevel++; |
319 | var->vd.pidx = registerlocalvar(ls, fs, var->vd.name); | 319 | var->vd.pidx = registerlocalvar(ls, fs, var->vd.name); |
320 | } | 320 | } |
321 | } | 321 | } |
@@ -366,7 +366,7 @@ static int newupvalue (FuncState *fs, TString *name, expdesc *v) { | |||
366 | FuncState *prev = fs->prev; | 366 | FuncState *prev = fs->prev; |
367 | if (v->k == VLOCAL) { | 367 | if (v->k == VLOCAL) { |
368 | up->instack = 1; | 368 | up->instack = 1; |
369 | up->idx = v->u.var.sidx; | 369 | up->idx = v->u.var.ridx; |
370 | up->kind = getlocalvardesc(prev, v->u.var.vidx)->vd.kind; | 370 | up->kind = getlocalvardesc(prev, v->u.var.vidx)->vd.kind; |
371 | lua_assert(eqstr(name, getlocalvardesc(prev, v->u.var.vidx)->vd.name)); | 371 | lua_assert(eqstr(name, getlocalvardesc(prev, v->u.var.vidx)->vd.name)); |
372 | } | 372 | } |
@@ -620,7 +620,7 @@ static void movegotosout (FuncState *fs, BlockCnt *bl) { | |||
620 | for (i = bl->firstgoto; i < gl->n; i++) { /* for each pending goto */ | 620 | for (i = bl->firstgoto; i < gl->n; i++) { /* for each pending goto */ |
621 | Labeldesc *gt = &gl->arr[i]; | 621 | Labeldesc *gt = &gl->arr[i]; |
622 | /* leaving a variable scope? */ | 622 | /* leaving a variable scope? */ |
623 | if (stacklevel(fs, gt->nactvar) > stacklevel(fs, bl->nactvar)) | 623 | if (reglevel(fs, gt->nactvar) > reglevel(fs, bl->nactvar)) |
624 | gt->close |= bl->upval; /* jump may need a close */ | 624 | gt->close |= bl->upval; /* jump may need a close */ |
625 | gt->nactvar = bl->nactvar; /* update goto level */ | 625 | gt->nactvar = bl->nactvar; /* update goto level */ |
626 | } | 626 | } |
@@ -661,7 +661,7 @@ static void leaveblock (FuncState *fs) { | |||
661 | BlockCnt *bl = fs->bl; | 661 | BlockCnt *bl = fs->bl; |
662 | LexState *ls = fs->ls; | 662 | LexState *ls = fs->ls; |
663 | int hasclose = 0; | 663 | int hasclose = 0; |
664 | int stklevel = stacklevel(fs, bl->nactvar); /* level outside the block */ | 664 | int stklevel = reglevel(fs, bl->nactvar); /* level outside the block */ |
665 | if (bl->isloop) /* fix pending breaks? */ | 665 | if (bl->isloop) /* fix pending breaks? */ |
666 | hasclose = createlabel(ls, luaS_newliteral(ls->L, "break"), 0, 0); | 666 | hasclose = createlabel(ls, luaS_newliteral(ls->L, "break"), 0, 0); |
667 | if (!hasclose && bl->previous && bl->upval) | 667 | if (!hasclose && bl->previous && bl->upval) |
@@ -1330,13 +1330,13 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { | |||
1330 | } | 1330 | } |
1331 | } | 1331 | } |
1332 | else { /* table is a register */ | 1332 | else { /* table is a register */ |
1333 | if (v->k == VLOCAL && lh->v.u.ind.t == v->u.var.sidx) { | 1333 | if (v->k == VLOCAL && lh->v.u.ind.t == v->u.var.ridx) { |
1334 | conflict = 1; /* table is the local being assigned now */ | 1334 | conflict = 1; /* table is the local being assigned now */ |
1335 | lh->v.u.ind.t = extra; /* assignment will use safe copy */ | 1335 | lh->v.u.ind.t = extra; /* assignment will use safe copy */ |
1336 | } | 1336 | } |
1337 | /* is index the local being assigned? */ | 1337 | /* is index the local being assigned? */ |
1338 | if (lh->v.k == VINDEXED && v->k == VLOCAL && | 1338 | if (lh->v.k == VINDEXED && v->k == VLOCAL && |
1339 | lh->v.u.ind.idx == v->u.var.sidx) { | 1339 | lh->v.u.ind.idx == v->u.var.ridx) { |
1340 | conflict = 1; | 1340 | conflict = 1; |
1341 | lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */ | 1341 | lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */ |
1342 | } | 1342 | } |
@@ -1346,7 +1346,7 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { | |||
1346 | if (conflict) { | 1346 | if (conflict) { |
1347 | /* copy upvalue/local value to a temporary (in position 'extra') */ | 1347 | /* copy upvalue/local value to a temporary (in position 'extra') */ |
1348 | if (v->k == VLOCAL) | 1348 | if (v->k == VLOCAL) |
1349 | luaK_codeABC(fs, OP_MOVE, extra, v->u.var.sidx, 0); | 1349 | luaK_codeABC(fs, OP_MOVE, extra, v->u.var.ridx, 0); |
1350 | else | 1350 | else |
1351 | luaK_codeABC(fs, OP_GETUPVAL, extra, v->u.info, 0); | 1351 | luaK_codeABC(fs, OP_GETUPVAL, extra, v->u.info, 0); |
1352 | luaK_reserveregs(fs, 1); | 1352 | luaK_reserveregs(fs, 1); |
@@ -1411,7 +1411,7 @@ static void gotostat (LexState *ls) { | |||
1411 | newgotoentry(ls, name, line, luaK_jump(fs)); | 1411 | newgotoentry(ls, name, line, luaK_jump(fs)); |
1412 | else { /* found a label */ | 1412 | else { /* found a label */ |
1413 | /* backward jump; will be resolved here */ | 1413 | /* backward jump; will be resolved here */ |
1414 | int lblevel = stacklevel(fs, lb->nactvar); /* label level */ | 1414 | int lblevel = reglevel(fs, lb->nactvar); /* label level */ |
1415 | if (luaY_nvarstack(fs) > lblevel) /* leaving the scope of a variable? */ | 1415 | if (luaY_nvarstack(fs) > lblevel) /* leaving the scope of a variable? */ |
1416 | luaK_codeABC(fs, OP_CLOSE, lblevel, 0, 0); | 1416 | luaK_codeABC(fs, OP_CLOSE, lblevel, 0, 0); |
1417 | /* create jump and link it to the label */ | 1417 | /* create jump and link it to the label */ |
@@ -1488,7 +1488,7 @@ static void repeatstat (LexState *ls, int line) { | |||
1488 | if (bl2.upval) { /* upvalues? */ | 1488 | if (bl2.upval) { /* upvalues? */ |
1489 | int exit = luaK_jump(fs); /* normal exit must jump over fix */ | 1489 | int exit = luaK_jump(fs); /* normal exit must jump over fix */ |
1490 | luaK_patchtohere(fs, condexit); /* repetition must close upvalues */ | 1490 | luaK_patchtohere(fs, condexit); /* repetition must close upvalues */ |
1491 | luaK_codeABC(fs, OP_CLOSE, stacklevel(fs, bl2.nactvar), 0, 0); | 1491 | luaK_codeABC(fs, OP_CLOSE, reglevel(fs, bl2.nactvar), 0, 0); |
1492 | condexit = luaK_jump(fs); /* repeat after closing upvalues */ | 1492 | condexit = luaK_jump(fs); /* repeat after closing upvalues */ |
1493 | luaK_patchtohere(fs, exit); /* normal exit comes to here */ | 1493 | luaK_patchtohere(fs, exit); /* normal exit comes to here */ |
1494 | } | 1494 | } |
@@ -1708,7 +1708,7 @@ static void checktoclose (LexState *ls, int level) { | |||
1708 | FuncState *fs = ls->fs; | 1708 | FuncState *fs = ls->fs; |
1709 | markupval(fs, level + 1); | 1709 | markupval(fs, level + 1); |
1710 | fs->bl->insidetbc = 1; /* in the scope of a to-be-closed variable */ | 1710 | fs->bl->insidetbc = 1; /* in the scope of a to-be-closed variable */ |
1711 | luaK_codeABC(fs, OP_TBC, stacklevel(fs, level), 0, 0); | 1711 | luaK_codeABC(fs, OP_TBC, reglevel(fs, level), 0, 0); |
1712 | } | 1712 | } |
1713 | } | 1713 | } |
1714 | 1714 | ||