diff options
-rw-r--r-- | ldo.c | 19 | ||||
-rw-r--r-- | lfunc.c | 7 | ||||
-rw-r--r-- | lfunc.h | 4 | ||||
-rw-r--r-- | lgc.c | 3 | ||||
-rw-r--r-- | lobject.h | 7 | ||||
-rw-r--r-- | lparser.c | 97 | ||||
-rw-r--r-- | lparser.h | 6 | ||||
-rw-r--r-- | ltests.c | 6 | ||||
-rw-r--r-- | lundump.c | 35 | ||||
-rw-r--r-- | lundump.h | 4 | ||||
-rw-r--r-- | lvm.c | 5 |
11 files changed, 103 insertions, 90 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.102 2011/11/29 15:55:08 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.103 2012/04/26 20:41:18 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -626,24 +626,23 @@ static void checkmode (lua_State *L, const char *mode, const char *x) { | |||
626 | 626 | ||
627 | static void f_parser (lua_State *L, void *ud) { | 627 | static void f_parser (lua_State *L, void *ud) { |
628 | int i; | 628 | int i; |
629 | Proto *tf; | ||
630 | Closure *cl; | 629 | Closure *cl; |
631 | struct SParser *p = cast(struct SParser *, ud); | 630 | struct SParser *p = cast(struct SParser *, ud); |
632 | int c = zgetc(p->z); /* read first character */ | 631 | int c = zgetc(p->z); /* read first character */ |
633 | if (c == LUA_SIGNATURE[0]) { | 632 | if (c == LUA_SIGNATURE[0]) { |
634 | checkmode(L, p->mode, "binary"); | 633 | checkmode(L, p->mode, "binary"); |
635 | tf = luaU_undump(L, p->z, &p->buff, p->name); | 634 | cl = luaU_undump(L, p->z, &p->buff, p->name); |
636 | } | 635 | } |
637 | else { | 636 | else { |
638 | checkmode(L, p->mode, "text"); | 637 | checkmode(L, p->mode, "text"); |
639 | tf = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); | 638 | cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); |
639 | } | ||
640 | lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues); | ||
641 | for (i = 0; i < cl->l.nupvalues; i++) { /* initialize upvalues */ | ||
642 | UpVal *up = luaF_newupval(L); | ||
643 | cl->l.upvals[i] = up; | ||
644 | luaC_objbarrier(L, cl, up); | ||
640 | } | 645 | } |
641 | setptvalue2s(L, L->top, tf); | ||
642 | incr_top(L); | ||
643 | cl = luaF_newLclosure(L, tf); | ||
644 | setclLvalue(L, L->top - 1, cl); | ||
645 | for (i = 0; i < tf->sizeupvalues; i++) /* initialize upvalues */ | ||
646 | cl->l.upvals[i] = luaF_newupval(L); | ||
647 | } | 646 | } |
648 | 647 | ||
649 | 648 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lfunc.c,v 2.27 2010/06/30 14:11:17 roberto Exp roberto $ | 2 | ** $Id: lfunc.c,v 2.28 2012/01/20 22:05:50 roberto Exp roberto $ |
3 | ** Auxiliary functions to manipulate prototypes and closures | 3 | ** Auxiliary functions to manipulate prototypes and closures |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -27,10 +27,9 @@ Closure *luaF_newCclosure (lua_State *L, int n) { | |||
27 | } | 27 | } |
28 | 28 | ||
29 | 29 | ||
30 | Closure *luaF_newLclosure (lua_State *L, Proto *p) { | 30 | Closure *luaF_newLclosure (lua_State *L, int n) { |
31 | int n = p->sizeupvalues; | ||
32 | Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n), NULL, 0)->cl; | 31 | Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n), NULL, 0)->cl; |
33 | c->l.p = p; | 32 | c->l.p = NULL; |
34 | c->l.nupvalues = cast_byte(n); | 33 | c->l.nupvalues = cast_byte(n); |
35 | while (n--) c->l.upvals[n] = NULL; | 34 | while (n--) c->l.upvals[n] = NULL; |
36 | return c; | 35 | return c; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lfunc.h,v 2.6 2010/06/04 13:06:15 roberto Exp roberto $ | 2 | ** $Id: lfunc.h,v 2.7 2012/01/20 22:05:50 roberto Exp roberto $ |
3 | ** Auxiliary functions to manipulate prototypes and closures | 3 | ** Auxiliary functions to manipulate prototypes and closures |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -20,7 +20,7 @@ | |||
20 | 20 | ||
21 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); | 21 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); |
22 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems); | 22 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems); |
23 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, Proto *p); | 23 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems); |
24 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); | 24 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); |
25 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); | 25 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); |
26 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); | 26 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.117 2012/01/20 22:05:50 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.119 2012/01/25 21:05:40 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -489,7 +489,6 @@ static int traverseCclosure (global_State *g, CClosure *cl) { | |||
489 | 489 | ||
490 | static int traverseLclosure (global_State *g, LClosure *cl) { | 490 | static int traverseLclosure (global_State *g, LClosure *cl) { |
491 | int i; | 491 | int i; |
492 | lua_assert(cl->nupvalues == cl->p->sizeupvalues); | ||
493 | markobject(g, cl->p); /* mark its prototype */ | 492 | markobject(g, cl->p); /* mark its prototype */ |
494 | for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */ | 493 | for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */ |
495 | markobject(g, cl->upvals[i]); | 494 | markobject(g, cl->upvals[i]); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 2.65 2012/01/20 22:05:50 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.68 2012/01/25 21:05:40 roberto Exp roberto $ |
3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -236,11 +236,6 @@ typedef struct lua_TValue TValue; | |||
236 | val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTABLE)); \ | 236 | val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTABLE)); \ |
237 | checkliveness(G(L),io); } | 237 | checkliveness(G(L),io); } |
238 | 238 | ||
239 | #define setptvalue(L,obj,x) \ | ||
240 | { TValue *io=(obj); \ | ||
241 | val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TPROTO)); \ | ||
242 | checkliveness(G(L),io); } | ||
243 | |||
244 | #define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY) | 239 | #define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY) |
245 | 240 | ||
246 | 241 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 2.125 2012/01/23 23:05:18 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.126 2012/04/20 19:20:05 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 | */ |
@@ -493,21 +493,30 @@ static void leaveblock (FuncState *fs) { | |||
493 | 493 | ||
494 | 494 | ||
495 | /* | 495 | /* |
496 | ** adds prototype being created into its parent list of prototypes | 496 | ** adds a new prototype into list of prototypes |
497 | ** and codes instruction to create new closure | ||
498 | */ | 497 | */ |
499 | static void codeclosure (LexState *ls, Proto *clp, expdesc *v) { | 498 | static Proto *addprototype (LexState *ls) { |
500 | FuncState *fs = ls->fs->prev; | 499 | Proto *clp; |
501 | Proto *f = fs->f; /* prototype of function creating new closure */ | 500 | lua_State *L = ls->L; |
501 | FuncState *fs = ls->fs; | ||
502 | Proto *f = fs->f; /* prototype of current function */ | ||
502 | if (fs->np >= f->sizep) { | 503 | if (fs->np >= f->sizep) { |
503 | int oldsize = f->sizep; | 504 | int oldsize = f->sizep; |
504 | luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *, | 505 | luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, "functions"); |
505 | MAXARG_Bx, "functions"); | ||
506 | while (oldsize < f->sizep) f->p[oldsize++] = NULL; | 506 | while (oldsize < f->sizep) f->p[oldsize++] = NULL; |
507 | } | 507 | } |
508 | f->p[fs->np++] = clp; | 508 | f->p[fs->np++] = clp = luaF_newproto(L); |
509 | luaC_objbarrier(ls->L, f, clp); | 509 | luaC_objbarrier(L, f, clp); |
510 | init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1)); | 510 | return clp; |
511 | } | ||
512 | |||
513 | |||
514 | /* | ||
515 | ** codes instruction to create new closure in parent function | ||
516 | */ | ||
517 | static void codeclosure (LexState *ls, expdesc *v) { | ||
518 | FuncState *fs = ls->fs->prev; | ||
519 | init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1)); | ||
511 | luaK_exp2nextreg(fs, v); /* fix it at stack top (for GC) */ | 520 | luaK_exp2nextreg(fs, v); /* fix it at stack top (for GC) */ |
512 | } | 521 | } |
513 | 522 | ||
@@ -529,13 +538,9 @@ static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) { | |||
529 | fs->nactvar = 0; | 538 | fs->nactvar = 0; |
530 | fs->firstlocal = ls->dyd->actvar.n; | 539 | fs->firstlocal = ls->dyd->actvar.n; |
531 | fs->bl = NULL; | 540 | fs->bl = NULL; |
532 | f = luaF_newproto(L); | 541 | f = fs->f; |
533 | fs->f = f; | ||
534 | f->source = ls->source; | 542 | f->source = ls->source; |
535 | f->maxstacksize = 2; /* registers 0/1 are always valid */ | 543 | f->maxstacksize = 2; /* registers 0/1 are always valid */ |
536 | /* anchor prototype (to avoid being collected) */ | ||
537 | setptvalue2s(L, L->top, f); | ||
538 | incr_top(L); | ||
539 | fs->h = luaH_new(L); | 544 | fs->h = luaH_new(L); |
540 | /* anchor table of constants (to avoid being collected) */ | 545 | /* anchor table of constants (to avoid being collected) */ |
541 | sethvalue2s(L, L->top, fs->h); | 546 | sethvalue2s(L, L->top, fs->h); |
@@ -568,20 +573,6 @@ static void close_func (LexState *ls) { | |||
568 | anchor_token(ls); | 573 | anchor_token(ls); |
569 | L->top--; /* pop table of constants */ | 574 | L->top--; /* pop table of constants */ |
570 | luaC_checkGC(L); | 575 | luaC_checkGC(L); |
571 | L->top--; /* pop prototype (after possible collection) */ | ||
572 | } | ||
573 | |||
574 | |||
575 | /* | ||
576 | ** opens the main function, which is a regular vararg function with an | ||
577 | ** upvalue named LUA_ENV | ||
578 | */ | ||
579 | static void open_mainfunc (LexState *ls, FuncState *fs, BlockCnt *bl) { | ||
580 | expdesc v; | ||
581 | open_func(ls, fs, bl); | ||
582 | fs->f->is_vararg = 1; /* main function is always vararg */ | ||
583 | init_exp(&v, VLOCAL, 0); | ||
584 | newupvalue(fs, ls->envn, &v); /* create environment upvalue */ | ||
585 | } | 576 | } |
586 | 577 | ||
587 | 578 | ||
@@ -795,8 +786,9 @@ static void body (LexState *ls, expdesc *e, int ismethod, int line) { | |||
795 | /* body -> `(' parlist `)' block END */ | 786 | /* body -> `(' parlist `)' block END */ |
796 | FuncState new_fs; | 787 | FuncState new_fs; |
797 | BlockCnt bl; | 788 | BlockCnt bl; |
798 | open_func(ls, &new_fs, &bl); | 789 | new_fs.f = addprototype(ls); |
799 | new_fs.f->linedefined = line; | 790 | new_fs.f->linedefined = line; |
791 | open_func(ls, &new_fs, &bl); | ||
800 | checknext(ls, '('); | 792 | checknext(ls, '('); |
801 | if (ismethod) { | 793 | if (ismethod) { |
802 | new_localvarliteral(ls, "self"); /* create 'self' parameter */ | 794 | new_localvarliteral(ls, "self"); /* create 'self' parameter */ |
@@ -807,7 +799,7 @@ static void body (LexState *ls, expdesc *e, int ismethod, int line) { | |||
807 | statlist(ls); | 799 | statlist(ls); |
808 | new_fs.f->lastlinedefined = ls->linenumber; | 800 | new_fs.f->lastlinedefined = ls->linenumber; |
809 | check_match(ls, TK_END, TK_FUNCTION, line); | 801 | check_match(ls, TK_END, TK_FUNCTION, line); |
810 | codeclosure(ls, new_fs.f, e); | 802 | codeclosure(ls, e); |
811 | close_func(ls); | 803 | close_func(ls); |
812 | } | 804 | } |
813 | 805 | ||
@@ -1596,27 +1588,42 @@ static void statement (LexState *ls) { | |||
1596 | /* }====================================================================== */ | 1588 | /* }====================================================================== */ |
1597 | 1589 | ||
1598 | 1590 | ||
1599 | Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, | 1591 | /* |
1600 | Dyndata *dyd, const char *name, int firstchar) { | 1592 | ** compiles the main function, which is a regular vararg function with an |
1593 | ** upvalue named LUA_ENV | ||
1594 | */ | ||
1595 | static void mainfunc (LexState *ls, FuncState *fs) { | ||
1596 | BlockCnt bl; | ||
1597 | expdesc v; | ||
1598 | open_func(ls, fs, &bl); | ||
1599 | fs->f->is_vararg = 1; /* main function is always vararg */ | ||
1600 | init_exp(&v, VLOCAL, 0); /* create and... */ | ||
1601 | newupvalue(fs, ls->envn, &v); /* ...set environment upvalue */ | ||
1602 | luaX_next(ls); /* read first token */ | ||
1603 | statlist(ls); /* parse main body */ | ||
1604 | check(ls, TK_EOS); | ||
1605 | close_func(ls); | ||
1606 | } | ||
1607 | |||
1608 | |||
1609 | Closure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, | ||
1610 | Dyndata *dyd, const char *name, int firstchar) { | ||
1601 | LexState lexstate; | 1611 | LexState lexstate; |
1602 | FuncState funcstate; | 1612 | FuncState funcstate; |
1603 | BlockCnt bl; | 1613 | Closure *cl = luaF_newLclosure(L, 1); /* create main closure */ |
1604 | TString *tname = luaS_new(L, name); | 1614 | /* anchor closure (to avoid being collected) */ |
1605 | setsvalue2s(L, L->top, tname); /* push name to protect it */ | 1615 | setclLvalue(L, L->top, cl); |
1606 | incr_top(L); | 1616 | incr_top(L); |
1617 | funcstate.f = cl->l.p = luaF_newproto(L); | ||
1618 | funcstate.f->source = luaS_new(L, name); /* create and anchor TString */ | ||
1607 | lexstate.buff = buff; | 1619 | lexstate.buff = buff; |
1608 | lexstate.dyd = dyd; | 1620 | lexstate.dyd = dyd; |
1609 | dyd->actvar.n = dyd->gt.n = dyd->label.n = 0; | 1621 | dyd->actvar.n = dyd->gt.n = dyd->label.n = 0; |
1610 | luaX_setinput(L, &lexstate, z, tname, firstchar); | 1622 | luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar); |
1611 | open_mainfunc(&lexstate, &funcstate, &bl); | 1623 | mainfunc(&lexstate, &funcstate); |
1612 | luaX_next(&lexstate); /* read first token */ | ||
1613 | statlist(&lexstate); /* main body */ | ||
1614 | check(&lexstate, TK_EOS); | ||
1615 | close_func(&lexstate); | ||
1616 | L->top--; /* pop name */ | ||
1617 | lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs); | 1624 | lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs); |
1618 | /* all scopes should be correctly finished */ | 1625 | /* all scopes should be correctly finished */ |
1619 | lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0); | 1626 | lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0); |
1620 | return funcstate.f; | 1627 | return cl; /* it's on the stack too */ |
1621 | } | 1628 | } |
1622 | 1629 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.h,v 1.68 2011/02/23 13:13:10 roberto Exp roberto $ | 2 | ** $Id: lparser.h,v 1.69 2011/07/27 18:09:01 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 | */ |
@@ -112,8 +112,8 @@ typedef struct FuncState { | |||
112 | } FuncState; | 112 | } FuncState; |
113 | 113 | ||
114 | 114 | ||
115 | LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, | 115 | LUAI_FUNC Closure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, |
116 | Dyndata *dyd, const char *name, int firstchar); | 116 | Dyndata *dyd, const char *name, int firstchar); |
117 | 117 | ||
118 | 118 | ||
119 | #endif | 119 | #endif |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.125 2012/01/20 22:05:50 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.126 2012/01/25 21:05:40 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -278,8 +278,7 @@ static void checkCclosure (global_State *g, CClosure *cl) { | |||
278 | static void checkLclosure (global_State *g, LClosure *cl) { | 278 | static void checkLclosure (global_State *g, LClosure *cl) { |
279 | GCObject *clgc = obj2gco(cl); | 279 | GCObject *clgc = obj2gco(cl); |
280 | int i; | 280 | int i; |
281 | lua_assert(cl->nupvalues == cl->p->sizeupvalues); | 281 | if (cl->p) checkobjref(g, clgc, cl->p); |
282 | checkobjref(g, clgc, cl->p); | ||
283 | for (i=0; i<cl->nupvalues; i++) { | 282 | for (i=0; i<cl->nupvalues; i++) { |
284 | if (cl->upvals[i]) { | 283 | if (cl->upvals[i]) { |
285 | lua_assert(cl->upvals[i]->tt == LUA_TUPVAL); | 284 | lua_assert(cl->upvals[i]->tt == LUA_TUPVAL); |
@@ -855,6 +854,7 @@ static int loadlib (lua_State *L) { | |||
855 | {"coroutine", luaopen_coroutine}, | 854 | {"coroutine", luaopen_coroutine}, |
856 | {"debug", luaopen_debug}, | 855 | {"debug", luaopen_debug}, |
857 | {"io", luaopen_io}, | 856 | {"io", luaopen_io}, |
857 | {"os", luaopen_os}, | ||
858 | {"math", luaopen_math}, | 858 | {"math", luaopen_math}, |
859 | {"string", luaopen_string}, | 859 | {"string", luaopen_string}, |
860 | {"table", luaopen_table}, | 860 | {"table", luaopen_table}, |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lundump.c,v 2.20 2012/01/23 23:02:10 roberto Exp roberto $ | 2 | ** $Id: lundump.c,v 2.21 2012/03/19 22:58:09 roberto Exp roberto $ |
3 | ** load precompiled Lua chunks | 3 | ** load precompiled Lua chunks |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -39,7 +39,7 @@ static l_noret error(LoadState* S, const char* why) | |||
39 | #define LoadVector(S,b,n,size) LoadMem(S,b,n,size) | 39 | #define LoadVector(S,b,n,size) LoadMem(S,b,n,size) |
40 | 40 | ||
41 | #if !defined(luai_verifycode) | 41 | #if !defined(luai_verifycode) |
42 | #define luai_verifycode(L,b,f) (f) | 42 | #define luai_verifycode(L,b,f) /* empty */ |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | static void LoadBlock(LoadState* S, void* b, size_t size) | 45 | static void LoadBlock(LoadState* S, void* b, size_t size) |
@@ -91,7 +91,7 @@ static void LoadCode(LoadState* S, Proto* f) | |||
91 | LoadVector(S,f->code,n,sizeof(Instruction)); | 91 | LoadVector(S,f->code,n,sizeof(Instruction)); |
92 | } | 92 | } |
93 | 93 | ||
94 | static Proto* LoadFunction(LoadState* S); | 94 | static void LoadFunction(LoadState* S, Proto* f); |
95 | 95 | ||
96 | static void LoadConstants(LoadState* S, Proto* f) | 96 | static void LoadConstants(LoadState* S, Proto* f) |
97 | { | 97 | { |
@@ -125,7 +125,11 @@ static void LoadConstants(LoadState* S, Proto* f) | |||
125 | f->p=luaM_newvector(S->L,n,Proto*); | 125 | f->p=luaM_newvector(S->L,n,Proto*); |
126 | f->sizep=n; | 126 | f->sizep=n; |
127 | for (i=0; i<n; i++) f->p[i]=NULL; | 127 | for (i=0; i<n; i++) f->p[i]=NULL; |
128 | for (i=0; i<n; i++) f->p[i]=LoadFunction(S); | 128 | for (i=0; i<n; i++) |
129 | { | ||
130 | f->p[i]=luaF_newproto(S->L); | ||
131 | LoadFunction(S,f->p[i]); | ||
132 | } | ||
129 | } | 133 | } |
130 | 134 | ||
131 | static void LoadUpvalues(LoadState* S, Proto* f) | 135 | static void LoadUpvalues(LoadState* S, Proto* f) |
@@ -164,10 +168,8 @@ static void LoadDebug(LoadState* S, Proto* f) | |||
164 | for (i=0; i<n; i++) f->upvalues[i].name=LoadString(S); | 168 | for (i=0; i<n; i++) f->upvalues[i].name=LoadString(S); |
165 | } | 169 | } |
166 | 170 | ||
167 | static Proto* LoadFunction(LoadState* S) | 171 | static void LoadFunction(LoadState* S, Proto* f) |
168 | { | 172 | { |
169 | Proto* f=luaF_newproto(S->L); | ||
170 | setptvalue2s(S->L,S->L->top,f); incr_top(S->L); | ||
171 | f->linedefined=LoadInt(S); | 173 | f->linedefined=LoadInt(S); |
172 | f->lastlinedefined=LoadInt(S); | 174 | f->lastlinedefined=LoadInt(S); |
173 | f->numparams=LoadByte(S); | 175 | f->numparams=LoadByte(S); |
@@ -177,8 +179,6 @@ static Proto* LoadFunction(LoadState* S) | |||
177 | LoadConstants(S,f); | 179 | LoadConstants(S,f); |
178 | LoadUpvalues(S,f); | 180 | LoadUpvalues(S,f); |
179 | LoadDebug(S,f); | 181 | LoadDebug(S,f); |
180 | S->L->top--; | ||
181 | return f; | ||
182 | } | 182 | } |
183 | 183 | ||
184 | /* the code below must be consistent with the code in luaU_header */ | 184 | /* the code below must be consistent with the code in luaU_header */ |
@@ -203,9 +203,10 @@ static void LoadHeader(LoadState* S) | |||
203 | /* | 203 | /* |
204 | ** load precompiled chunk | 204 | ** load precompiled chunk |
205 | */ | 205 | */ |
206 | Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) | 206 | Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) |
207 | { | 207 | { |
208 | LoadState S; | 208 | LoadState S; |
209 | Closure* cl; | ||
209 | if (*name=='@' || *name=='=') | 210 | if (*name=='@' || *name=='=') |
210 | S.name=name+1; | 211 | S.name=name+1; |
211 | else if (*name==LUA_SIGNATURE[0]) | 212 | else if (*name==LUA_SIGNATURE[0]) |
@@ -216,7 +217,19 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) | |||
216 | S.Z=Z; | 217 | S.Z=Z; |
217 | S.b=buff; | 218 | S.b=buff; |
218 | LoadHeader(&S); | 219 | LoadHeader(&S); |
219 | return luai_verifycode(L,buff,LoadFunction(&S)); | 220 | cl=luaF_newLclosure(L,1); |
221 | setclLvalue(L,L->top,cl); incr_top(L); | ||
222 | cl->l.p=luaF_newproto(L); | ||
223 | LoadFunction(&S,cl->l.p); | ||
224 | if (cl->l.p->sizeupvalues != 1) | ||
225 | { | ||
226 | Proto* p=cl->l.p; | ||
227 | cl=luaF_newLclosure(L,cl->l.p->sizeupvalues); | ||
228 | cl->l.p=p; | ||
229 | setclLvalue(L,L->top-1,cl); | ||
230 | } | ||
231 | luai_verifycode(L,buff,cl->l.p); | ||
232 | return cl; | ||
220 | } | 233 | } |
221 | 234 | ||
222 | #define MYINT(s) (s[0]-'0') | 235 | #define MYINT(s) (s[0]-'0') |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lundump.h,v 1.44 2011/05/06 13:35:17 lhf Exp $ | 2 | ** $Id: lundump.h,v 1.38 2011/05/17 12:42:43 roberto Exp roberto $ |
3 | ** load precompiled Lua chunks | 3 | ** load precompiled Lua chunks |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -11,7 +11,7 @@ | |||
11 | #include "lzio.h" | 11 | #include "lzio.h" |
12 | 12 | ||
13 | /* load one chunk; from lundump.c */ | 13 | /* load one chunk; from lundump.c */ |
14 | LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); | 14 | LUAI_FUNC Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); |
15 | 15 | ||
16 | /* make header; from lundump.c */ | 16 | /* make header; from lundump.c */ |
17 | LUAI_FUNC void luaU_header (lu_byte* h); | 17 | LUAI_FUNC void luaU_header (lu_byte* h); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.147 2011/12/07 14:43:55 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.149 2012/01/25 21:05:40 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -395,7 +395,8 @@ static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base, | |||
395 | int nup = p->sizeupvalues; | 395 | int nup = p->sizeupvalues; |
396 | Upvaldesc *uv = p->upvalues; | 396 | Upvaldesc *uv = p->upvalues; |
397 | int i; | 397 | int i; |
398 | Closure *ncl = luaF_newLclosure(L, p); | 398 | Closure *ncl = luaF_newLclosure(L, nup); |
399 | ncl->l.p = p; | ||
399 | setclLvalue(L, ra, ncl); /* anchor new closure in stack */ | 400 | setclLvalue(L, ra, ncl); /* anchor new closure in stack */ |
400 | for (i = 0; i < nup; i++) { /* fill in its upvalues */ | 401 | for (i = 0; i < nup; i++) { /* fill in its upvalues */ |
401 | if (uv[i].instack) /* upvalue refers to local variable? */ | 402 | if (uv[i].instack) /* upvalue refers to local variable? */ |