OP_TFORLOOP uses extra stack space

This commit is contained in:
Roberto Ierusalimschy 2002-12-11 10:34:22 -02:00
parent 9e8face8d8
commit 73517e86b0
4 changed files with 8 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/*
** $Id: lcode.c,v 1.113 2002/11/14 16:15:53 roberto Exp roberto $
** $Id: lcode.c,v 1.114 2002/12/04 17:38:31 roberto Exp roberto $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@ -176,7 +176,7 @@ void luaK_concat (FuncState *fs, int *l1, int l2) {
}
static void luaK_checkstack (FuncState *fs, int n) {
void luaK_checkstack (FuncState *fs, int n) {
int newstack = fs->freereg + n;
if (newstack > fs->f->maxstacksize) {
if (newstack >= MAXSTACK)

View File

@ -1,5 +1,5 @@
/*
** $Id: lcode.h,v 1.36 2002/05/13 13:07:48 roberto Exp roberto $
** $Id: lcode.h,v 1.37 2002/06/12 19:16:00 roberto Exp roberto $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@ -47,6 +47,7 @@ int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);
void luaK_fixline (FuncState *fs, int line);
void luaK_nil (FuncState *fs, int from, int n);
void luaK_reserveregs (FuncState *fs, int n);
void luaK_checkstack (FuncState *fs, int n);
int luaK_stringK (FuncState *fs, TString *s);
int luaK_numberK (FuncState *fs, lua_Number r);
void luaK_dischargevars (FuncState *fs, expdesc *e);

View File

@ -1,5 +1,5 @@
/*
** $Id: ldebug.c,v 1.141 2002/12/04 17:38:31 roberto Exp roberto $
** $Id: ldebug.c,v 1.142 2002/12/06 17:15:35 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@ -364,7 +364,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) {
break;
}
case OP_TFORLOOP:
checkreg(pt, a+2+c);
checkreg(pt, a+c+5);
if (reg >= a) last = pc; /* affect all registers above base */
/* go through */
case OP_FORLOOP:

View File

@ -1,5 +1,5 @@
/*
** $Id: lparser.c,v 1.200 2002/12/04 17:38:31 roberto Exp roberto $
** $Id: lparser.c,v 1.201 2002/12/06 17:09:00 roberto Exp roberto $
** Lua Parser
** See Copyright Notice in lua.h
*/
@ -1070,6 +1070,7 @@ static void forlist (LexState *ls, TString *indexname) {
check(ls, TK_IN);
line = ls->linenumber;
adjust_assign(ls, nvars, explist1(ls, &e), &e);
luaK_checkstack(fs, 3); /* extra space to call generator */
luaK_codeAsBx(fs, OP_TFORPREP, base, NO_JUMP);
forbody(ls, base, line, nvars, 0);
}