diff options
| -rw-r--r-- | lparser.c | 53 | ||||
| -rw-r--r-- | manual/manual.of | 30 | ||||
| -rwxr-xr-x | testes/all.lua | 2 | ||||
| -rw-r--r-- | testes/calls.lua | 2 | ||||
| -rw-r--r-- | testes/closure.lua | 2 | ||||
| -rw-r--r-- | testes/code.lua | 2 | ||||
| -rw-r--r-- | testes/files.lua | 2 | ||||
| -rw-r--r-- | testes/goto.lua | 12 | ||||
| -rw-r--r-- | testes/literals.lua | 2 | ||||
| -rw-r--r-- | testes/locals.lua | 22 | ||||
| -rw-r--r-- | testes/math.lua | 7 | ||||
| -rw-r--r-- | testes/nextvar.lua | 2 | ||||
| -rw-r--r-- | testes/pm.lua | 2 | ||||
| -rw-r--r-- | testes/strings.lua | 2 | ||||
| -rw-r--r-- | testes/utf8.lua | 2 |
15 files changed, 84 insertions, 60 deletions
| @@ -1733,7 +1733,7 @@ static void localfunc (LexState *ls) { | |||
| 1733 | } | 1733 | } |
| 1734 | 1734 | ||
| 1735 | 1735 | ||
| 1736 | static lu_byte getvarattribute (LexState *ls) { | 1736 | static lu_byte getvarattribute (LexState *ls, lu_byte df) { |
| 1737 | /* attrib -> ['<' NAME '>'] */ | 1737 | /* attrib -> ['<' NAME '>'] */ |
| 1738 | if (testnext(ls, '<')) { | 1738 | if (testnext(ls, '<')) { |
| 1739 | TString *ts = str_checkname(ls); | 1739 | TString *ts = str_checkname(ls); |
| @@ -1746,7 +1746,7 @@ static lu_byte getvarattribute (LexState *ls) { | |||
| 1746 | else | 1746 | else |
| 1747 | luaK_semerror(ls, "unknown attribute '%s'", attr); | 1747 | luaK_semerror(ls, "unknown attribute '%s'", attr); |
| 1748 | } | 1748 | } |
| 1749 | return VDKREG; /* regular variable */ | 1749 | return df; /* return default value */ |
| 1750 | } | 1750 | } |
| 1751 | 1751 | ||
| 1752 | 1752 | ||
| @@ -1767,10 +1767,12 @@ static void localstat (LexState *ls) { | |||
| 1767 | int nvars = 0; | 1767 | int nvars = 0; |
| 1768 | int nexps; | 1768 | int nexps; |
| 1769 | expdesc e; | 1769 | expdesc e; |
| 1770 | do { | 1770 | /* get prefixed attribute (if any); default is regular local variable */ |
| 1771 | TString *vname = str_checkname(ls); | 1771 | lu_byte defkind = getvarattribute(ls, VDKREG); |
| 1772 | lu_byte kind = getvarattribute(ls); | 1772 | do { /* for each variable */ |
| 1773 | vidx = new_varkind(ls, vname, kind); | 1773 | TString *vname = str_checkname(ls); /* get its name */ |
| 1774 | lu_byte kind = getvarattribute(ls, defkind); /* postfixed attribute */ | ||
| 1775 | vidx = new_varkind(ls, vname, kind); /* predeclare it */ | ||
| 1774 | if (kind == RDKTOCLOSE) { /* to-be-closed? */ | 1776 | if (kind == RDKTOCLOSE) { /* to-be-closed? */ |
| 1775 | if (toclose != -1) /* one already present? */ | 1777 | if (toclose != -1) /* one already present? */ |
| 1776 | luaK_semerror(ls, "multiple to-be-closed variables in local list"); | 1778 | luaK_semerror(ls, "multiple to-be-closed variables in local list"); |
| @@ -1778,13 +1780,13 @@ static void localstat (LexState *ls) { | |||
| 1778 | } | 1780 | } |
| 1779 | nvars++; | 1781 | nvars++; |
| 1780 | } while (testnext(ls, ',')); | 1782 | } while (testnext(ls, ',')); |
| 1781 | if (testnext(ls, '=')) | 1783 | if (testnext(ls, '=')) /* initialization? */ |
| 1782 | nexps = explist(ls, &e); | 1784 | nexps = explist(ls, &e); |
| 1783 | else { | 1785 | else { |
| 1784 | e.k = VVOID; | 1786 | e.k = VVOID; |
| 1785 | nexps = 0; | 1787 | nexps = 0; |
| 1786 | } | 1788 | } |
| 1787 | var = getlocalvardesc(fs, vidx); /* get last variable */ | 1789 | var = getlocalvardesc(fs, vidx); /* retrieve last variable */ |
| 1788 | if (nvars == nexps && /* no adjustments? */ | 1790 | if (nvars == nexps && /* no adjustments? */ |
| 1789 | var->vd.kind == RDKCONST && /* last variable is const? */ | 1791 | var->vd.kind == RDKCONST && /* last variable is const? */ |
| 1790 | luaK_exp2const(fs, &e, &var->k)) { /* compile-time constant? */ | 1792 | luaK_exp2const(fs, &e, &var->k)) { /* compile-time constant? */ |
| @@ -1800,29 +1802,35 @@ static void localstat (LexState *ls) { | |||
| 1800 | } | 1802 | } |
| 1801 | 1803 | ||
| 1802 | 1804 | ||
| 1803 | static lu_byte getglobalattribute (LexState *ls) { | 1805 | static lu_byte getglobalattribute (LexState *ls, lu_byte df) { |
| 1804 | lu_byte kind = getvarattribute(ls); | 1806 | lu_byte kind = getvarattribute(ls, df); |
| 1805 | if (kind == RDKTOCLOSE) | 1807 | switch (kind) { |
| 1806 | luaK_semerror(ls, "global variables cannot be to-be-closed"); | 1808 | case RDKTOCLOSE: |
| 1807 | /* adjust kind for global variable */ | 1809 | luaK_semerror(ls, "global variables cannot be to-be-closed"); |
| 1808 | return (kind == VDKREG) ? GDKREG : GDKCONST; | 1810 | break; /* to avoid warnings */ |
| 1811 | case RDKCONST: | ||
| 1812 | return GDKCONST; /* adjust kind for global variable */ | ||
| 1813 | default: | ||
| 1814 | return kind; | ||
| 1815 | } | ||
| 1809 | } | 1816 | } |
| 1810 | 1817 | ||
| 1811 | 1818 | ||
| 1812 | static void globalstat (LexState *ls) { | 1819 | static void globalstat (LexState *ls) { |
| 1813 | /* globalstat -> (GLOBAL) '*' attrib | 1820 | /* globalstat -> (GLOBAL) attrib '*' |
| 1814 | globalstat -> (GLOBAL) NAME attrib {',' NAME attrib} */ | 1821 | globalstat -> (GLOBAL) attrib NAME attrib {',' NAME attrib} */ |
| 1815 | FuncState *fs = ls->fs; | 1822 | FuncState *fs = ls->fs; |
| 1823 | /* get prefixed attribute (if any); default is regular global variable */ | ||
| 1824 | lu_byte defkind = getglobalattribute(ls, GDKREG); | ||
| 1816 | if (testnext(ls, '*')) { | 1825 | if (testnext(ls, '*')) { |
| 1817 | lu_byte kind = getglobalattribute(ls); | ||
| 1818 | /* use NULL as name to represent '*' entries */ | 1826 | /* use NULL as name to represent '*' entries */ |
| 1819 | new_varkind(ls, NULL, kind); | 1827 | new_varkind(ls, NULL, defkind); |
| 1820 | fs->nactvar++; /* activate declaration */ | 1828 | fs->nactvar++; /* activate declaration */ |
| 1821 | } | 1829 | } |
| 1822 | else { | 1830 | else { |
| 1823 | do { | 1831 | do { /* list of names */ |
| 1824 | TString *vname = str_checkname(ls); | 1832 | TString *vname = str_checkname(ls); |
| 1825 | lu_byte kind = getglobalattribute(ls); | 1833 | lu_byte kind = getglobalattribute(ls, defkind); |
| 1826 | new_varkind(ls, vname, kind); | 1834 | new_varkind(ls, vname, kind); |
| 1827 | fs->nactvar++; /* activate declaration */ | 1835 | fs->nactvar++; /* activate declaration */ |
| 1828 | } while (testnext(ls, ',')); | 1836 | } while (testnext(ls, ',')); |
| @@ -2003,8 +2011,9 @@ static void statement (LexState *ls) { | |||
| 2003 | is not reserved */ | 2011 | is not reserved */ |
| 2004 | if (ls->t.seminfo.ts == ls->glbn) { /* current = "global"? */ | 2012 | if (ls->t.seminfo.ts == ls->glbn) { /* current = "global"? */ |
| 2005 | int lk = luaX_lookahead(ls); | 2013 | int lk = luaX_lookahead(ls); |
| 2006 | if (lk == TK_NAME || lk == '*' || lk == TK_FUNCTION) { | 2014 | if (lk == '<' || lk == TK_NAME || lk == '*' || lk == TK_FUNCTION) { |
| 2007 | /* 'global name' or 'global *' or 'global function' */ | 2015 | /* 'global <attrib>' or 'global name' or 'global *' or |
| 2016 | 'global function' */ | ||
| 2008 | globalstatfunc(ls, line); | 2017 | globalstatfunc(ls, line); |
| 2009 | break; | 2018 | break; |
| 2010 | } | 2019 | } |
diff --git a/manual/manual.of b/manual/manual.of index effb95da..eb97e853 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
| @@ -1651,43 +1651,47 @@ Function calls are explained in @See{functioncall}. | |||
| 1651 | Local and global variables can be declared anywhere inside a block. | 1651 | Local and global variables can be declared anywhere inside a block. |
| 1652 | The declaration for locals can include an initialization: | 1652 | The declaration for locals can include an initialization: |
| 1653 | @Produc{ | 1653 | @Produc{ |
| 1654 | @producname{stat}@producbody{@Rw{local} attnamelist @bnfopt{@bnfter{=} explist}} | 1654 | @producname{stat}@producbody{@Rw{local} |
| 1655 | attnamelist @bnfopt{@bnfter{=} explist}} | ||
| 1655 | @producname{stat}@producbody{@Rw{global} attnamelist} | 1656 | @producname{stat}@producbody{@Rw{global} attnamelist} |
| 1656 | @producname{attnamelist}@producbody{ | ||
| 1657 | @bnfNter{Name} @bnfopt{attrib} | ||
| 1658 | @bnfrep{@bnfter{,} @bnfNter{Name} @bnfopt{attrib}}} | ||
| 1659 | } | 1657 | } |
| 1660 | If present, an initial assignment has the same semantics | 1658 | If present, an initial assignment has the same semantics |
| 1661 | of a multiple assignment @see{assignment}. | 1659 | of a multiple assignment @see{assignment}. |
| 1662 | Otherwise, all local variables are initialized with @nil. | 1660 | Otherwise, all local variables are initialized with @nil. |
| 1663 | 1661 | ||
| 1664 | Each variable name may be postfixed by an attribute | 1662 | The list of names may be prefixed by an attribute |
| 1665 | (a name between angle brackets): | 1663 | (a name between angle brackets) |
| 1664 | and each variable name may be postfixed by an attribute: | ||
| 1666 | @Produc{ | 1665 | @Produc{ |
| 1666 | @producname{attnamelist}@producbody{ | ||
| 1667 | @bnfopt{attrib} @bnfNter{Name} @bnfopt{attrib} | ||
| 1668 | @bnfrep{@bnfter{,} @bnfNter{Name} @bnfopt{attrib}}} | ||
| 1667 | @producname{attrib}@producbody{@bnfter{<} @bnfNter{Name} @bnfter{>}} | 1669 | @producname{attrib}@producbody{@bnfter{<} @bnfNter{Name} @bnfter{>}} |
| 1668 | } | 1670 | } |
| 1671 | A prefixed attribute applies to all names in the list; | ||
| 1672 | a postfixed attribute applies to its particular name. | ||
| 1669 | There are two possible attributes: | 1673 | There are two possible attributes: |
| 1670 | @id{const}, which declares a @emph{constant} or @emph{read-only} variable, | 1674 | @id{const}, which declares a @emph{constant} or @emph{read-only} variable, |
| 1671 | @index{constant variable} | 1675 | @index{constant variable} |
| 1672 | that is, a variable that cannot be used as the left-hand side of an | 1676 | that is, a variable that cannot be used as the left-hand side of an |
| 1673 | assignment, | 1677 | assignment, |
| 1674 | and @id{close}, which declares a to-be-closed variable @see{to-be-closed}. | 1678 | and @id{close}, which declares a to-be-closed variable @see{to-be-closed}. |
| 1675 | A list of variables can contain at most one to-be-closed variable. | ||
| 1676 | Only local variables can have the @id{close} attribute. | 1679 | Only local variables can have the @id{close} attribute. |
| 1680 | A list of variables can contain at most one to-be-closed variable. | ||
| 1677 | 1681 | ||
| 1678 | Lua offers also a collective declaration for global variables: | 1682 | Lua offers also a collective declaration for global variables: |
| 1679 | @Produc{ | 1683 | @Produc{ |
| 1680 | @producname{stat}@producbody{@Rw{global} @bnfter{*} @bnfopt{attrib}} | 1684 | @producname{stat}@producbody{@Rw{global} @bnfopt{attrib} @bnfter{*}} |
| 1681 | } | 1685 | } |
| 1682 | This special form implicitly declares | 1686 | This special form implicitly declares |
| 1683 | as globals all names not explicitly declared previously. | 1687 | as globals all names not explicitly declared previously. |
| 1684 | In particular, | 1688 | In particular, |
| 1685 | @T{global * <const>} implicitly declares | 1689 | @T{global<const> *} implicitly declares |
| 1686 | as read-only globals all names not explicitly declared previously; | 1690 | as read-only globals all names not explicitly declared previously; |
| 1687 | see the following example: | 1691 | see the following example: |
| 1688 | @verbatim{ | 1692 | @verbatim{ |
| 1689 | global X | 1693 | global X |
| 1690 | global * <const> | 1694 | global<const> * |
| 1691 | print(math.pi) -- Ok, 'print' and 'math' are read-only | 1695 | print(math.pi) -- Ok, 'print' and 'math' are read-only |
| 1692 | X = 1 -- Ok, declared as read-write | 1696 | X = 1 -- Ok, declared as read-write |
| 1693 | Y = 1 -- Error, Y is read-only | 1697 | Y = 1 -- Error, Y is read-only |
| @@ -1700,7 +1704,7 @@ the scope of any other @Rw{global} declaration. | |||
| 1700 | Therefore, a program that does not use global declarations | 1704 | Therefore, a program that does not use global declarations |
| 1701 | or start with @T{global *} | 1705 | or start with @T{global *} |
| 1702 | has free read-write access to any global; | 1706 | has free read-write access to any global; |
| 1703 | a program that starts with @T{global * <const>} | 1707 | a program that starts with @T{global<const> *} |
| 1704 | has free read-only access to any global; | 1708 | has free read-only access to any global; |
| 1705 | and a program that starts with any other global declaration | 1709 | and a program that starts with any other global declaration |
| 1706 | (e.g., @T{global none}) can only refer to declared variables. | 1710 | (e.g., @T{global none}) can only refer to declared variables. |
| @@ -9620,11 +9624,11 @@ and @bnfNter{LiteralString}, see @See{lexical}.) | |||
| 9620 | @OrNL @Rw{global} @Rw{function} @bnfNter{Name} funcbody | 9624 | @OrNL @Rw{global} @Rw{function} @bnfNter{Name} funcbody |
| 9621 | @OrNL @Rw{local} attnamelist @bnfopt{@bnfter{=} explist} | 9625 | @OrNL @Rw{local} attnamelist @bnfopt{@bnfter{=} explist} |
| 9622 | @OrNL @Rw{global} attnamelist | 9626 | @OrNL @Rw{global} attnamelist |
| 9623 | @OrNL @Rw{global} @bnfter{*} @bnfopt{attrib} | 9627 | @OrNL @Rw{global} @bnfopt{attrib} @bnfter{*} |
| 9624 | } | 9628 | } |
| 9625 | 9629 | ||
| 9626 | @producname{attnamelist}@producbody{ | 9630 | @producname{attnamelist}@producbody{ |
| 9627 | @bnfNter{Name} @bnfopt{attrib} | 9631 | @bnfopt{attrib} @bnfNter{Name} @bnfopt{attrib} |
| 9628 | @bnfrep{@bnfter{,} @bnfNter{Name} @bnfopt{attrib}}} | 9632 | @bnfrep{@bnfter{,} @bnfNter{Name} @bnfopt{attrib}}} |
| 9629 | 9633 | ||
| 9630 | @producname{attrib}@producbody{@bnfter{<} @bnfNter{Name} @bnfter{>}} | 9634 | @producname{attrib}@producbody{@bnfter{<} @bnfNter{Name} @bnfter{>}} |
diff --git a/testes/all.lua b/testes/all.lua index 499c100d..d3e2f123 100755 --- a/testes/all.lua +++ b/testes/all.lua | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | -- $Id: testes/all.lua $ | 2 | -- $Id: testes/all.lua $ |
| 3 | -- See Copyright Notice in file lua.h | 3 | -- See Copyright Notice in file lua.h |
| 4 | 4 | ||
| 5 | global * <const> | 5 | global <const> * |
| 6 | 6 | ||
| 7 | global _soft, _port, _nomsg | 7 | global _soft, _port, _nomsg |
| 8 | global T | 8 | global T |
diff --git a/testes/calls.lua b/testes/calls.lua index 0ea1c4ab..21441701 100644 --- a/testes/calls.lua +++ b/testes/calls.lua | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | -- $Id: testes/calls.lua $ | 1 | -- $Id: testes/calls.lua $ |
| 2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
| 3 | 3 | ||
| 4 | global * <const> | 4 | global <const> * |
| 5 | 5 | ||
| 6 | print("testing functions and calls") | 6 | print("testing functions and calls") |
| 7 | 7 | ||
diff --git a/testes/closure.lua b/testes/closure.lua index c55d1583..0c2e96c0 100644 --- a/testes/closure.lua +++ b/testes/closure.lua | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | -- $Id: testes/closure.lua $ | 1 | -- $Id: testes/closure.lua $ |
| 2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
| 3 | 3 | ||
| 4 | global * <const> | 4 | global <const> * |
| 5 | 5 | ||
| 6 | print "testing closures" | 6 | print "testing closures" |
| 7 | 7 | ||
diff --git a/testes/code.lua b/testes/code.lua index b6ceb34c..633f4896 100644 --- a/testes/code.lua +++ b/testes/code.lua | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | -- $Id: testes/code.lua $ | 1 | -- $Id: testes/code.lua $ |
| 2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
| 3 | 3 | ||
| 4 | global * <const> | 4 | global <const> * |
| 5 | 5 | ||
| 6 | if T==nil then | 6 | if T==nil then |
| 7 | (Message or print)('\n >>> testC not active: skipping opcode tests <<<\n') | 7 | (Message or print)('\n >>> testC not active: skipping opcode tests <<<\n') |
diff --git a/testes/files.lua b/testes/files.lua index c2b355fb..d4e327b7 100644 --- a/testes/files.lua +++ b/testes/files.lua | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | -- $Id: testes/files.lua $ | 1 | -- $Id: testes/files.lua $ |
| 2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
| 3 | 3 | ||
| 4 | global * <const> | 4 | global <const> * |
| 5 | 5 | ||
| 6 | local debug = require "debug" | 6 | local debug = require "debug" |
| 7 | 7 | ||
diff --git a/testes/goto.lua b/testes/goto.lua index 3f1f6e69..44486e20 100644 --- a/testes/goto.lua +++ b/testes/goto.lua | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | -- $Id: testes/goto.lua $ | 1 | -- $Id: testes/goto.lua $ |
| 2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
| 3 | 3 | ||
| 4 | global require | 4 | global<const> require |
| 5 | global print, load, assert, string, setmetatable | 5 | global<const> print, load, assert, string, setmetatable |
| 6 | global collectgarbage, error | 6 | global<const> collectgarbage, error |
| 7 | 7 | ||
| 8 | print("testing goto and global declarations") | 8 | print("testing goto and global declarations") |
| 9 | 9 | ||
| @@ -304,7 +304,7 @@ do | |||
| 304 | 304 | ||
| 305 | -- global variables cannot be to-be-closed | 305 | -- global variables cannot be to-be-closed |
| 306 | checkerr("global X<close>", "cannot be") | 306 | checkerr("global X<close>", "cannot be") |
| 307 | checkerr("global * <close>", "cannot be") | 307 | checkerr("global <close> *", "cannot be") |
| 308 | 308 | ||
| 309 | do | 309 | do |
| 310 | local X = 10 | 310 | local X = 10 |
| @@ -345,7 +345,7 @@ do | |||
| 345 | end | 345 | end |
| 346 | 346 | ||
| 347 | checkerr([[ | 347 | checkerr([[ |
| 348 | global foo <const>; | 348 | global<const> foo; |
| 349 | function foo (x) return end -- ERROR: foo is read-only | 349 | function foo (x) return end -- ERROR: foo is read-only |
| 350 | ]], "assign to const variable 'foo'") | 350 | ]], "assign to const variable 'foo'") |
| 351 | 351 | ||
| @@ -357,7 +357,7 @@ do | |||
| 357 | ]], "%:2%:") -- correct line in error message | 357 | ]], "%:2%:") -- correct line in error message |
| 358 | 358 | ||
| 359 | checkerr([[ | 359 | checkerr([[ |
| 360 | global * <const>; | 360 | global<const> *; |
| 361 | print(X) -- Ok to use | 361 | print(X) -- Ok to use |
| 362 | Y = 1 -- ERROR | 362 | Y = 1 -- ERROR |
| 363 | ]], "assign to const variable 'Y'") | 363 | ]], "assign to const variable 'Y'") |
diff --git a/testes/literals.lua b/testes/literals.lua index fecdd6d3..336ef585 100644 --- a/testes/literals.lua +++ b/testes/literals.lua | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | print('testing scanner') | 4 | print('testing scanner') |
| 5 | 5 | ||
| 6 | global * <const> | 6 | global <const> * |
| 7 | 7 | ||
| 8 | local debug = require "debug" | 8 | local debug = require "debug" |
| 9 | 9 | ||
diff --git a/testes/locals.lua b/testes/locals.lua index 99ff9edc..02f41980 100644 --- a/testes/locals.lua +++ b/testes/locals.lua | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | -- $Id: testes/locals.lua $ | 1 | -- $Id: testes/locals.lua $ |
| 2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
| 3 | 3 | ||
| 4 | global * <const> | 4 | global <const> * |
| 5 | 5 | ||
| 6 | print('testing local variables and environments') | 6 | print('testing local variables and environments') |
| 7 | 7 | ||
| @@ -181,23 +181,25 @@ assert(x==20) | |||
| 181 | A = nil | 181 | A = nil |
| 182 | 182 | ||
| 183 | 183 | ||
| 184 | do -- constants | 184 | do print("testing local constants") |
| 185 | global assert<const>, load, string, X | 185 | global assert<const>, load, string, X |
| 186 | X = 1 -- not a constant | 186 | X = 1 -- not a constant |
| 187 | local a<const>, b, c<const> = 10, 20, 30 | 187 | local a<const>, b, c<const> = 10, 20, 30 |
| 188 | b = a + c + b -- 'b' is not constant | 188 | b = a + c + b -- 'b' is not constant |
| 189 | assert(a == 10 and b == 60 and c == 30) | 189 | assert(a == 10 and b == 60 and c == 30) |
| 190 | |||
| 190 | local function checkro (name, code) | 191 | local function checkro (name, code) |
| 191 | local st, msg = load(code) | 192 | local st, msg = load(code) |
| 192 | local gab = string.format("attempt to assign to const variable '%s'", name) | 193 | local gab = string.format("attempt to assign to const variable '%s'", name) |
| 193 | assert(not st and string.find(msg, gab)) | 194 | assert(not st and string.find(msg, gab)) |
| 194 | end | 195 | end |
| 196 | |||
| 195 | checkro("y", "local x, y <const>, z = 10, 20, 30; x = 11; y = 12") | 197 | checkro("y", "local x, y <const>, z = 10, 20, 30; x = 11; y = 12") |
| 196 | checkro("x", "local x <const>, y, z <const> = 10, 20, 30; x = 11") | 198 | checkro("x", "local x <const>, y, z <const> = 10, 20, 30; x = 11") |
| 197 | checkro("z", "local x <const>, y, z <const> = 10, 20, 30; y = 10; z = 11") | 199 | checkro("z", "local x <const>, y, z <const> = 10, 20, 30; y = 10; z = 11") |
| 198 | checkro("foo", "local foo <const> = 10; function foo() end") | 200 | checkro("foo", "local<const> foo = 10; function foo() end") |
| 199 | checkro("foo", "local foo <const> = {}; function foo() end") | 201 | checkro("foo", "local<const> foo <const> = {}; function foo() end") |
| 200 | checkro("foo", "global foo <const>; function foo() end") | 202 | checkro("foo", "global<const> foo <const>; function foo() end") |
| 201 | checkro("XX", "global XX <const>; XX = 10") | 203 | checkro("XX", "global XX <const>; XX = 10") |
| 202 | checkro("XX", "local _ENV; global XX <const>; XX = 10") | 204 | checkro("XX", "local _ENV; global XX <const>; XX = 10") |
| 203 | 205 | ||
| @@ -218,8 +220,18 @@ do -- constants | |||
| 218 | end | 220 | end |
| 219 | 221 | ||
| 220 | 222 | ||
| 223 | |||
| 221 | print"testing to-be-closed variables" | 224 | print"testing to-be-closed variables" |
| 222 | 225 | ||
| 226 | |||
| 227 | do | ||
| 228 | local st, msg = load("local <close> a, b") | ||
| 229 | assert(not st and string.find(msg, "multiple")) | ||
| 230 | |||
| 231 | local st, msg = load("local a<close>, b<close>") | ||
| 232 | assert(not st and string.find(msg, "multiple")) | ||
| 233 | end | ||
| 234 | |||
| 223 | local function stack(n) n = ((n == 0) or stack(n - 1)) end | 235 | local function stack(n) n = ((n == 0) or stack(n - 1)) end |
| 224 | 236 | ||
| 225 | local function func2close (f, x, y) | 237 | local function func2close (f, x, y) |
diff --git a/testes/math.lua b/testes/math.lua index 242579b1..0d228d09 100644 --- a/testes/math.lua +++ b/testes/math.lua | |||
| @@ -8,11 +8,10 @@ local string = require "string" | |||
| 8 | 8 | ||
| 9 | global none | 9 | global none |
| 10 | 10 | ||
| 11 | global print, assert, pcall, type, pairs, load | 11 | global<const> print, assert, pcall, type, pairs, load |
| 12 | global tonumber, tostring, select | 12 | global<const> tonumber, tostring, select |
| 13 | 13 | ||
| 14 | local minint <const> = math.mininteger | 14 | local<const> minint, maxint = math.mininteger, math.maxinteger |
| 15 | local maxint <const> = math.maxinteger | ||
| 16 | 15 | ||
| 17 | local intbits <const> = math.floor(math.log(maxint, 2) + 0.5) + 1 | 16 | local intbits <const> = math.floor(math.log(maxint, 2) + 0.5) + 1 |
| 18 | assert((1 << intbits) == 0) | 17 | assert((1 << intbits) == 0) |
diff --git a/testes/nextvar.lua b/testes/nextvar.lua index e5a97178..03810a8e 100644 --- a/testes/nextvar.lua +++ b/testes/nextvar.lua | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | -- $Id: testes/nextvar.lua $ | 1 | -- $Id: testes/nextvar.lua $ |
| 2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
| 3 | 3 | ||
| 4 | global * <const> | 4 | global <const> * |
| 5 | 5 | ||
| 6 | print('testing tables, next, and for') | 6 | print('testing tables, next, and for') |
| 7 | 7 | ||
diff --git a/testes/pm.lua b/testes/pm.lua index 1700ca2c..720d2a35 100644 --- a/testes/pm.lua +++ b/testes/pm.lua | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | print('testing pattern matching') | 7 | print('testing pattern matching') |
| 8 | 8 | ||
| 9 | global * <const> | 9 | global <const> * |
| 10 | 10 | ||
| 11 | local function checkerror (msg, f, ...) | 11 | local function checkerror (msg, f, ...) |
| 12 | local s, err = pcall(f, ...) | 12 | local s, err = pcall(f, ...) |
diff --git a/testes/strings.lua b/testes/strings.lua index 455398c3..46912d43 100644 --- a/testes/strings.lua +++ b/testes/strings.lua | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | -- ISO Latin encoding | 4 | -- ISO Latin encoding |
| 5 | 5 | ||
| 6 | global * <const> | 6 | global <const> * |
| 7 | 7 | ||
| 8 | print('testing strings and string library') | 8 | print('testing strings and string library') |
| 9 | 9 | ||
diff --git a/testes/utf8.lua b/testes/utf8.lua index ec9b706f..143c6d34 100644 --- a/testes/utf8.lua +++ b/testes/utf8.lua | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | -- UTF-8 file | 4 | -- UTF-8 file |
| 5 | 5 | ||
| 6 | global * <const> | 6 | global <const> * |
| 7 | 7 | ||
| 8 | print "testing UTF-8 library" | 8 | print "testing UTF-8 library" |
| 9 | 9 | ||
