aboutsummaryrefslogtreecommitdiff
path: root/lparser.c
diff options
context:
space:
mode:
Diffstat (limited to 'lparser.c')
-rw-r--r--lparser.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/lparser.c b/lparser.c
index 40a30ff6..77141e79 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1875,6 +1875,16 @@ static lu_byte getglobalattribute (LexState *ls, lu_byte df) {
1875} 1875}
1876 1876
1877 1877
1878static void checkglobal (LexState *ls, TString *varname, int line) {
1879 FuncState *fs = ls->fs;
1880 expdesc var;
1881 int k;
1882 buildglobal(ls, varname, &var); /* create global variable in 'var' */
1883 k = var.u.ind.keystr; /* index of global name in 'k' */
1884 luaK_codecheckglobal(fs, &var, k, line);
1885}
1886
1887
1878/* 1888/*
1879** Recursively traverse list of globals to be initalized. When 1889** Recursively traverse list of globals to be initalized. When
1880** going, generate table description for the global. In the end, 1890** going, generate table description for the global. In the end,
@@ -1883,7 +1893,8 @@ static lu_byte getglobalattribute (LexState *ls, lu_byte df) {
1883** the stack to the corresponding table description. 'n' is the variable 1893** the stack to the corresponding table description. 'n' is the variable
1884** being handled, range [0, nvars - 1]. 1894** being handled, range [0, nvars - 1].
1885*/ 1895*/
1886static void initglobal (LexState *ls, int nvars, int firstidx, int n) { 1896static void initglobal (LexState *ls, int nvars, int firstidx, int n,
1897 int line) {
1887 if (n == nvars) { /* traversed all variables? */ 1898 if (n == nvars) { /* traversed all variables? */
1888 expdesc e; 1899 expdesc e;
1889 int nexps = explist(ls, &e); /* read list of expressions */ 1900 int nexps = explist(ls, &e); /* read list of expressions */
@@ -1895,8 +1906,9 @@ static void initglobal (LexState *ls, int nvars, int firstidx, int n) {
1895 TString *varname = getlocalvardesc(fs, firstidx + n)->vd.name; 1906 TString *varname = getlocalvardesc(fs, firstidx + n)->vd.name;
1896 buildglobal(ls, varname, &var); /* create global variable in 'var' */ 1907 buildglobal(ls, varname, &var); /* create global variable in 'var' */
1897 enterlevel(ls); /* control recursion depth */ 1908 enterlevel(ls); /* control recursion depth */
1898 initglobal(ls, nvars, firstidx, n + 1); 1909 initglobal(ls, nvars, firstidx, n + 1, line);
1899 leavelevel(ls); 1910 leavelevel(ls);
1911 checkglobal(ls, varname, line);
1900 storevartop(fs, &var); 1912 storevartop(fs, &var);
1901 } 1913 }
1902} 1914}
@@ -1913,7 +1925,7 @@ static void globalnames (LexState *ls, lu_byte defkind) {
1913 nvars++; 1925 nvars++;
1914 } while (testnext(ls, ',')); 1926 } while (testnext(ls, ','));
1915 if (testnext(ls, '=')) /* initialization? */ 1927 if (testnext(ls, '=')) /* initialization? */
1916 initglobal(ls, nvars, lastidx - nvars + 1, 0); 1928 initglobal(ls, nvars, lastidx - nvars + 1, 0, ls->linenumber);
1917 fs->nactvar = cast_short(fs->nactvar + nvars); /* activate declaration */ 1929 fs->nactvar = cast_short(fs->nactvar + nvars); /* activate declaration */
1918} 1930}
1919 1931
@@ -1943,6 +1955,7 @@ static void globalfunc (LexState *ls, int line) {
1943 fs->nactvar++; /* enter its scope */ 1955 fs->nactvar++; /* enter its scope */
1944 buildglobal(ls, fname, &var); 1956 buildglobal(ls, fname, &var);
1945 body(ls, &b, 0, ls->linenumber); /* compile and return closure in 'b' */ 1957 body(ls, &b, 0, ls->linenumber); /* compile and return closure in 'b' */
1958 checkglobal(ls, fname, line);
1946 luaK_storevar(fs, &var, &b); 1959 luaK_storevar(fs, &var, &b);
1947 luaK_fixline(fs, line); /* definition "happens" in the first line */ 1960 luaK_fixline(fs, line); /* definition "happens" in the first line */
1948} 1961}