diff options
| -rw-r--r-- | lparser.c | 21 |
1 files changed, 13 insertions, 8 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 2.89 2010/07/02 20:42:40 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.90 2010/07/07 16:27:29 roberto Exp roberto $ |
| 3 | ** Lua Parser | 3 | ** Lua Parser |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -352,15 +352,20 @@ static void leaveblock (FuncState *fs) { | |||
| 352 | } | 352 | } |
| 353 | 353 | ||
| 354 | 354 | ||
| 355 | static void pushclosure (LexState *ls, Proto *clp, expdesc *v) { | 355 | /* |
| 356 | ** adds prototype being created into its parent list of prototypes | ||
| 357 | ** and codes instruction to create new closure | ||
| 358 | */ | ||
| 359 | static void codeclosure (LexState *ls, Proto *clp, expdesc *v) { | ||
| 356 | FuncState *fs = ls->fs->prev; | 360 | FuncState *fs = ls->fs->prev; |
| 357 | Proto *f = fs->f; /* prototype of function creating new closure */ | 361 | Proto *f = fs->f; /* prototype of function creating new closure */ |
| 358 | int oldsize = f->sizep; | 362 | if (fs->np >= f->sizep) { |
| 359 | luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *, | 363 | int oldsize = f->sizep; |
| 360 | MAXARG_Bx, "functions"); | 364 | luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *, |
| 361 | while (oldsize < f->sizep) f->p[oldsize++] = NULL; | 365 | MAXARG_Bx, "functions"); |
| 366 | while (oldsize < f->sizep) f->p[oldsize++] = NULL; | ||
| 367 | } | ||
| 362 | f->p[fs->np++] = clp; | 368 | f->p[fs->np++] = clp; |
| 363 | /* initial environment for new function is current lexical environment */ | ||
| 364 | luaC_objbarrier(ls->L, f, clp); | 369 | luaC_objbarrier(ls->L, f, clp); |
| 365 | init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1)); | 370 | init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1)); |
| 366 | } | 371 | } |
| @@ -653,7 +658,7 @@ static void body (LexState *ls, expdesc *e, int needself, int line) { | |||
| 653 | chunk(ls); | 658 | chunk(ls); |
| 654 | new_fs.f->lastlinedefined = ls->linenumber; | 659 | new_fs.f->lastlinedefined = ls->linenumber; |
| 655 | check_match(ls, TK_END, TK_FUNCTION, line); | 660 | check_match(ls, TK_END, TK_FUNCTION, line); |
| 656 | pushclosure(ls, new_fs.f, e); | 661 | codeclosure(ls, new_fs.f, e); |
| 657 | close_func(ls); | 662 | close_func(ls); |
| 658 | } | 663 | } |
| 659 | 664 | ||
