diff options
Diffstat (limited to 'lparser.c')
| -rw-r--r-- | lparser.c | 13 |
1 files changed, 11 insertions, 2 deletions
| @@ -1682,13 +1682,22 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isgen) { | |||
| 1682 | } | 1682 | } |
| 1683 | 1683 | ||
| 1684 | 1684 | ||
| 1685 | /* | ||
| 1686 | ** Control whether for-loop control variables are read-only | ||
| 1687 | */ | ||
| 1688 | #if defined(LUA_COMPAT_LOOPVAR) | ||
| 1689 | #define LOOPVARKIND VDKREG | ||
| 1690 | #else /* by default, these variables are read only */ | ||
| 1691 | #define LOOPVARKIND RDKCONST | ||
| 1692 | #endif | ||
| 1693 | |||
| 1685 | static void fornum (LexState *ls, TString *varname, int line) { | 1694 | static void fornum (LexState *ls, TString *varname, int line) { |
| 1686 | /* fornum -> NAME = exp,exp[,exp] forbody */ | 1695 | /* fornum -> NAME = exp,exp[,exp] forbody */ |
| 1687 | FuncState *fs = ls->fs; | 1696 | FuncState *fs = ls->fs; |
| 1688 | int base = fs->freereg; | 1697 | int base = fs->freereg; |
| 1689 | new_localvarliteral(ls, "(for state)"); | 1698 | new_localvarliteral(ls, "(for state)"); |
| 1690 | new_localvarliteral(ls, "(for state)"); | 1699 | new_localvarliteral(ls, "(for state)"); |
| 1691 | new_varkind(ls, varname, RDKCONST); /* control variable */ | 1700 | new_varkind(ls, varname, LOOPVARKIND); /* control variable */ |
| 1692 | checknext(ls, '='); | 1701 | checknext(ls, '='); |
| 1693 | exp1(ls); /* initial value */ | 1702 | exp1(ls); /* initial value */ |
| 1694 | checknext(ls, ','); | 1703 | checknext(ls, ','); |
| @@ -1715,7 +1724,7 @@ static void forlist (LexState *ls, TString *indexname) { | |||
| 1715 | new_localvarliteral(ls, "(for state)"); /* iterator function */ | 1724 | new_localvarliteral(ls, "(for state)"); /* iterator function */ |
| 1716 | new_localvarliteral(ls, "(for state)"); /* state */ | 1725 | new_localvarliteral(ls, "(for state)"); /* state */ |
| 1717 | new_localvarliteral(ls, "(for state)"); /* closing var. (after swap) */ | 1726 | new_localvarliteral(ls, "(for state)"); /* closing var. (after swap) */ |
| 1718 | new_varkind(ls, indexname, RDKCONST); /* control variable */ | 1727 | new_varkind(ls, indexname, LOOPVARKIND); /* control variable */ |
| 1719 | /* other declared variables */ | 1728 | /* other declared variables */ |
| 1720 | while (testnext(ls, ',')) { | 1729 | while (testnext(ls, ',')) { |
| 1721 | new_localvar(ls, str_checkname(ls)); | 1730 | new_localvar(ls, str_checkname(ls)); |
