diff options
| author | Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> | 1996-03-11 19:01:46 -0300 |
|---|---|---|
| committer | Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> | 1996-03-11 19:01:46 -0300 |
| commit | 5eff5d3eac37a7596550a881d1db470fef0c1648 (patch) | |
| tree | aead9b53a7f6621c67b9b9345164e30400331f70 | |
| parent | 8ad8426c43ff848682cb26269bdf80c21c372483 (diff) | |
| download | lua-5eff5d3eac37a7596550a881d1db470fef0c1648.tar.gz lua-5eff5d3eac37a7596550a881d1db470fef0c1648.tar.bz2 lua-5eff5d3eac37a7596550a881d1db470fef0c1648.zip | |
moved some includes from undump.h
LoadString now uses luaI_buffer
added LoadNewString
needs tf->marked=0
luaI_undump now returns int and aborts if luaI_dorun fails
| -rw-r--r-- | undump.c | 60 |
1 files changed, 30 insertions, 30 deletions
| @@ -3,10 +3,13 @@ | |||
| 3 | ** load bytecodes from files | 3 | ** load bytecodes from files |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char* rcs_undump="$Id: undump.c,v 1.10 1996/03/06 21:40:10 lhf Exp lhf $"; | 6 | char* rcs_undump="$Id: undump.c,v 1.11 1996/03/08 21:44:12 lhf Exp lhf $"; |
| 7 | 7 | ||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| 10 | #include "opcode.h" | ||
| 11 | #include "mem.h" | ||
| 12 | #include "table.h" | ||
| 10 | #include "undump.h" | 13 | #include "undump.h" |
| 11 | 14 | ||
| 12 | static int swapword=0; | 15 | static int swapword=0; |
| @@ -16,7 +19,9 @@ static TFunc* lastF=NULL; | |||
| 16 | 19 | ||
| 17 | static void warn(char* s) /* TODO: remove */ | 20 | static void warn(char* s) /* TODO: remove */ |
| 18 | { | 21 | { |
| 22 | #if 0 | ||
| 19 | fprintf(stderr,"undump: %s\n",s); | 23 | fprintf(stderr,"undump: %s\n",s); |
| 24 | #endif | ||
| 20 | } | 25 | } |
| 21 | 26 | ||
| 22 | static void FixCode(Byte* code, Byte* end) /* swap words */ | 27 | static void FixCode(Byte* code, Byte* end) /* swap words */ |
| @@ -160,13 +165,6 @@ static int LoadWord(FILE* D) | |||
| 160 | return w; | 165 | return w; |
| 161 | } | 166 | } |
| 162 | 167 | ||
| 163 | static char* LoadBlock(int size, FILE* D) | ||
| 164 | { | ||
| 165 | char* b=luaI_malloc(size); | ||
| 166 | fread(b,size,1,D); | ||
| 167 | return b; | ||
| 168 | } | ||
| 169 | |||
| 170 | static int LoadSize(FILE* D) | 168 | static int LoadSize(FILE* D) |
| 171 | { | 169 | { |
| 172 | Word hi=LoadWord(D); | 170 | Word hi=LoadWord(D); |
| @@ -176,8 +174,23 @@ static int LoadSize(FILE* D) | |||
| 176 | return s; | 174 | return s; |
| 177 | } | 175 | } |
| 178 | 176 | ||
| 177 | static char* LoadBlock(int size, FILE* D) | ||
| 178 | { | ||
| 179 | char* b=luaI_malloc(size); | ||
| 180 | fread(b,size,1,D); | ||
| 181 | return b; | ||
| 182 | } | ||
| 183 | |||
| 179 | static char* LoadString(FILE* D) | 184 | static char* LoadString(FILE* D) |
| 180 | { | 185 | { |
| 186 | int size=LoadWord(D); | ||
| 187 | char *b=luaI_buffer(size); | ||
| 188 | fread(b,size,1,D); | ||
| 189 | return b; | ||
| 190 | } | ||
| 191 | |||
| 192 | static char* LoadNewString(FILE* D) | ||
| 193 | { | ||
| 181 | return LoadBlock(LoadWord(D),D); | 194 | return LoadBlock(LoadWord(D),D); |
| 182 | } | 195 | } |
| 183 | 196 | ||
| @@ -190,7 +203,7 @@ static void LoadFunction(FILE* D) | |||
| 190 | tf->lineDefined=LoadWord(D); | 203 | tf->lineDefined=LoadWord(D); |
| 191 | if (IsMain(tf)) /* new main */ | 204 | if (IsMain(tf)) /* new main */ |
| 192 | { | 205 | { |
| 193 | tf->fileName=LoadString(D); | 206 | tf->fileName=LoadNewString(D); |
| 194 | Main=lastF=tf; | 207 | Main=lastF=tf; |
| 195 | } | 208 | } |
| 196 | else /* fix PUSHFUNCTION */ | 209 | else /* fix PUSHFUNCTION */ |
| @@ -204,9 +217,7 @@ static void LoadFunction(FILE* D) | |||
| 204 | *p++=c.m.c1; *p++=c.m.c2; *p++=c.m.c3; *p++=c.m.c4; | 217 | *p++=c.m.c1; *p++=c.m.c2; *p++=c.m.c3; *p++=c.m.c4; |
| 205 | lastF=lastF->next=tf; | 218 | lastF=lastF->next=tf; |
| 206 | } | 219 | } |
| 207 | #if 0 | 220 | tf->marked=0; |
| 208 | tf->marked=0; /* TODO: is this ok? */ | ||
| 209 | #endif | ||
| 210 | tf->code=LoadBlock(tf->size,D); | 221 | tf->code=LoadBlock(tf->size,D); |
| 211 | if (swapword || swapfloat) FixCode(tf->code,tf->code+tf->size); | 222 | if (swapword || swapfloat) FixCode(tf->code,tf->code+tf->size); |
| 212 | while (1) /* unthread */ | 223 | while (1) /* unthread */ |
| @@ -216,14 +227,14 @@ static void LoadFunction(FILE* D) | |||
| 216 | { | 227 | { |
| 217 | int i=LoadWord(D); | 228 | int i=LoadWord(D); |
| 218 | char* s=LoadString(D); | 229 | char* s=LoadString(D); |
| 219 | int v=luaI_findsymbolbyname(s); /* TODO: free s? */ | 230 | int v=luaI_findsymbolbyname(s); |
| 220 | Unthread(tf->code,i,v); | 231 | Unthread(tf->code,i,v); |
| 221 | } | 232 | } |
| 222 | else if (c==ID_STR) /* constant string */ | 233 | else if (c==ID_STR) /* constant string */ |
| 223 | { | 234 | { |
| 224 | int i=LoadWord(D); | 235 | int i=LoadWord(D); |
| 225 | char* s=LoadString(D); | 236 | char* s=LoadString(D); |
| 226 | int v=luaI_findconstantbyname(s); /* TODO: free s? */ | 237 | int v=luaI_findconstantbyname(s); |
| 227 | Unthread(tf->code,i,v); | 238 | Unthread(tf->code,i,v); |
| 228 | } | 239 | } |
| 229 | else | 240 | else |
| @@ -303,25 +314,14 @@ TFunc* luaI_undump1(FILE* D) | |||
| 303 | /* | 314 | /* |
| 304 | ** load and run all chunks in a file | 315 | ** load and run all chunks in a file |
| 305 | */ | 316 | */ |
| 306 | void luaI_undump(FILE* D) | 317 | int luaI_undump(FILE* D) |
| 307 | { | 318 | { |
| 308 | TFunc* m; | 319 | TFunc* m; |
| 309 | while ((m=luaI_undump1(D))) | 320 | while ((m=luaI_undump1(D))) |
| 310 | { | 321 | { |
| 311 | #if 0 | 322 | int status=luaI_dorun(m); |
| 312 | luaI_dorun(m); | 323 | luaI_freefunc(m); |
| 313 | luaI_freefunc(m); /* TODO: free others? */ | 324 | if (status!=0) return status; |
| 314 | #endif | ||
| 315 | } | 325 | } |
| 316 | } | 326 | return 0; |
| 317 | |||
| 318 | char* luaI_buffer(int n) | ||
| 319 | { | ||
| 320 | static int size=0; | ||
| 321 | static char* buffer=NULL; | ||
| 322 | if (buffer==NULL) | ||
| 323 | buffer=luaI_malloc(n); | ||
| 324 | else if (n>size) | ||
| 325 | buffer=luaI_realloc(buffer,size=n); | ||
| 326 | return buffer; | ||
| 327 | } | 327 | } |
