فهرست منبع

C stack is the same for the parser and the interpreter, so depth
control should be unified in both parts.

Roberto Ierusalimschy 20 سال پیش
والد
کامیت
fabf5db237
3فایلهای تغییر یافته به همراه14 افزوده شده و 18 حذف شده
  1. 1 2
      llex.h
  2. 10 7
      lparser.c
  3. 3 9
      luaconf.h

+ 1 - 2
llex.h

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.h,v 1.51 2004/12/02 12:59:10 roberto Exp roberto $
+** $Id: llex.h,v 1.52 2004/12/03 20:54:12 roberto Exp roberto $
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 */
@@ -63,7 +63,6 @@ typedef struct LexState {
   ZIO *z;  /* input stream */
   Mbuffer *buff;  /* buffer for tokens */
   TString *source;  /* current source name */
-  int nestlevel;  /* level of nested non-terminals */
 } LexState;
 
 

+ 10 - 7
lparser.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lparser.c,v 2.18 2005/03/09 16:28:07 roberto Exp roberto $
+** $Id: lparser.c,v 2.19 2005/03/16 16:59:21 roberto Exp roberto $
 ** Lua Parser
 ** See Copyright Notice in lua.h
 */
@@ -33,10 +33,6 @@
 
 #define luaY_checklimit(fs,v,l,m)	if ((v)>(l)) errorlimit(fs,l,m)
 
-#define enterlevel(ls) if (++(ls)->nestlevel > LUAI_MAXPARSERLEVEL) \
-	luaX_lexerror(ls, "chunk has too many syntax levels", 0)
-#define leavelevel(ls)	((ls)->nestlevel--)
-
 
 /*
 ** nodes for block list (list of active blocks)
@@ -295,6 +291,15 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
 }
 
 
+static void enterlevel (LexState *ls) {
+  if (++ls->L->nCcalls > LUAI_MAXCCALLS)
+	luaX_lexerror(ls, "chunk has too many syntax levels", 0);
+}
+
+
+#define leavelevel(ls)	((ls)->L->nCcalls--)
+
+
 static void enterblock (FuncState *fs, BlockCnt *bl, int isbreakable) {
   bl->breaklist = NO_JUMP;
   bl->isbreakable = isbreakable;
@@ -395,7 +400,6 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
   struct LexState lexstate;
   struct FuncState funcstate;
   lexstate.buff = buff;
-  lexstate.nestlevel = 0;
   luaX_setinput(L, &lexstate, z, luaS_new(L, name));
   open_func(&lexstate, &funcstate);
   funcstate.f->is_vararg = NEWSTYLEVARARG;
@@ -405,7 +409,6 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
   close_func(&lexstate);
   lua_assert(funcstate.prev == NULL);
   lua_assert(funcstate.f->nups == 0);
-  lua_assert(lexstate.nestlevel == 0);
   lua_assert(lexstate.fs == NULL);
   return funcstate.f;
 }

+ 3 - 9
luaconf.h

@@ -1,5 +1,5 @@
 /*
-** $Id: luaconf.h,v 1.40 2005/03/29 16:20:48 roberto Exp roberto $
+** $Id: luaconf.h,v 1.41 2005/04/06 17:30:13 roberto Exp roberto $
 ** Configuration file for Lua
 ** See Copyright Notice in lua.h
 */
@@ -351,18 +351,12 @@
 
 
 /*
-@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short).
+@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and
+@* syntactical nested non-terminals in a program.
 */
 #define LUAI_MAXCCALLS	200
 
 
-/*
-@@ LUAI_MAXPARSERLEVEL is the maximum number of syntactical nested
-@* non-terminals in a program.
-*/
-#define LUAI_MAXPARSERLEVEL	200
-
-
 /*
 @@ LUAI_MAXVARS is the maximum number of local variables per function
 @* (must be smaller than 250).