diff options
Diffstat (limited to '')
| -rw-r--r-- | lundump.c | 32 |
1 files changed, 15 insertions, 17 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lundump.c,v 1.18 1999/04/09 03:10:40 lhf Exp lhf $ | 2 | ** $Id: lundump.c,v 1.19 1999/04/15 12:30:03 lhf Exp lhf $ |
| 3 | ** load bytecodes from files | 3 | ** load bytecodes from files |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -15,12 +15,6 @@ | |||
| 15 | 15 | ||
| 16 | #define LoadBlock(b,size,Z) ezread(Z,b,size) | 16 | #define LoadBlock(b,size,Z) ezread(Z,b,size) |
| 17 | 17 | ||
| 18 | #if LUAC_NATIVE | ||
| 19 | #define doLoadNumber(x,Z) LoadBlock(&x,sizeof(x),Z) | ||
| 20 | #else | ||
| 21 | #define doLoadNumber(x,Z) x=LoadNumber(Z) | ||
| 22 | #endif | ||
| 23 | |||
| 24 | static void unexpectedEOZ (ZIO* Z) | 18 | static void unexpectedEOZ (ZIO* Z) |
| 25 | { | 19 | { |
| 26 | luaL_verror("unexpected end of file in %s",zname(Z)); | 20 | luaL_verror("unexpected end of file in %s",zname(Z)); |
| @@ -55,6 +49,11 @@ static unsigned long LoadLong (ZIO* Z) | |||
| 55 | 49 | ||
| 56 | static real LoadNumber (ZIO* Z) | 50 | static real LoadNumber (ZIO* Z) |
| 57 | { | 51 | { |
| 52 | #ifdef LUAC_NATIVE | ||
| 53 | real x; | ||
| 54 | LoadBlock(&x,sizeof(x),Z); | ||
| 55 | return x; | ||
| 56 | #else | ||
| 58 | char b[256]; | 57 | char b[256]; |
| 59 | int size=ezgetc(Z); | 58 | int size=ezgetc(Z); |
| 60 | LoadBlock(b,size,Z); | 59 | LoadBlock(b,size,Z); |
| @@ -62,7 +61,8 @@ static real LoadNumber (ZIO* Z) | |||
| 62 | if (b[0]=='-') | 61 | if (b[0]=='-') |
| 63 | return -luaO_str2d(b+1); | 62 | return -luaO_str2d(b+1); |
| 64 | else | 63 | else |
| 65 | return luaO_str2d(b); | 64 | return luaO_str2d(b); |
| 65 | #endif | ||
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | static int LoadInt (ZIO* Z, char* message) | 68 | static int LoadInt (ZIO* Z, char* message) |
| @@ -127,7 +127,7 @@ static void LoadConstants (TProtoFunc* tf, ZIO* Z) | |||
| 127 | switch (ttype(o)) | 127 | switch (ttype(o)) |
| 128 | { | 128 | { |
| 129 | case LUA_T_NUMBER: | 129 | case LUA_T_NUMBER: |
| 130 | doLoadNumber(nvalue(o),Z); | 130 | nvalue(o)=LoadNumber(Z); |
| 131 | break; | 131 | break; |
| 132 | case LUA_T_STRING: | 132 | case LUA_T_STRING: |
| 133 | tsvalue(o)=LoadTString(Z); | 133 | tsvalue(o)=LoadTString(Z); |
| @@ -178,10 +178,9 @@ static void LoadHeader (ZIO* Z) | |||
| 178 | "%s too old: version=0x%02x; expected at least 0x%02x", | 178 | "%s too old: version=0x%02x; expected at least 0x%02x", |
| 179 | zname(Z),version,VERSION0); | 179 | zname(Z),version,VERSION0); |
| 180 | sizeofR=ezgetc(Z); /* test number representation */ | 180 | sizeofR=ezgetc(Z); /* test number representation */ |
| 181 | #if LUAC_NATIVE | 181 | #ifdef LUAC_NATIVE |
| 182 | if (sizeofR==0) | 182 | if (sizeofR==0) |
| 183 | luaL_verror("cannot read numbers in %s: " | 183 | luaL_verror("cannot read numbers in %s: no support for decimal format", |
| 184 | "support for decimal format not enabled", | ||
| 185 | zname(Z)); | 184 | zname(Z)); |
| 186 | if (sizeofR!=sizeof(real)) | 185 | if (sizeofR!=sizeof(real)) |
| 187 | luaL_verror("unknown number size in %s: read %d; expected %d", | 186 | luaL_verror("unknown number size in %s: read %d; expected %d", |
| @@ -189,16 +188,15 @@ static void LoadHeader (ZIO* Z) | |||
| 189 | else | 188 | else |
| 190 | { | 189 | { |
| 191 | real f=-TEST_NUMBER,tf=TEST_NUMBER; | 190 | real f=-TEST_NUMBER,tf=TEST_NUMBER; |
| 192 | doLoadNumber(f,Z); | 191 | f=LoadNumber(Z); |
| 193 | if (f!=tf) | 192 | if ((long)f!=(long)tf) |
| 194 | luaL_verror("unknown number representation in %s: " | 193 | luaL_verror("unknown number format in %s: " |
| 195 | "read " NUMBER_FMT "; expected " NUMBER_FMT, | 194 | "read " NUMBER_FMT "; expected " NUMBER_FMT, |
| 196 | zname(Z),f,tf); | 195 | zname(Z),f,tf); |
| 197 | } | 196 | } |
| 198 | #else | 197 | #else |
| 199 | if (sizeofR!=0) | 198 | if (sizeofR!=0) |
| 200 | luaL_verror("cannot read numbers in %s: " | 199 | luaL_verror("cannot read numbers in %s: no support for native format", |
| 201 | "support for native format not enabled", | ||
| 202 | zname(Z)); | 200 | zname(Z)); |
| 203 | #endif | 201 | #endif |
| 204 | } | 202 | } |
