diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-30 12:18:19 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-30 12:18:19 -0300 |
| commit | 0d529138042563baf260366e19a7aa2c60a07174 (patch) | |
| tree | ea8699a57a9b26e620a2ed6bc2a11c9e49dee780 /lparser.c | |
| parent | b80077b8f3e27a94c6afa895b41a9f8b52c42e61 (diff) | |
| download | lua-0d529138042563baf260366e19a7aa2c60a07174.tar.gz lua-0d529138042563baf260366e19a7aa2c60a07174.tar.bz2 lua-0d529138042563baf260366e19a7aa2c60a07174.zip | |
Change in the syntax of attributes
Attributes changed to posfixed ('x <const>', instead of '<const> 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.
Diffstat (limited to 'lparser.c')
| -rw-r--r-- | lparser.c | 25 |
1 files changed, 13 insertions, 12 deletions
| @@ -190,7 +190,7 @@ static int registerlocalvar (LexState *ls, FuncState *fs, TString *varname) { | |||
| 190 | ** Create a new local variable with the given 'name'. Return its index | 190 | ** Create a new local variable with the given 'name'. Return its index |
| 191 | ** in the function. | 191 | ** in the function. |
| 192 | */ | 192 | */ |
| 193 | static int new_localvar (LexState *ls, TString *name, int kind) { | 193 | static int new_localvar (LexState *ls, TString *name) { |
| 194 | lua_State *L = ls->L; | 194 | lua_State *L = ls->L; |
| 195 | FuncState *fs = ls->fs; | 195 | FuncState *fs = ls->fs; |
| 196 | Dyndata *dyd = ls->dyd; | 196 | Dyndata *dyd = ls->dyd; |
| @@ -200,14 +200,14 @@ static int new_localvar (LexState *ls, TString *name, int kind) { | |||
| 200 | luaM_growvector(L, dyd->actvar.arr, dyd->actvar.n + 1, | 200 | luaM_growvector(L, dyd->actvar.arr, dyd->actvar.n + 1, |
| 201 | dyd->actvar.size, Vardesc, USHRT_MAX, "local variables"); | 201 | dyd->actvar.size, Vardesc, USHRT_MAX, "local variables"); |
| 202 | var = &dyd->actvar.arr[dyd->actvar.n++]; | 202 | var = &dyd->actvar.arr[dyd->actvar.n++]; |
| 203 | var->vd.kind = kind; | 203 | var->vd.kind = VDKREG; /* default */ |
| 204 | var->vd.name = name; | 204 | var->vd.name = name; |
| 205 | return dyd->actvar.n - 1 - fs->firstlocal; | 205 | return dyd->actvar.n - 1 - fs->firstlocal; |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | #define new_localvarliteral(ls,v) \ | 208 | #define new_localvarliteral(ls,v) \ |
| 209 | new_localvar(ls, \ | 209 | new_localvar(ls, \ |
| 210 | luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char)) - 1), VDKREG); | 210 | luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char)) - 1)); |
| 211 | 211 | ||
| 212 | 212 | ||
| 213 | 213 | ||
| @@ -947,7 +947,7 @@ static void parlist (LexState *ls) { | |||
| 947 | do { | 947 | do { |
| 948 | switch (ls->t.token) { | 948 | switch (ls->t.token) { |
| 949 | case TK_NAME: { /* param -> NAME */ | 949 | case TK_NAME: { /* param -> NAME */ |
| 950 | new_localvar(ls, str_checkname(ls), VDKREG); | 950 | new_localvar(ls, str_checkname(ls)); |
| 951 | nparams++; | 951 | nparams++; |
| 952 | break; | 952 | break; |
| 953 | } | 953 | } |
| @@ -1553,7 +1553,7 @@ static void fornum (LexState *ls, TString *varname, int line) { | |||
| 1553 | new_localvarliteral(ls, "(for state)"); | 1553 | new_localvarliteral(ls, "(for state)"); |
| 1554 | new_localvarliteral(ls, "(for state)"); | 1554 | new_localvarliteral(ls, "(for state)"); |
| 1555 | new_localvarliteral(ls, "(for state)"); | 1555 | new_localvarliteral(ls, "(for state)"); |
| 1556 | new_localvar(ls, varname, VDKREG); | 1556 | new_localvar(ls, varname); |
| 1557 | checknext(ls, '='); | 1557 | checknext(ls, '='); |
| 1558 | exp1(ls); /* initial value */ | 1558 | exp1(ls); /* initial value */ |
| 1559 | checknext(ls, ','); | 1559 | checknext(ls, ','); |
| @@ -1582,9 +1582,9 @@ static void forlist (LexState *ls, TString *indexname) { | |||
| 1582 | new_localvarliteral(ls, "(for state)"); | 1582 | new_localvarliteral(ls, "(for state)"); |
| 1583 | new_localvarliteral(ls, "(for state)"); | 1583 | new_localvarliteral(ls, "(for state)"); |
| 1584 | /* create declared variables */ | 1584 | /* create declared variables */ |
| 1585 | new_localvar(ls, indexname, VDKREG); | 1585 | new_localvar(ls, indexname); |
| 1586 | while (testnext(ls, ',')) { | 1586 | while (testnext(ls, ',')) { |
| 1587 | new_localvar(ls, str_checkname(ls), VDKREG); | 1587 | new_localvar(ls, str_checkname(ls)); |
| 1588 | nvars++; | 1588 | nvars++; |
| 1589 | } | 1589 | } |
| 1590 | checknext(ls, TK_IN); | 1590 | checknext(ls, TK_IN); |
| @@ -1708,7 +1708,7 @@ static void localfunc (LexState *ls) { | |||
| 1708 | expdesc b; | 1708 | expdesc b; |
| 1709 | FuncState *fs = ls->fs; | 1709 | FuncState *fs = ls->fs; |
| 1710 | int fvar = fs->nactvar; /* function's variable index */ | 1710 | int fvar = fs->nactvar; /* function's variable index */ |
| 1711 | new_localvar(ls, str_checkname(ls), VDKREG); /* new local variable */ | 1711 | new_localvar(ls, str_checkname(ls)); /* new local variable */ |
| 1712 | adjustlocalvars(ls, 1); /* enter its scope */ | 1712 | adjustlocalvars(ls, 1); /* enter its scope */ |
| 1713 | body(ls, &b, 0, ls->linenumber); /* function created in next register */ | 1713 | body(ls, &b, 0, ls->linenumber); /* function created in next register */ |
| 1714 | /* debug information will only see the variable after this point! */ | 1714 | /* debug information will only see the variable after this point! */ |
| @@ -1723,7 +1723,7 @@ static int getlocalattribute (LexState *ls) { | |||
| 1723 | checknext(ls, '>'); | 1723 | checknext(ls, '>'); |
| 1724 | if (strcmp(attr, "const") == 0) | 1724 | if (strcmp(attr, "const") == 0) |
| 1725 | return RDKCONST; /* read-only variable */ | 1725 | return RDKCONST; /* read-only variable */ |
| 1726 | else if (strcmp(attr, "toclose") == 0) | 1726 | else if (strcmp(attr, "close") == 0) |
| 1727 | return RDKTOCLOSE; /* to-be-closed variable */ | 1727 | return RDKTOCLOSE; /* to-be-closed variable */ |
| 1728 | else | 1728 | else |
| 1729 | luaK_semerror(ls, | 1729 | luaK_semerror(ls, |
| @@ -1748,13 +1748,14 @@ static void localstat (LexState *ls) { | |||
| 1748 | FuncState *fs = ls->fs; | 1748 | FuncState *fs = ls->fs; |
| 1749 | int toclose = -1; /* index of to-be-closed variable (if any) */ | 1749 | int toclose = -1; /* index of to-be-closed variable (if any) */ |
| 1750 | Vardesc *var; /* last variable */ | 1750 | Vardesc *var; /* last variable */ |
| 1751 | int ivar; /* index of last variable */ | 1751 | int ivar, kind; /* index and kind of last variable */ |
| 1752 | int nvars = 0; | 1752 | int nvars = 0; |
| 1753 | int nexps; | 1753 | int nexps; |
| 1754 | expdesc e; | 1754 | expdesc e; |
| 1755 | do { | 1755 | do { |
| 1756 | int kind = getlocalattribute(ls); | 1756 | ivar = new_localvar(ls, str_checkname(ls)); |
| 1757 | ivar = new_localvar(ls, str_checkname(ls), kind); | 1757 | kind = getlocalattribute(ls); |
| 1758 | getlocalvardesc(fs, ivar)->vd.kind = kind; | ||
| 1758 | if (kind == RDKTOCLOSE) { /* to-be-closed? */ | 1759 | if (kind == RDKTOCLOSE) { /* to-be-closed? */ |
| 1759 | if (toclose != -1) /* one already present? */ | 1760 | if (toclose != -1) /* one already present? */ |
| 1760 | luaK_semerror(ls, "multiple to-be-closed variables in local list"); | 1761 | luaK_semerror(ls, "multiple to-be-closed variables in local list"); |
