Roberto Ierusalimschy пре 24 година
родитељ
комит
888f91fa24
6 измењених фајлова са 21 додато и 18 уклоњено
  1. 4 3
      ldebug.c
  2. 2 1
      lfunc.c
  3. 4 2
      lgc.c
  4. 2 1
      lobject.h
  5. 8 9
      lparser.c
  6. 1 2
      lparser.h

+ 4 - 3
ldebug.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ldebug.c,v 1.64 2001/02/16 17:58:27 roberto Exp roberto $
+** $Id: ldebug.c,v 1.65 2001/02/20 18:15:33 roberto Exp roberto $
 ** Debug Interface
 ** Debug Interface
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -433,7 +433,7 @@ static Instruction luaG_symbexec (lua_State *L, const Proto *pt,
         break;
         break;
       }
       }
       case OP_PUSHUPVALUE: {
       case OP_PUSHUPVALUE: {
-        /* ?? */
+        check(arg1 < pt->nupvalues);
         break;
         break;
       }
       }
       case OP_GETLOCAL:
       case OP_GETLOCAL:
@@ -462,7 +462,8 @@ static Instruction luaG_symbexec (lua_State *L, const Proto *pt,
         break;
         break;
       }
       }
       case OP_CLOSURE: {
       case OP_CLOSURE: {
-        /* ?? */
+        check(arg1 < pt->sizekproto);
+        check(arg2 == pt->kproto[arg1]->nupvalues);
         pop = arg2;
         pop = arg2;
         break;
         break;
       }
       }

+ 2 - 1
lfunc.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lfunc.c,v 1.39 2001/02/01 17:40:48 roberto Exp roberto $
+** $Id: lfunc.c,v 1.40 2001/02/09 20:22:29 roberto Exp roberto $
 ** Auxiliary functions to manipulate prototypes and closures
 ** Auxiliary functions to manipulate prototypes and closures
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -37,6 +37,7 @@ Proto *luaF_newproto (lua_State *L) {
   f->sizekproto = 0;
   f->sizekproto = 0;
   f->code = NULL;
   f->code = NULL;
   f->sizecode = 0;
   f->sizecode = 0;
+  f->nupvalues = 0;
   f->numparams = 0;
   f->numparams = 0;
   f->is_vararg = 0;
   f->is_vararg = 0;
   f->maxstacksize = 0;
   f->maxstacksize = 0;

+ 4 - 2
lgc.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lgc.c,v 1.88 2001/02/07 18:13:49 roberto Exp roberto $
+** $Id: lgc.c,v 1.89 2001/02/20 18:15:33 roberto Exp roberto $
 ** Garbage Collector
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -62,8 +62,10 @@ static void protomark (Proto *f) {
 
 
 static void markclosure (GCState *st, Closure *cl) {
 static void markclosure (GCState *st, Closure *cl) {
   if (!ismarked(cl)) {
   if (!ismarked(cl)) {
-    if (!cl->isC)
+    if (!cl->isC) {
+      lua_assert(cl->nupvalues == cl->f.l->nupvalues);
       protomark(cl->f.l);
       protomark(cl->f.l);
+    }
     cl->mark = st->cmark;  /* chain it for later traversal */
     cl->mark = st->cmark;  /* chain it for later traversal */
     st->cmark = cl;
     st->cmark = cl;
   }
   }

+ 2 - 1
lobject.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lobject.h,v 1.95 2001/02/09 20:22:29 roberto Exp roberto $
+** $Id: lobject.h,v 1.96 2001/02/20 18:15:33 roberto Exp roberto $
 ** Type definitions for Lua objects
 ** Type definitions for Lua objects
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -133,6 +133,7 @@ typedef struct Proto {
   int sizekproto;  /* size of `kproto' */
   int sizekproto;  /* size of `kproto' */
   Instruction *code;
   Instruction *code;
   int sizecode;
   int sizecode;
+  short nupvalues;
   short numparams;
   short numparams;
   short is_vararg;
   short is_vararg;
   short maxstacksize;
   short maxstacksize;

+ 8 - 9
lparser.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lparser.c,v 1.134 2001/02/14 17:38:45 roberto Exp roberto $
+** $Id: lparser.c,v 1.135 2001/02/20 18:15:33 roberto Exp roberto $
 ** LL(1) Parser and code generator for Lua
 ** LL(1) Parser and code generator for Lua
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -219,14 +219,14 @@ static void singlevar (LexState *ls, TString *n, expdesc *var) {
 static int indexupvalue (LexState *ls, expdesc *v) {
 static int indexupvalue (LexState *ls, expdesc *v) {
   FuncState *fs = ls->fs;
   FuncState *fs = ls->fs;
   int i;
   int i;
-  for (i=0; i<fs->nupvalues; i++) {
+  for (i=0; i<fs->f->nupvalues; i++) {
     if (fs->upvalues[i].k == v->k && fs->upvalues[i].u.index == v->u.index)
     if (fs->upvalues[i].k == v->k && fs->upvalues[i].u.index == v->u.index)
       return i;
       return i;
   }
   }
   /* new one */
   /* new one */
-  luaX_checklimit(ls, fs->nupvalues+1, MAXUPVALUES, "upvalues");
-  fs->upvalues[fs->nupvalues] = *v;
-  return fs->nupvalues++;
+  luaX_checklimit(ls, fs->f->nupvalues+1, MAXUPVALUES, "upvalues");
+  fs->upvalues[fs->f->nupvalues] = *v;
+  return fs->f->nupvalues++;
 }
 }
 
 
 
 
@@ -297,12 +297,12 @@ static void pushclosure (LexState *ls, FuncState *func) {
   FuncState *fs = ls->fs;
   FuncState *fs = ls->fs;
   Proto *f = fs->f;
   Proto *f = fs->f;
   int i;
   int i;
-  for (i=0; i<func->nupvalues; i++)
+  for (i=0; i<func->f->nupvalues; i++)
     luaK_tostack(ls, &func->upvalues[i], 1);
     luaK_tostack(ls, &func->upvalues[i], 1);
   luaM_growvector(ls->L, f->kproto, fs->nkproto, f->sizekproto, Proto *,
   luaM_growvector(ls->L, f->kproto, fs->nkproto, f->sizekproto, Proto *,
                   MAXARG_A, "constant table overflow");
                   MAXARG_A, "constant table overflow");
   f->kproto[fs->nkproto++] = func->f;
   f->kproto[fs->nkproto++] = func->f;
-  luaK_code2(fs, OP_CLOSURE, fs->nkproto-1, func->nupvalues);
+  luaK_code2(fs, OP_CLOSURE, fs->nkproto-1, func->f->nupvalues);
 }
 }
 
 
 
 
@@ -323,7 +323,6 @@ static void open_func (LexState *ls, FuncState *fs) {
   fs->nlineinfo = 0;
   fs->nlineinfo = 0;
   fs->nlocvars = 0;
   fs->nlocvars = 0;
   fs->nactloc = 0;
   fs->nactloc = 0;
-  fs->nupvalues = 0;
   fs->lastline = 0;
   fs->lastline = 0;
   fs->bl = NULL;
   fs->bl = NULL;
   f->code = NULL;
   f->code = NULL;
@@ -370,7 +369,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z) {
   check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected");
   check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected");
   close_func(&lexstate);
   close_func(&lexstate);
   lua_assert(funcstate.prev == NULL);
   lua_assert(funcstate.prev == NULL);
-  lua_assert(funcstate.nupvalues == 0);
+  lua_assert(funcstate.f->nupvalues == 0);
   return funcstate.f;
   return funcstate.f;
 }
 }
 
 

+ 1 - 2
lparser.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lparser.h,v 1.28 2000/12/26 18:46:09 roberto Exp roberto $
+** $Id: lparser.h,v 1.29 2000/12/28 12:55:41 roberto Exp roberto $
 ** LL(1) Parser and code generator for Lua
 ** LL(1) Parser and code generator for Lua
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -51,7 +51,6 @@ typedef struct FuncState {
   int nlineinfo;  /* number of elements in `lineinfo' */
   int nlineinfo;  /* number of elements in `lineinfo' */
   int nlocvars;  /* number of elements in `locvars' */
   int nlocvars;  /* number of elements in `locvars' */
   int nactloc;  /* number of active local variables */
   int nactloc;  /* number of active local variables */
-  int nupvalues;  /* number of upvalues */
   int lastline;  /* line where last `lineinfo' was generated */
   int lastline;  /* line where last `lineinfo' was generated */
   struct Breaklabel *bl;  /* chain of breakable blocks */
   struct Breaklabel *bl;  /* chain of breakable blocks */
   expdesc upvalues[MAXUPVALUES];  /* upvalues */
   expdesc upvalues[MAXUPVALUES];  /* upvalues */