浏览代码

'pushclosure' -> 'codeclosure' (as there is another 'pushclosure' in
'lvm.c) + small detail

Roberto Ierusalimschy 15 年之前
父节点
当前提交
8d9ea59d28
共有 1 个文件被更改,包括 13 次插入8 次删除
  1. 13 8
      lparser.c

+ 13 - 8
lparser.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lparser.c,v 2.89 2010/07/02 20:42:40 roberto Exp roberto $
+** $Id: lparser.c,v 2.90 2010/07/07 16:27:29 roberto Exp roberto $
 ** Lua Parser
 ** Lua Parser
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -352,15 +352,20 @@ static void leaveblock (FuncState *fs) {
 }
 }
 
 
 
 
-static void pushclosure (LexState *ls, Proto *clp, expdesc *v) {
+/*
+** adds prototype being created into its parent list of prototypes
+** and codes instruction to create new closure
+*/
+static void codeclosure (LexState *ls, Proto *clp, expdesc *v) {
   FuncState *fs = ls->fs->prev;
   FuncState *fs = ls->fs->prev;
   Proto *f = fs->f;  /* prototype of function creating new closure */
   Proto *f = fs->f;  /* prototype of function creating new closure */
-  int oldsize = f->sizep;
-  luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *,
-                  MAXARG_Bx, "functions");
-  while (oldsize < f->sizep) f->p[oldsize++] = NULL;
+  if (fs->np >= f->sizep) {
+    int oldsize = f->sizep;
+    luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *,
+                    MAXARG_Bx, "functions");
+    while (oldsize < f->sizep) f->p[oldsize++] = NULL;
+  }
   f->p[fs->np++] = clp;
   f->p[fs->np++] = clp;
-  /* initial environment for new function is current lexical environment */
   luaC_objbarrier(ls->L, f, clp);
   luaC_objbarrier(ls->L, f, clp);
   init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1));
   init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1));
 }
 }
@@ -653,7 +658,7 @@ static void body (LexState *ls, expdesc *e, int needself, int line) {
   chunk(ls);
   chunk(ls);
   new_fs.f->lastlinedefined = ls->linenumber;
   new_fs.f->lastlinedefined = ls->linenumber;
   check_match(ls, TK_END, TK_FUNCTION, line);
   check_match(ls, TK_END, TK_FUNCTION, line);
-  pushclosure(ls, new_fs.f, e);
+  codeclosure(ls, new_fs.f, e);
   close_func(ls);
   close_func(ls);
 }
 }