From 0d529138042563baf260366e19a7aa2c60a07174 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 30 Jul 2019 12:18:19 -0300 Subject: Change in the syntax of attributes Attributes changed to posfixed ('x ', instead of ' x'), and "toclose" renamed to "close". Posfixed attributes seem to make it clearer that it applies to only one variable when there are multiple variables. --- lparser.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'lparser.c') diff --git a/lparser.c b/lparser.c index f1d2ce85..2dcd320c 100644 --- a/lparser.c +++ b/lparser.c @@ -190,7 +190,7 @@ static int registerlocalvar (LexState *ls, FuncState *fs, TString *varname) { ** Create a new local variable with the given 'name'. Return its index ** in the function. */ -static int new_localvar (LexState *ls, TString *name, int kind) { +static int new_localvar (LexState *ls, TString *name) { lua_State *L = ls->L; FuncState *fs = ls->fs; Dyndata *dyd = ls->dyd; @@ -200,14 +200,14 @@ static int new_localvar (LexState *ls, TString *name, int kind) { luaM_growvector(L, dyd->actvar.arr, dyd->actvar.n + 1, dyd->actvar.size, Vardesc, USHRT_MAX, "local variables"); var = &dyd->actvar.arr[dyd->actvar.n++]; - var->vd.kind = kind; + var->vd.kind = VDKREG; /* default */ var->vd.name = name; return dyd->actvar.n - 1 - fs->firstlocal; } #define new_localvarliteral(ls,v) \ new_localvar(ls, \ - luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char)) - 1), VDKREG); + luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char)) - 1)); @@ -947,7 +947,7 @@ static void parlist (LexState *ls) { do { switch (ls->t.token) { case TK_NAME: { /* param -> NAME */ - new_localvar(ls, str_checkname(ls), VDKREG); + new_localvar(ls, str_checkname(ls)); nparams++; break; } @@ -1553,7 +1553,7 @@ static void fornum (LexState *ls, TString *varname, int line) { new_localvarliteral(ls, "(for state)"); new_localvarliteral(ls, "(for state)"); new_localvarliteral(ls, "(for state)"); - new_localvar(ls, varname, VDKREG); + new_localvar(ls, varname); checknext(ls, '='); exp1(ls); /* initial value */ checknext(ls, ','); @@ -1582,9 +1582,9 @@ static void forlist (LexState *ls, TString *indexname) { new_localvarliteral(ls, "(for state)"); new_localvarliteral(ls, "(for state)"); /* create declared variables */ - new_localvar(ls, indexname, VDKREG); + new_localvar(ls, indexname); while (testnext(ls, ',')) { - new_localvar(ls, str_checkname(ls), VDKREG); + new_localvar(ls, str_checkname(ls)); nvars++; } checknext(ls, TK_IN); @@ -1708,7 +1708,7 @@ static void localfunc (LexState *ls) { expdesc b; FuncState *fs = ls->fs; int fvar = fs->nactvar; /* function's variable index */ - new_localvar(ls, str_checkname(ls), VDKREG); /* new local variable */ + new_localvar(ls, str_checkname(ls)); /* new local variable */ adjustlocalvars(ls, 1); /* enter its scope */ body(ls, &b, 0, ls->linenumber); /* function created in next register */ /* debug information will only see the variable after this point! */ @@ -1723,7 +1723,7 @@ static int getlocalattribute (LexState *ls) { checknext(ls, '>'); if (strcmp(attr, "const") == 0) return RDKCONST; /* read-only variable */ - else if (strcmp(attr, "toclose") == 0) + else if (strcmp(attr, "close") == 0) return RDKTOCLOSE; /* to-be-closed variable */ else luaK_semerror(ls, @@ -1748,13 +1748,14 @@ static void localstat (LexState *ls) { FuncState *fs = ls->fs; int toclose = -1; /* index of to-be-closed variable (if any) */ Vardesc *var; /* last variable */ - int ivar; /* index of last variable */ + int ivar, kind; /* index and kind of last variable */ int nvars = 0; int nexps; expdesc e; do { - int kind = getlocalattribute(ls); - ivar = new_localvar(ls, str_checkname(ls), kind); + ivar = new_localvar(ls, str_checkname(ls)); + kind = getlocalattribute(ls); + getlocalvardesc(fs, ivar)->vd.kind = kind; if (kind == RDKTOCLOSE) { /* to-be-closed? */ if (toclose != -1) /* one already present? */ luaK_semerror(ls, "multiple to-be-closed variables in local list"); -- cgit v1.2.3-55-g6feb