aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--lcode.c6
-rw-r--r--ldblib.c4
-rw-r--r--lparser.c46
-rw-r--r--lparser.h6
5 files changed, 32 insertions, 32 deletions
diff --git a/README.md b/README.md
index 5893dc9a..5bc0ee77 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,6 @@
2 2
3This is the repository of Lua development code, as seen by the Lua team. It contains the full history of all commits but is mirrored irregularly. For complete information about Lua, visit [Lua.org](https://www.lua.org/). 3This is the repository of Lua development code, as seen by the Lua team. It contains the full history of all commits but is mirrored irregularly. For complete information about Lua, visit [Lua.org](https://www.lua.org/).
4 4
5Please **do not** send pull requests. To report issues and send patches, post a message to the [Lua mailing list](https://www.lua.org/lua-l.html). 5Please **do not** send pull requests. To report issues, post a message to the [Lua mailing list](https://www.lua.org/lua-l.html).
6 6
7Download official Lua releases from [Lua.org](https://www.lua.org/download.html). 7Download official Lua releases from [Lua.org](https://www.lua.org/download.html).
diff --git a/lcode.c b/lcode.c
index 14d41f1a..97e427b2 100644
--- a/lcode.c
+++ b/lcode.c
@@ -763,7 +763,7 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) {
763 break; 763 break;
764 } 764 }
765 case VLOCAL: { /* already in a register */ 765 case VLOCAL: { /* already in a register */
766 e->u.info = e->u.var.sidx; 766 e->u.info = e->u.var.ridx;
767 e->k = VNONRELOC; /* becomes a non-relocatable value */ 767 e->k = VNONRELOC; /* becomes a non-relocatable value */
768 break; 768 break;
769 } 769 }
@@ -1036,7 +1036,7 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
1036 switch (var->k) { 1036 switch (var->k) {
1037 case VLOCAL: { 1037 case VLOCAL: {
1038 freeexp(fs, ex); 1038 freeexp(fs, ex);
1039 exp2reg(fs, ex, var->u.var.sidx); /* compute 'ex' into proper place */ 1039 exp2reg(fs, ex, var->u.var.ridx); /* compute 'ex' into proper place */
1040 return; 1040 return;
1041 } 1041 }
1042 case VUPVAL: { 1042 case VUPVAL: {
@@ -1276,7 +1276,7 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
1276 } 1276 }
1277 else { 1277 else {
1278 /* register index of the table */ 1278 /* register index of the table */
1279 t->u.ind.t = (t->k == VLOCAL) ? t->u.var.sidx: t->u.info; 1279 t->u.ind.t = (t->k == VLOCAL) ? t->u.var.ridx: t->u.info;
1280 if (isKstr(fs, k)) { 1280 if (isKstr(fs, k)) {
1281 t->u.ind.idx = k->u.info; /* literal string */ 1281 t->u.ind.idx = k->u.info; /* literal string */
1282 t->k = VINDEXSTR; 1282 t->k = VINDEXSTR;
diff --git a/ldblib.c b/ldblib.c
index 5a326ade..15593bfb 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -377,7 +377,7 @@ static int db_sethook (lua_State *L) {
377 } 377 }
378 if (!luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)) { 378 if (!luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)) {
379 /* table just created; initialize it */ 379 /* table just created; initialize it */
380 lua_pushstring(L, "k"); 380 lua_pushliteral(L, "k");
381 lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */ 381 lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
382 lua_pushvalue(L, -1); 382 lua_pushvalue(L, -1);
383 lua_setmetatable(L, -2); /* metatable(hooktable) = hooktable */ 383 lua_setmetatable(L, -2); /* metatable(hooktable) = hooktable */
@@ -420,7 +420,7 @@ static int db_debug (lua_State *L) {
420 for (;;) { 420 for (;;) {
421 char buffer[250]; 421 char buffer[250];
422 lua_writestringerror("%s", "lua_debug> "); 422 lua_writestringerror("%s", "lua_debug> ");
423 if (fgets(buffer, sizeof(buffer), stdin) == 0 || 423 if (fgets(buffer, sizeof(buffer), stdin) == NULL ||
424 strcmp(buffer, "cont\n") == 0) 424 strcmp(buffer, "cont\n") == 0)
425 return 0; 425 return 0;
426 if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || 426 if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
diff --git a/lparser.c b/lparser.c
index 77813a74..249ba9a4 100644
--- a/lparser.c
+++ b/lparser.c
@@ -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*/
230static int stacklevel (FuncState *fs, int nvar) { 229static 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*/
243int luaY_nvarstack (FuncState *fs) { 243int 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*/
311static void adjustlocalvars (LexState *ls, int nvars) { 311static 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
diff --git a/lparser.h b/lparser.h
index 2e6dae72..5e4500f1 100644
--- a/lparser.h
+++ b/lparser.h
@@ -35,7 +35,7 @@ typedef enum {
35 (string is fixed by the lexer) */ 35 (string is fixed by the lexer) */
36 VNONRELOC, /* expression has its value in a fixed register; 36 VNONRELOC, /* expression has its value in a fixed register;
37 info = result register */ 37 info = result register */
38 VLOCAL, /* local variable; var.sidx = stack index (local register); 38 VLOCAL, /* local variable; var.ridx = register index;
39 var.vidx = relative index in 'actvar.arr' */ 39 var.vidx = relative index in 'actvar.arr' */
40 VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ 40 VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */
41 VCONST, /* compile-time <const> variable; 41 VCONST, /* compile-time <const> variable;
@@ -77,7 +77,7 @@ typedef struct expdesc {
77 lu_byte t; /* table (register or upvalue) */ 77 lu_byte t; /* table (register or upvalue) */
78 } ind; 78 } ind;
79 struct { /* for local variables */ 79 struct { /* for local variables */
80 lu_byte sidx; /* index in the stack */ 80 lu_byte ridx; /* register holding the variable */
81 unsigned short vidx; /* compiler index (in 'actvar.arr') */ 81 unsigned short vidx; /* compiler index (in 'actvar.arr') */
82 } var; 82 } var;
83 } u; 83 } u;
@@ -97,7 +97,7 @@ typedef union Vardesc {
97 struct { 97 struct {
98 TValuefields; /* constant value (if it is a compile-time constant) */ 98 TValuefields; /* constant value (if it is a compile-time constant) */
99 lu_byte kind; 99 lu_byte kind;
100 lu_byte sidx; /* index of the variable in the stack */ 100 lu_byte ridx; /* register holding the variable */
101 short pidx; /* index of the variable in the Proto's 'locvars' array */ 101 short pidx; /* index of the variable in the Proto's 'locvars' array */
102 TString *name; /* variable name */ 102 TString *name; /* variable name */
103 } vd; 103 } vd;