diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-01-27 13:52:57 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-01-27 13:52:57 -0200 |
| commit | 0175f8d5d18d18e2d8a94db9c5be5c40598aebda (patch) | |
| tree | 9b16f0dfa99f038e87cbd053353042581cbcfc6a | |
| parent | e79bf02f33c57523833b5b700d0d5b6e6955a5d7 (diff) | |
| download | lua-0175f8d5d18d18e2d8a94db9c5be5c40598aebda.tar.gz lua-0175f8d5d18d18e2d8a94db9c5be5c40598aebda.tar.bz2 lua-0175f8d5d18d18e2d8a94db9c5be5c40598aebda.zip | |
dump/undump of upvalue names
| -rw-r--r-- | ldump.c | 32 | ||||
| -rw-r--r-- | lundump.c | 26 | ||||
| -rw-r--r-- | lundump.h | 8 |
3 files changed, 50 insertions, 16 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldump.c,v 1.1 2002/10/25 21:31:28 roberto Exp roberto $ | 2 | ** $Id: ldump.c,v 1.3 2003/01/10 11:08:45 lhf Exp $ |
| 3 | ** save bytecodes | 3 | ** save bytecodes |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -19,13 +19,12 @@ | |||
| 19 | #define DumpLiteral(s,D) DumpBlock("" s,(sizeof(s))-1,D) | 19 | #define DumpLiteral(s,D) DumpBlock("" s,(sizeof(s))-1,D) |
| 20 | 20 | ||
| 21 | typedef struct { | 21 | typedef struct { |
| 22 | lua_State *L; | 22 | lua_State* L; |
| 23 | lua_Chunkwriter write; | 23 | lua_Chunkwriter write; |
| 24 | void *data; | 24 | void* data; |
| 25 | } DumpState; | 25 | } DumpState; |
| 26 | 26 | ||
| 27 | 27 | static void DumpBlock(const void* b, size_t size, DumpState* D) | |
| 28 | static void DumpBlock(const void *b, size_t size, DumpState* D) | ||
| 29 | { | 28 | { |
| 30 | lua_unlock(D->L); | 29 | lua_unlock(D->L); |
| 31 | (*D->write)(D->L,b,size,D->data); | 30 | (*D->write)(D->L,b,size,D->data); |
| @@ -89,6 +88,18 @@ static void DumpLines(const Proto* f, DumpState* D) | |||
| 89 | DumpVector(f->lineinfo,f->sizelineinfo,sizeof(*f->lineinfo),D); | 88 | DumpVector(f->lineinfo,f->sizelineinfo,sizeof(*f->lineinfo),D); |
| 90 | } | 89 | } |
| 91 | 90 | ||
| 91 | static void DumpUpvalues(const Proto* f, DumpState* D) | ||
| 92 | { | ||
| 93 | if (f->upvalues==NULL) | ||
| 94 | DumpInt(0,D); | ||
| 95 | else | ||
| 96 | { | ||
| 97 | int i,n=f->nupvalues; | ||
| 98 | DumpInt(n,D); | ||
| 99 | for (i=0; i<n; i++) DumpString(f->upvalues[i],D); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 92 | static void DumpFunction(const Proto* f, const TString* p, DumpState* D); | 103 | static void DumpFunction(const Proto* f, const TString* p, DumpState* D); |
| 93 | 104 | ||
| 94 | static void DumpConstants(const Proto* f, DumpState* D) | 105 | static void DumpConstants(const Proto* f, DumpState* D) |
| @@ -122,12 +133,13 @@ static void DumpFunction(const Proto* f, const TString* p, DumpState* D) | |||
| 122 | { | 133 | { |
| 123 | DumpString((f->source==p) ? NULL : f->source,D); | 134 | DumpString((f->source==p) ? NULL : f->source,D); |
| 124 | DumpInt(f->lineDefined,D); | 135 | DumpInt(f->lineDefined,D); |
| 125 | DumpByte(f->nupvalues,D); | 136 | DumpInt(f->nupvalues,D); |
| 126 | DumpByte(f->numparams,D); | 137 | DumpByte(f->numparams,D); |
| 127 | DumpByte(f->is_vararg,D); | 138 | DumpByte(f->is_vararg,D); |
| 128 | DumpByte(f->maxstacksize,D); | 139 | DumpByte(f->maxstacksize,D); |
| 129 | DumpLocals(f,D); | ||
| 130 | DumpLines(f,D); | 140 | DumpLines(f,D); |
| 141 | DumpLocals(f,D); | ||
| 142 | DumpUpvalues(f,D); | ||
| 131 | DumpConstants(f,D); | 143 | DumpConstants(f,D); |
| 132 | DumpCode(f,D); | 144 | DumpCode(f,D); |
| 133 | } | 145 | } |
| @@ -148,7 +160,10 @@ static void DumpHeader(DumpState* D) | |||
| 148 | DumpNumber(TEST_NUMBER,D); | 160 | DumpNumber(TEST_NUMBER,D); |
| 149 | } | 161 | } |
| 150 | 162 | ||
| 151 | void luaU_dump(lua_State *L, const Proto* Main, lua_Chunkwriter w, void* data) | 163 | /* |
| 164 | ** dump function as precompiled chunk | ||
| 165 | */ | ||
| 166 | void luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data) | ||
| 152 | { | 167 | { |
| 153 | DumpState D; | 168 | DumpState D; |
| 154 | D.L=L; | 169 | D.L=L; |
| @@ -157,4 +172,3 @@ void luaU_dump(lua_State *L, const Proto* Main, lua_Chunkwriter w, void* data) | |||
| 157 | DumpHeader(&D); | 172 | DumpHeader(&D); |
| 158 | DumpFunction(Main,NULL,&D); | 173 | DumpFunction(Main,NULL,&D); |
| 159 | } | 174 | } |
| 160 | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lundump.c,v 1.57 2002/11/14 16:15:53 roberto Exp roberto $ | 2 | ** $Id: lundump.c,v 1.47 2003/01/10 11:08:45 lhf Exp $ |
| 3 | ** load pre-compiled Lua chunks | 3 | ** load pre-compiled Lua chunks |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -138,6 +138,25 @@ static void LoadLines (LoadState* S, Proto* f) | |||
| 138 | LoadVector(S,f->lineinfo,size,sizeof(*f->lineinfo)); | 138 | LoadVector(S,f->lineinfo,size,sizeof(*f->lineinfo)); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | static void LoadUpvalues (LoadState* S, Proto* f) | ||
| 142 | { | ||
| 143 | int i,n,noname; | ||
| 144 | n=LoadInt(S); | ||
| 145 | noname=(n==0); | ||
| 146 | if (!noname && n!=f->nupvalues) | ||
| 147 | luaG_runerror(S->L,"bad nupvalues in %s: read %d; expected %d", | ||
| 148 | S->name,n,f->nupvalues); | ||
| 149 | n=f->nupvalues; | ||
| 150 | f->upvalues=luaM_newvector(S->L,n,TString*); | ||
| 151 | if (noname) | ||
| 152 | { | ||
| 153 | TString* name=luaS_newliteral(S->L,"(no name)"); | ||
| 154 | for (i=0; i<n; i++) f->upvalues[i]=name; | ||
| 155 | } | ||
| 156 | else | ||
| 157 | for (i=0; i<n; i++) f->upvalues[i]=LoadString(S); | ||
| 158 | } | ||
| 159 | |||
| 141 | static Proto* LoadFunction (LoadState* S, TString* p); | 160 | static Proto* LoadFunction (LoadState* S, TString* p); |
| 142 | 161 | ||
| 143 | static void LoadConstants (LoadState* S, Proto* f) | 162 | static void LoadConstants (LoadState* S, Proto* f) |
| @@ -177,12 +196,13 @@ static Proto* LoadFunction (LoadState* S, TString* p) | |||
| 177 | Proto* f=luaF_newproto(S->L); | 196 | Proto* f=luaF_newproto(S->L); |
| 178 | f->source=LoadString(S); if (f->source==NULL) f->source=p; | 197 | f->source=LoadString(S); if (f->source==NULL) f->source=p; |
| 179 | f->lineDefined=LoadInt(S); | 198 | f->lineDefined=LoadInt(S); |
| 180 | f->nupvalues=LoadByte(S); | 199 | f->nupvalues=LoadInt(S); |
| 181 | f->numparams=LoadByte(S); | 200 | f->numparams=LoadByte(S); |
| 182 | f->is_vararg=LoadByte(S); | 201 | f->is_vararg=LoadByte(S); |
| 183 | f->maxstacksize=LoadByte(S); | 202 | f->maxstacksize=LoadByte(S); |
| 184 | LoadLocals(S,f); | ||
| 185 | LoadLines(S,f); | 203 | LoadLines(S,f); |
| 204 | LoadLocals(S,f); | ||
| 205 | LoadUpvalues(S,f); | ||
| 186 | LoadConstants(S,f); | 206 | LoadConstants(S,f); |
| 187 | LoadCode(S,f); | 207 | LoadCode(S,f); |
| 188 | #ifndef TRUST_BINARIES | 208 | #ifndef TRUST_BINARIES |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lundump.h,v 1.28 2002/10/09 13:42:01 roberto Exp roberto $ | 2 | ** $Id: lundump.h,v 1.28 2002/12/13 11:12:35 lhf Exp $ |
| 3 | ** load pre-compiled Lua chunks | 3 | ** load pre-compiled Lua chunks |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -11,13 +11,13 @@ | |||
| 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 | Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer *buff); | 14 | Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff); |
| 15 | 15 | ||
| 16 | /* find byte order; from lundump.c */ | 16 | /* find byte order; from lundump.c */ |
| 17 | int luaU_endianness (void); | 17 | int luaU_endianness (void); |
| 18 | 18 | ||
| 19 | /* dump one chunk; from dump.c */ | 19 | /* dump one chunk; from ldump.c */ |
| 20 | void luaU_dump (lua_State *L, const Proto* Main, lua_Chunkwriter w, void* data); | 20 | void luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data); |
| 21 | 21 | ||
| 22 | /* print one chunk; from print.c */ | 22 | /* print one chunk; from print.c */ |
| 23 | void luaU_print (const Proto* Main); | 23 | void luaU_print (const Proto* Main); |
