diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-05-08 10:53:33 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-05-08 10:53:33 -0300 |
commit | 3cadc37f470df50deb5c920b028125b8bb6c316b (patch) | |
tree | a2a448ef80bddb0ddef2581d0692ccec3de5b159 /lundump.c | |
parent | bb1146dc3986c6f123ed6d85a26694ca8d56f94a (diff) | |
download | lua-3cadc37f470df50deb5c920b028125b8bb6c316b.tar.gz lua-3cadc37f470df50deb5c920b028125b8bb6c316b.tar.bz2 lua-3cadc37f470df50deb5c920b028125b8bb6c316b.zip |
no more 'Proto' objects on the stack. Protos are anchored on outer
Protos or on a Closure, which must be created before the Proto.
Diffstat (limited to 'lundump.c')
-rw-r--r-- | lundump.c | 35 |
1 files changed, 24 insertions, 11 deletions
@@ -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') |