Browse Source

Details

Names in the parser and other details that do not change actual code.
pull/25/head
Roberto Ierusalimschy 4 years ago
parent
commit
d9d2904f09
  1. 2
      README.md
  2. 6
      lcode.c
  3. 4
      ldblib.c
  4. 46
      lparser.c
  5. 6
      lparser.h

2
README.md

@ -2,6 +2,6 @@
This 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/). This 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/).
Please **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). Please **do not** send pull requests. To report issues, post a message to the [Lua mailing list](https://www.lua.org/lua-l.html).
Download official Lua releases from [Lua.org](https://www.lua.org/download.html). Download official Lua releases from [Lua.org](https://www.lua.org/download.html).

6
lcode.c

@ -763,7 +763,7 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) {
break; break;
} }
case VLOCAL: { /* already in a register */ case VLOCAL: { /* already in a register */
e->u.info = e->u.var.sidx; e->u.info = e->u.var.ridx;
e->k = VNONRELOC; /* becomes a non-relocatable value */ e->k = VNONRELOC; /* becomes a non-relocatable value */
break; break;
} }
@ -1036,7 +1036,7 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
switch (var->k) { switch (var->k) {
case VLOCAL: { case VLOCAL: {
freeexp(fs, ex); freeexp(fs, ex);
exp2reg(fs, ex, var->u.var.sidx); /* compute 'ex' into proper place */ exp2reg(fs, ex, var->u.var.ridx); /* compute 'ex' into proper place */
return; return;
} }
case VUPVAL: { case VUPVAL: {
@ -1276,7 +1276,7 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
} }
else { else {
/* register index of the table */ /* register index of the table */
t->u.ind.t = (t->k == VLOCAL) ? t->u.var.sidx: t->u.info; t->u.ind.t = (t->k == VLOCAL) ? t->u.var.ridx: t->u.info;
if (isKstr(fs, k)) { if (isKstr(fs, k)) {
t->u.ind.idx = k->u.info; /* literal string */ t->u.ind.idx = k->u.info; /* literal string */
t->k = VINDEXSTR; t->k = VINDEXSTR;

4
ldblib.c

@ -377,7 +377,7 @@ static int db_sethook (lua_State *L) {
} }
if (!luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)) { if (!luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)) {
/* table just created; initialize it */ /* table just created; initialize it */
lua_pushstring(L, "k"); lua_pushliteral(L, "k");
lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */ lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
lua_pushvalue(L, -1); lua_pushvalue(L, -1);
lua_setmetatable(L, -2); /* metatable(hooktable) = hooktable */ lua_setmetatable(L, -2); /* metatable(hooktable) = hooktable */
@ -420,7 +420,7 @@ static int db_debug (lua_State *L) {
for (;;) { for (;;) {
char buffer[250]; char buffer[250];
lua_writestringerror("%s", "lua_debug> "); lua_writestringerror("%s", "lua_debug> ");
if (fgets(buffer, sizeof(buffer), stdin) == 0 || if (fgets(buffer, sizeof(buffer), stdin) == NULL ||
strcmp(buffer, "cont\n") == 0) strcmp(buffer, "cont\n") == 0)
return 0; return 0;
if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||

46
lparser.c

@ -222,26 +222,26 @@ static Vardesc *getlocalvardesc (FuncState *fs, int vidx) {
/* /*
** Convert 'nvar', a compiler index level, to it corresponding ** Convert 'nvar', a compiler index level, to its corresponding
** stack index level. For that, search for the highest variable ** register. For that, search for the highest variable below that level
** below that level that is in the stack and uses its stack ** that is in a register and uses its register index ('ridx') plus one.
** index ('sidx').
*/ */
static int stacklevel (FuncState *fs, int nvar) { static int reglevel (FuncState *fs, int nvar) {
while (nvar-- > 0) { while (nvar-- > 0) {
Vardesc *vd = getlocalvardesc(fs, nvar); /* get variable */ Vardesc *vd = getlocalvardesc(fs, nvar); /* get previous variable */
if (vd->vd.kind != RDKCTC) /* is in the stack? */ if (vd->vd.kind != RDKCTC) /* is in a register? */
return vd->vd.sidx + 1; return vd->vd.ridx + 1;
} }
return 0; /* no variables in the stack */ return 0; /* no variables in registers */
} }
/* /*
** Return the number of variables in the stack for function 'fs' ** Return the number of variables in the register stack for the given
** function.
*/ */
int luaY_nvarstack (FuncState *fs) { int luaY_nvarstack (FuncState *fs) {
return stacklevel(fs, fs->nactvar); return reglevel(fs, fs->nactvar);
} }
@ -267,7 +267,7 @@ static void init_var (FuncState *fs, expdesc *e, int vidx) {
e->f = e->t = NO_JUMP; e->f = e->t = NO_JUMP;
e->k = VLOCAL; e->k = VLOCAL;
e->u.var.vidx = vidx; e->u.var.vidx = vidx;
e->u.var.sidx = getlocalvardesc(fs, vidx)->vd.sidx; e->u.var.ridx = getlocalvardesc(fs, vidx)->vd.ridx;
} }
@ -310,12 +310,12 @@ static void check_readonly (LexState *ls, expdesc *e) {
*/ */
static void adjustlocalvars (LexState *ls, int nvars) { static void adjustlocalvars (LexState *ls, int nvars) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
int stklevel = luaY_nvarstack(fs); int reglevel = luaY_nvarstack(fs);
int i; int i;
for (i = 0; i < nvars; i++) { for (i = 0; i < nvars; i++) {
int vidx = fs->nactvar++; int vidx = fs->nactvar++;
Vardesc *var = getlocalvardesc(fs, vidx); Vardesc *var = getlocalvardesc(fs, vidx);
var->vd.sidx = stklevel++; var->vd.ridx = reglevel++;
var->vd.pidx = registerlocalvar(ls, fs, var->vd.name); var->vd.pidx = registerlocalvar(ls, fs, var->vd.name);
} }
} }
@ -366,7 +366,7 @@ static int newupvalue (FuncState *fs, TString *name, expdesc *v) {
FuncState *prev = fs->prev; FuncState *prev = fs->prev;
if (v->k == VLOCAL) { if (v->k == VLOCAL) {
up->instack = 1; up->instack = 1;
up->idx = v->u.var.sidx; up->idx = v->u.var.ridx;
up->kind = getlocalvardesc(prev, v->u.var.vidx)->vd.kind; up->kind = getlocalvardesc(prev, v->u.var.vidx)->vd.kind;
lua_assert(eqstr(name, getlocalvardesc(prev, v->u.var.vidx)->vd.name)); lua_assert(eqstr(name, getlocalvardesc(prev, v->u.var.vidx)->vd.name));
} }
@ -620,7 +620,7 @@ static void movegotosout (FuncState *fs, BlockCnt *bl) {
for (i = bl->firstgoto; i < gl->n; i++) { /* for each pending goto */ for (i = bl->firstgoto; i < gl->n; i++) { /* for each pending goto */
Labeldesc *gt = &gl->arr[i]; Labeldesc *gt = &gl->arr[i];
/* leaving a variable scope? */ /* leaving a variable scope? */
if (stacklevel(fs, gt->nactvar) > stacklevel(fs, bl->nactvar)) if (reglevel(fs, gt->nactvar) > reglevel(fs, bl->nactvar))
gt->close |= bl->upval; /* jump may need a close */ gt->close |= bl->upval; /* jump may need a close */
gt->nactvar = bl->nactvar; /* update goto level */ gt->nactvar = bl->nactvar; /* update goto level */
} }
@ -661,7 +661,7 @@ static void leaveblock (FuncState *fs) {
BlockCnt *bl = fs->bl; BlockCnt *bl = fs->bl;
LexState *ls = fs->ls; LexState *ls = fs->ls;
int hasclose = 0; int hasclose = 0;
int stklevel = stacklevel(fs, bl->nactvar); /* level outside the block */ int stklevel = reglevel(fs, bl->nactvar); /* level outside the block */
if (bl->isloop) /* fix pending breaks? */ if (bl->isloop) /* fix pending breaks? */
hasclose = createlabel(ls, luaS_newliteral(ls->L, "break"), 0, 0); hasclose = createlabel(ls, luaS_newliteral(ls->L, "break"), 0, 0);
if (!hasclose && bl->previous && bl->upval) if (!hasclose && bl->previous && bl->upval)
@ -1330,13 +1330,13 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
} }
} }
else { /* table is a register */ else { /* table is a register */
if (v->k == VLOCAL && lh->v.u.ind.t == v->u.var.sidx) { if (v->k == VLOCAL && lh->v.u.ind.t == v->u.var.ridx) {
conflict = 1; /* table is the local being assigned now */ conflict = 1; /* table is the local being assigned now */
lh->v.u.ind.t = extra; /* assignment will use safe copy */ lh->v.u.ind.t = extra; /* assignment will use safe copy */
} }
/* is index the local being assigned? */ /* is index the local being assigned? */
if (lh->v.k == VINDEXED && v->k == VLOCAL && if (lh->v.k == VINDEXED && v->k == VLOCAL &&
lh->v.u.ind.idx == v->u.var.sidx) { lh->v.u.ind.idx == v->u.var.ridx) {
conflict = 1; conflict = 1;
lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */ lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */
} }
@ -1346,7 +1346,7 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
if (conflict) { if (conflict) {
/* copy upvalue/local value to a temporary (in position 'extra') */ /* copy upvalue/local value to a temporary (in position 'extra') */
if (v->k == VLOCAL) if (v->k == VLOCAL)
luaK_codeABC(fs, OP_MOVE, extra, v->u.var.sidx, 0); luaK_codeABC(fs, OP_MOVE, extra, v->u.var.ridx, 0);
else else
luaK_codeABC(fs, OP_GETUPVAL, extra, v->u.info, 0); luaK_codeABC(fs, OP_GETUPVAL, extra, v->u.info, 0);
luaK_reserveregs(fs, 1); luaK_reserveregs(fs, 1);
@ -1411,7 +1411,7 @@ static void gotostat (LexState *ls) {
newgotoentry(ls, name, line, luaK_jump(fs)); newgotoentry(ls, name, line, luaK_jump(fs));
else { /* found a label */ else { /* found a label */
/* backward jump; will be resolved here */ /* backward jump; will be resolved here */
int lblevel = stacklevel(fs, lb->nactvar); /* label level */ int lblevel = reglevel(fs, lb->nactvar); /* label level */
if (luaY_nvarstack(fs) > lblevel) /* leaving the scope of a variable? */ if (luaY_nvarstack(fs) > lblevel) /* leaving the scope of a variable? */
luaK_codeABC(fs, OP_CLOSE, lblevel, 0, 0); luaK_codeABC(fs, OP_CLOSE, lblevel, 0, 0);
/* create jump and link it to the label */ /* create jump and link it to the label */
@ -1488,7 +1488,7 @@ static void repeatstat (LexState *ls, int line) {
if (bl2.upval) { /* upvalues? */ if (bl2.upval) { /* upvalues? */
int exit = luaK_jump(fs); /* normal exit must jump over fix */ int exit = luaK_jump(fs); /* normal exit must jump over fix */
luaK_patchtohere(fs, condexit); /* repetition must close upvalues */ luaK_patchtohere(fs, condexit); /* repetition must close upvalues */
luaK_codeABC(fs, OP_CLOSE, stacklevel(fs, bl2.nactvar), 0, 0); luaK_codeABC(fs, OP_CLOSE, reglevel(fs, bl2.nactvar), 0, 0);
condexit = luaK_jump(fs); /* repeat after closing upvalues */ condexit = luaK_jump(fs); /* repeat after closing upvalues */
luaK_patchtohere(fs, exit); /* normal exit comes to here */ luaK_patchtohere(fs, exit); /* normal exit comes to here */
} }
@ -1708,7 +1708,7 @@ static void checktoclose (LexState *ls, int level) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
markupval(fs, level + 1); markupval(fs, level + 1);
fs->bl->insidetbc = 1; /* in the scope of a to-be-closed variable */ fs->bl->insidetbc = 1; /* in the scope of a to-be-closed variable */
luaK_codeABC(fs, OP_TBC, stacklevel(fs, level), 0, 0); luaK_codeABC(fs, OP_TBC, reglevel(fs, level), 0, 0);
} }
} }

6
lparser.h

@ -35,7 +35,7 @@ typedef enum {
(string is fixed by the lexer) */ (string is fixed by the lexer) */
VNONRELOC, /* expression has its value in a fixed register; VNONRELOC, /* expression has its value in a fixed register;
info = result register */ info = result register */
VLOCAL, /* local variable; var.sidx = stack index (local register); VLOCAL, /* local variable; var.ridx = register index;
var.vidx = relative index in 'actvar.arr' */ var.vidx = relative index in 'actvar.arr' */
VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */
VCONST, /* compile-time <const> variable; VCONST, /* compile-time <const> variable;
@ -77,7 +77,7 @@ typedef struct expdesc {
lu_byte t; /* table (register or upvalue) */ lu_byte t; /* table (register or upvalue) */
} ind; } ind;
struct { /* for local variables */ struct { /* for local variables */
lu_byte sidx; /* index in the stack */ lu_byte ridx; /* register holding the variable */
unsigned short vidx; /* compiler index (in 'actvar.arr') */ unsigned short vidx; /* compiler index (in 'actvar.arr') */
} var; } var;
} u; } u;
@ -97,7 +97,7 @@ typedef union Vardesc {
struct { struct {
TValuefields; /* constant value (if it is a compile-time constant) */ TValuefields; /* constant value (if it is a compile-time constant) */
lu_byte kind; lu_byte kind;
lu_byte sidx; /* index of the variable in the stack */ lu_byte ridx; /* register holding the variable */
short pidx; /* index of the variable in the Proto's 'locvars' array */ short pidx; /* index of the variable in the Proto's 'locvars' array */
TString *name; /* variable name */ TString *name; /* variable name */
} vd; } vd;

Loading…
Cancel
Save