diff options
-rw-r--r-- | lparser.c | 5 | ||||
-rw-r--r-- | lparser.h | 4 | ||||
-rw-r--r-- | testes/errors.lua | 2 | ||||
-rw-r--r-- | testes/goto.lua | 38 |
4 files changed, 38 insertions, 11 deletions
@@ -50,7 +50,7 @@ typedef struct BlockCnt { | |||
50 | struct BlockCnt *previous; /* chain */ | 50 | struct BlockCnt *previous; /* chain */ |
51 | int firstlabel; /* index of first label in this block */ | 51 | int firstlabel; /* index of first label in this block */ |
52 | int firstgoto; /* index of first pending goto in this block */ | 52 | int firstgoto; /* index of first pending goto in this block */ |
53 | lu_byte nactvar; /* # active locals outside the block */ | 53 | short nactvar; /* number of active declarations at block entry */ |
54 | lu_byte upval; /* true if some variable in the block is an upvalue */ | 54 | lu_byte upval; /* true if some variable in the block is an upvalue */ |
55 | lu_byte isloop; /* 1 if 'block' is a loop; 2 if it has pending breaks */ | 55 | lu_byte isloop; /* 1 if 'block' is a loop; 2 if it has pending breaks */ |
56 | lu_byte insidetbc; /* true if inside the scope of a to-be-closed var. */ | 56 | lu_byte insidetbc; /* true if inside the scope of a to-be-closed var. */ |
@@ -196,8 +196,6 @@ static int new_varkind (LexState *ls, TString *name, lu_byte kind) { | |||
196 | FuncState *fs = ls->fs; | 196 | FuncState *fs = ls->fs; |
197 | Dyndata *dyd = ls->dyd; | 197 | Dyndata *dyd = ls->dyd; |
198 | Vardesc *var; | 198 | Vardesc *var; |
199 | luaY_checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal, | ||
200 | MAXVARS, "local variables"); | ||
201 | luaM_growvector(L, dyd->actvar.arr, dyd->actvar.n + 1, | 199 | luaM_growvector(L, dyd->actvar.arr, dyd->actvar.n + 1, |
202 | dyd->actvar.size, Vardesc, SHRT_MAX, "variable declarationss"); | 200 | dyd->actvar.size, Vardesc, SHRT_MAX, "variable declarationss"); |
203 | var = &dyd->actvar.arr[dyd->actvar.n++]; | 201 | var = &dyd->actvar.arr[dyd->actvar.n++]; |
@@ -330,6 +328,7 @@ static void adjustlocalvars (LexState *ls, int nvars) { | |||
330 | Vardesc *var = getlocalvardesc(fs, vidx); | 328 | Vardesc *var = getlocalvardesc(fs, vidx); |
331 | var->vd.ridx = cast_byte(reglevel++); | 329 | var->vd.ridx = cast_byte(reglevel++); |
332 | var->vd.pidx = registerlocalvar(ls, fs, var->vd.name); | 330 | var->vd.pidx = registerlocalvar(ls, fs, var->vd.name); |
331 | luaY_checklimit(fs, reglevel, MAXVARS, "local variables"); | ||
333 | } | 332 | } |
334 | } | 333 | } |
335 | 334 | ||
@@ -128,7 +128,7 @@ typedef struct Labeldesc { | |||
128 | TString *name; /* label identifier */ | 128 | TString *name; /* label identifier */ |
129 | int pc; /* position in code */ | 129 | int pc; /* position in code */ |
130 | int line; /* line where it appeared */ | 130 | int line; /* line where it appeared */ |
131 | lu_byte nactvar; /* number of active variables in that position */ | 131 | short nactvar; /* number of active variables in that position */ |
132 | lu_byte close; /* true for goto that escapes upvalues */ | 132 | lu_byte close; /* true for goto that escapes upvalues */ |
133 | } Labeldesc; | 133 | } Labeldesc; |
134 | 134 | ||
@@ -173,7 +173,7 @@ typedef struct FuncState { | |||
173 | int firstlocal; /* index of first local var (in Dyndata array) */ | 173 | int firstlocal; /* index of first local var (in Dyndata array) */ |
174 | int firstlabel; /* index of first label (in 'dyd->label->arr') */ | 174 | int firstlabel; /* index of first label (in 'dyd->label->arr') */ |
175 | short ndebugvars; /* number of elements in 'f->locvars' */ | 175 | short ndebugvars; /* number of elements in 'f->locvars' */ |
176 | lu_byte nactvar; /* number of active local variables */ | 176 | short nactvar; /* number of active variable declarations */ |
177 | lu_byte nups; /* number of upvalues */ | 177 | lu_byte nups; /* number of upvalues */ |
178 | lu_byte freereg; /* first free register */ | 178 | lu_byte freereg; /* first free register */ |
179 | lu_byte iwthabs; /* instructions issued since last absolute line info */ | 179 | lu_byte iwthabs; /* instructions issued since last absolute line info */ |
diff --git a/testes/errors.lua b/testes/errors.lua index a0728913..4230a352 100644 --- a/testes/errors.lua +++ b/testes/errors.lua | |||
@@ -742,7 +742,7 @@ assert(c > 255 and string.find(b, "too many upvalues") and | |||
742 | 742 | ||
743 | -- local variables | 743 | -- local variables |
744 | s = "\nfunction foo ()\n local " | 744 | s = "\nfunction foo ()\n local " |
745 | for j = 1,300 do | 745 | for j = 1,200 do |
746 | s = s.."a"..j..", " | 746 | s = s.."a"..j..", " |
747 | end | 747 | end |
748 | s = s.."b\n" | 748 | s = s.."b\n" |
diff --git a/testes/goto.lua b/testes/goto.lua index 7e40fc4f..3519e75d 100644 --- a/testes/goto.lua +++ b/testes/goto.lua | |||
@@ -293,14 +293,14 @@ end | |||
293 | foo() | 293 | foo() |
294 | -------------------------------------------------------------------------- | 294 | -------------------------------------------------------------------------- |
295 | 295 | ||
296 | local function checkerr (code, err) | ||
297 | local st, msg = load(code) | ||
298 | assert(not st and string.find(msg, err)) | ||
299 | end | ||
300 | |||
296 | do | 301 | do |
297 | global T<const> | 302 | global T<const> |
298 | 303 | ||
299 | local function checkerr (code, err) | ||
300 | local st, msg = load(code) | ||
301 | assert(not st and string.find(msg, err)) | ||
302 | end | ||
303 | |||
304 | -- globals must be declared, after a global declaration | 304 | -- globals must be declared, after a global declaration |
305 | checkerr("global none; X = 1", "variable 'X'") | 305 | checkerr("global none; X = 1", "variable 'X'") |
306 | checkerr("global none; function XX() end", "variable 'XX'") | 306 | checkerr("global none; function XX() end", "variable 'XX'") |
@@ -383,5 +383,33 @@ do | |||
383 | 383 | ||
384 | end | 384 | end |
385 | 385 | ||
386 | |||
387 | do -- Ok to declare hundreds of globals | ||
388 | global table | ||
389 | local code = {} | ||
390 | for i = 1, 1000 do | ||
391 | code[#code + 1] = ";global x" .. i | ||
392 | end | ||
393 | code[#code + 1] = "; return x990" | ||
394 | code = table.concat(code) | ||
395 | _ENV.x990 = 11 | ||
396 | assert(load(code)() == 11) | ||
397 | _ENV.x990 = nil | ||
398 | end | ||
399 | |||
400 | do -- mixing lots of global/local declarations | ||
401 | global table | ||
402 | local code = {} | ||
403 | for i = 1, 200 do | ||
404 | code[#code + 1] = ";global x" .. i | ||
405 | code[#code + 1] = ";local y" .. i .. "=" .. (2*i) | ||
406 | end | ||
407 | code[#code + 1] = "; return x200 + y200" | ||
408 | code = table.concat(code) | ||
409 | _ENV.x200 = 11 | ||
410 | assert(assert(load(code))() == 2*200 + 11) | ||
411 | _ENV.x200 = nil | ||
412 | end | ||
413 | |||
386 | print'OK' | 414 | print'OK' |
387 | 415 | ||