diff options
author | Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> | 1997-04-14 09:12:40 -0300 |
---|---|---|
committer | Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> | 1997-04-14 09:12:40 -0300 |
commit | e78c1c54aacdd581f729214b199b2eb750a349ac (patch) | |
tree | c6873bec256578cc5ff66435235b12e902042262 | |
parent | 42049b42f1ec7ba3dfb8ffd5cdcfc8b2b95a008f (diff) | |
download | lua-3.0-alpha.tar.gz lua-3.0-alpha.tar.bz2 lua-3.0-alpha.zip |
mem.h is now luamem.hv3.0-alpha
removed warn
added support for new opcodes (VARARGS, STOREMAP)
better error messages with luaL_verror
-rw-r--r-- | undump.c | 46 |
1 files changed, 23 insertions, 23 deletions
@@ -3,12 +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.20 1996/11/16 20:14:23 lhf Exp lhf $"; | 6 | char* rcs_undump="$Id: undump.c,v 1.21 1996/11/18 11:18:29 lhf Exp lhf $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <string.h> | 9 | #include <string.h> |
10 | #include "auxlib.h" | ||
10 | #include "opcode.h" | 11 | #include "opcode.h" |
11 | #include "mem.h" | 12 | #include "luamem.h" |
12 | #include "table.h" | 13 | #include "table.h" |
13 | #include "undump.h" | 14 | #include "undump.h" |
14 | 15 | ||
@@ -17,19 +18,12 @@ static int swapfloat=0; | |||
17 | static TFunc* Main=NULL; /* functions in a chunk */ | 18 | static TFunc* Main=NULL; /* functions in a chunk */ |
18 | static TFunc* lastF=NULL; | 19 | static TFunc* lastF=NULL; |
19 | 20 | ||
20 | static void warn(char* s) /* TODO: remove */ | ||
21 | { | ||
22 | #if 0 | ||
23 | fprintf(stderr,"undump: %s\n",s); | ||
24 | #endif | ||
25 | } | ||
26 | |||
27 | static void FixCode(Byte* code, Byte* end) /* swap words */ | 21 | static void FixCode(Byte* code, Byte* end) /* swap words */ |
28 | { | 22 | { |
29 | Byte* p; | 23 | Byte* p; |
30 | for (p=code; p!=end;) | 24 | for (p=code; p!=end;) |
31 | { | 25 | { |
32 | OpCode op=(OpCode)*p; | 26 | int op=*p; |
33 | switch (op) | 27 | switch (op) |
34 | { | 28 | { |
35 | case PUSHNIL: | 29 | case PUSHNIL: |
@@ -83,6 +77,8 @@ static void FixCode(Byte* code, Byte* end) /* swap words */ | |||
83 | case STORELIST0: | 77 | case STORELIST0: |
84 | case ADJUST: | 78 | case ADJUST: |
85 | case RETCODE: | 79 | case RETCODE: |
80 | case VARARGS: | ||
81 | case STOREMAP: | ||
86 | p+=2; | 82 | p+=2; |
87 | break; | 83 | break; |
88 | case STORELIST: | 84 | case STORELIST: |
@@ -132,7 +128,8 @@ static void FixCode(Byte* code, Byte* end) /* swap words */ | |||
132 | break; | 128 | break; |
133 | } | 129 | } |
134 | default: | 130 | default: |
135 | lua_error("corrupt binary file"); | 131 | luaL_verror("corrupt binary file: bad opcode %d at %d\n", |
132 | op,(int)(p-code)); | ||
136 | break; | 133 | break; |
137 | } | 134 | } |
138 | } | 135 | } |
@@ -156,7 +153,7 @@ static int LoadWord(FILE* D) | |||
156 | fread(&w,sizeof(w),1,D); | 153 | fread(&w,sizeof(w),1,D); |
157 | if (swapword) | 154 | if (swapword) |
158 | { | 155 | { |
159 | Byte* p=(Byte*)&w; /* TODO: need union? */ | 156 | Byte* p=(Byte*)&w; |
160 | Byte t; | 157 | Byte t; |
161 | t=p[0]; p[0]=p[1]; p[1]=t; | 158 | t=p[0]; p[0]=p[1]; p[1]=t; |
162 | } | 159 | } |
@@ -243,10 +240,10 @@ static void LoadSignature(FILE* D) | |||
243 | char* s=SIGNATURE; | 240 | char* s=SIGNATURE; |
244 | while (*s!=0 && getc(D)==*s) | 241 | while (*s!=0 && getc(D)==*s) |
245 | ++s; | 242 | ++s; |
246 | if (*s!=0) lua_error("bad signature"); | 243 | if (*s!=0) lua_error("cannot load binary file: bad signature"); |
247 | } | 244 | } |
248 | 245 | ||
249 | static void LoadHeader(FILE* D) /* TODO: error handling */ | 246 | static void LoadHeader(FILE* D) |
250 | { | 247 | { |
251 | Word w,tw=TEST_WORD; | 248 | Word w,tw=TEST_WORD; |
252 | float f,tf=TEST_FLOAT; | 249 | float f,tf=TEST_FLOAT; |
@@ -259,30 +256,33 @@ static void LoadHeader(FILE* D) /* TODO: error handling */ | |||
259 | int oldsizeofF=getc(D); | 256 | int oldsizeofF=getc(D); |
260 | int oldsizeofP=getc(D); | 257 | int oldsizeofP=getc(D); |
261 | if (oldsizeofW!=2) | 258 | if (oldsizeofW!=2) |
262 | lua_error("cannot load binary file created on machine with sizeof(Word)!=2"); | 259 | luaL_verror( |
260 | "cannot load binary file created on machine with sizeof(Word)=%d; " | ||
261 | "expected 2",oldsizeofW); | ||
263 | if (oldsizeofF!=4) | 262 | if (oldsizeofF!=4) |
264 | lua_error("cannot load binary file created on machine with sizeof(float)!=4. not an IEEE machine?"); | 263 | luaL_verror( |
265 | if (oldsizeofP!=sizeof(TFunc*)) /* TODO: pack */ | 264 | "cannot load binary file created on machine with sizeof(float)=%d; " |
266 | lua_error("cannot load binary file: different pointer sizes"); | 265 | "expected 4\nnot an IEEE machine?",oldsizeofF); |
266 | if (oldsizeofP!=sizeof(TFunc*)) /* TODO: pack? */ | ||
267 | luaL_verror( | ||
268 | "cannot load binary file created on machine with sizeof(TFunc*)=%d; " | ||
269 | "expected %d",oldsizeofP,sizeof(TFunc*)); | ||
267 | } | 270 | } |
268 | fread(&w,sizeof(w),1,D); /* test word */ | 271 | fread(&w,sizeof(w),1,D); /* test word */ |
269 | if (w!=tw) | 272 | if (w!=tw) |
270 | { | 273 | { |
271 | swapword=1; | 274 | swapword=1; |
272 | warn("different byte order"); | ||
273 | } | 275 | } |
274 | fread(&f,sizeof(f),1,D); /* test float */ | 276 | fread(&f,sizeof(f),1,D); /* test float */ |
275 | if (f!=tf) | 277 | if (f!=tf) |
276 | { | 278 | { |
277 | Byte* p=(Byte*)&f; /* TODO: need union? */ | 279 | Byte* p=(Byte*)&f; |
278 | Byte t; | 280 | Byte t; |
279 | swapfloat=1; | 281 | swapfloat=1; |
280 | t=p[0]; p[0]=p[3]; p[3]=t; | 282 | t=p[0]; p[0]=p[3]; p[3]=t; |
281 | t=p[1]; p[1]=p[2]; p[2]=t; | 283 | t=p[1]; p[1]=p[2]; p[2]=t; |
282 | if (f!=tf) /* TODO: try another perm? */ | 284 | if (f!=tf) /* TODO: try another perm? */ |
283 | lua_error("different float representation"); | 285 | lua_error("cannot load binary file: unknown float representation"); |
284 | else | ||
285 | warn("different byte order in floats"); | ||
286 | } | 286 | } |
287 | } | 287 | } |
288 | 288 | ||