diff options
Diffstat (limited to 'lparser.c')
-rw-r--r-- | lparser.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 2.70 2009/10/13 19:35:42 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.71 2009/10/14 16:43:11 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 | */ |
@@ -370,10 +370,6 @@ static void open_func (LexState *ls, FuncState *fs) { | |||
370 | fs->firstlocal = ls->varl->nactvar; | 370 | fs->firstlocal = ls->varl->nactvar; |
371 | fs->envreg = NO_REG; | 371 | fs->envreg = NO_REG; |
372 | fs->bl = NULL; | 372 | fs->bl = NULL; |
373 | fs->h = luaH_new(L); | ||
374 | /* anchor table of constants (to avoid being collected) */ | ||
375 | sethvalue2s(L, L->top, fs->h); | ||
376 | incr_top(L); | ||
377 | f = luaF_newproto(L); | 373 | f = luaF_newproto(L); |
378 | fs->f = f; | 374 | fs->f = f; |
379 | f->source = ls->source; | 375 | f->source = ls->source; |
@@ -381,6 +377,10 @@ static void open_func (LexState *ls, FuncState *fs) { | |||
381 | /* anchor prototype (to avoid being collected) */ | 377 | /* anchor prototype (to avoid being collected) */ |
382 | setptvalue2s(L, L->top, f); | 378 | setptvalue2s(L, L->top, f); |
383 | incr_top(L); | 379 | incr_top(L); |
380 | fs->h = luaH_new(L); | ||
381 | /* anchor table of constants (to avoid being collected) */ | ||
382 | sethvalue2s(L, L->top, fs->h); | ||
383 | incr_top(L); | ||
384 | } | 384 | } |
385 | 385 | ||
386 | 386 | ||
@@ -404,9 +404,11 @@ static void close_func (LexState *ls) { | |||
404 | f->sizeupvalues = fs->nups; | 404 | f->sizeupvalues = fs->nups; |
405 | lua_assert(fs->bl == NULL); | 405 | lua_assert(fs->bl == NULL); |
406 | ls->fs = fs->prev; | 406 | ls->fs = fs->prev; |
407 | L->top -= 2; /* remove table and prototype from the stack */ | ||
408 | /* last token read was anchored in defunct function; must reanchor it */ | 407 | /* last token read was anchored in defunct function; must reanchor it */ |
409 | anchor_token(ls); | 408 | anchor_token(ls); |
409 | L->top--; /* pop table of constants */ | ||
410 | luaC_checkGC(L); | ||
411 | L->top--; /* pop prototype (after possible collection) */ | ||
410 | } | 412 | } |
411 | 413 | ||
412 | 414 | ||
@@ -415,18 +417,18 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, Varlist *varl, | |||
415 | struct LexState lexstate; | 417 | struct LexState lexstate; |
416 | struct FuncState funcstate; | 418 | struct FuncState funcstate; |
417 | TString *tname = luaS_new(L, name); | 419 | TString *tname = luaS_new(L, name); |
418 | setsvalue2s(L, L->top, tname); /* protect name */ | 420 | setsvalue2s(L, L->top, tname); /* push name to protect it */ |
419 | incr_top(L); | 421 | incr_top(L); |
420 | lexstate.buff = buff; | 422 | lexstate.buff = buff; |
421 | lexstate.varl = varl; | 423 | lexstate.varl = varl; |
422 | luaX_setinput(L, &lexstate, z, tname); | 424 | luaX_setinput(L, &lexstate, z, tname); |
423 | open_func(&lexstate, &funcstate); | 425 | open_func(&lexstate, &funcstate); |
424 | funcstate.f->is_vararg = 1; /* main func. is always vararg */ | 426 | funcstate.f->is_vararg = 1; /* main function is always vararg */ |
425 | luaX_next(&lexstate); /* read first token */ | 427 | luaX_next(&lexstate); /* read first token */ |
426 | chunk(&lexstate); | 428 | chunk(&lexstate); |
427 | check(&lexstate, TK_EOS); | 429 | check(&lexstate, TK_EOS); |
428 | close_func(&lexstate); | 430 | close_func(&lexstate); |
429 | L->top--; | 431 | L->top--; /* pop name */ |
430 | lua_assert(funcstate.prev == NULL); | 432 | lua_assert(funcstate.prev == NULL); |
431 | lua_assert(funcstate.nups == 0); | 433 | lua_assert(funcstate.nups == 0); |
432 | lua_assert(lexstate.fs == NULL); | 434 | lua_assert(lexstate.fs == NULL); |