diff options
-rw-r--r-- | lundump.c | 36 | ||||
-rw-r--r-- | lundump.h | 30 |
2 files changed, 38 insertions, 28 deletions
@@ -1,11 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lundump.c,v 1.9 1998/06/13 16:54:15 lhf Exp $ | 2 | ** $Id: lundump.c,v 1.10 1998/06/25 15:50:09 lhf Exp $ |
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 | */ |
6 | 6 | ||
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | |||
9 | #include "lauxlib.h" | 8 | #include "lauxlib.h" |
10 | #include "lfunc.h" | 9 | #include "lfunc.h" |
11 | #include "lmem.h" | 10 | #include "lmem.h" |
@@ -13,21 +12,12 @@ | |||
13 | #include "lundump.h" | 12 | #include "lundump.h" |
14 | 13 | ||
15 | #define LoadBlock(b,size,Z) ezread(Z,b,size) | 14 | #define LoadBlock(b,size,Z) ezread(Z,b,size) |
16 | #define LoadNative(t,D) LoadBlock(&t,sizeof(t),D) | 15 | #define LoadNative(t,Z) LoadBlock(&t,sizeof(t),Z) |
17 | |||
18 | /* LUA_NUMBER */ | ||
19 | /* see comment in lundump.h */ | ||
20 | 16 | ||
21 | #if ID_NUMBER==ID_REAL4 | 17 | #if ID_NUMBER==ID_NATIVE |
22 | #define LoadNumber LoadFloat | 18 | #define doLoadNumber(f,Z) LoadNative(f,Z) |
23 | #elif ID_NUMBER==ID_REAL8 | ||
24 | #define LoadNumber LoadDouble | ||
25 | #elif ID_NUMBER==ID_INT4 | ||
26 | #define LoadNumber LoadLong | ||
27 | #elif ID_NUMBER==ID_NATIVE | ||
28 | #define LoadNumber LoadNative | ||
29 | #else | 19 | #else |
30 | #define LoadNumber LoadWhat | 20 | #define doLoadNumber(f,Z) f=LoadNumber(Z) |
31 | #endif | 21 | #endif |
32 | 22 | ||
33 | static void unexpectedEOZ(ZIO* Z) | 23 | static void unexpectedEOZ(ZIO* Z) |
@@ -150,11 +140,7 @@ static void LoadConstants(TProtoFunc* tf, ZIO* Z) | |||
150 | { | 140 | { |
151 | case ID_NUM: | 141 | case ID_NUM: |
152 | ttype(o)=LUA_T_NUMBER; | 142 | ttype(o)=LUA_T_NUMBER; |
153 | #if ID_NUMBER==ID_NATIVE | 143 | doLoadNumber(nvalue(o),Z); |
154 | LoadNative(nvalue(o),Z) | ||
155 | #else | ||
156 | nvalue(o)=LoadNumber(Z); | ||
157 | #endif | ||
158 | break; | 144 | break; |
159 | case ID_STR: | 145 | case ID_STR: |
160 | ttype(o)=LUA_T_STRING; | 146 | ttype(o)=LUA_T_STRING; |
@@ -200,19 +186,19 @@ static void LoadHeader(ZIO* Z) | |||
200 | luaL_verror( | 186 | luaL_verror( |
201 | "%s too new: version=0x%02x; expected at most 0x%02x", | 187 | "%s too new: version=0x%02x; expected at most 0x%02x", |
202 | zname(Z),version,VERSION); | 188 | zname(Z),version,VERSION); |
203 | if (version<0x31) /* major change in 3.1 */ | 189 | if (version<VERSION0) /* check last major change */ |
204 | luaL_verror( | 190 | luaL_verror( |
205 | "%s too old: version=0x%02x; expected at least 0x%02x", | 191 | "%s too old: version=0x%02x; expected at least 0x%02x", |
206 | zname(Z),version,0x31); | 192 | zname(Z),version,VERSION0); |
207 | id=ezgetc(Z); /* test number representation */ | 193 | id=ezgetc(Z); /* test number representation */ |
208 | sizeofR=ezgetc(Z); | 194 | sizeofR=ezgetc(Z); |
209 | if (id!=ID_NUMBER || sizeofR!=sizeof(real)) | 195 | if (id!=ID_NUMBER || sizeofR!=sizeof(real)) |
210 | { | 196 | { |
211 | luaL_verror("unknown number representation in %s: " | 197 | luaL_verror("unknown number signature in %s: " |
212 | "read 0x%02x %d; expected 0x%02x %d", | 198 | "read 0x%02x%02x; expected 0x%02x%02x", |
213 | zname(Z),id,sizeofR,ID_NUMBER,sizeof(real)); | 199 | zname(Z),id,sizeofR,ID_NUMBER,sizeof(real)); |
214 | } | 200 | } |
215 | f=LoadNumber(Z); | 201 | doLoadNumber(f,Z); |
216 | if (f!=tf) | 202 | if (f!=tf) |
217 | luaL_verror("unknown number representation in %s: " | 203 | luaL_verror("unknown number representation in %s: " |
218 | "read " NUMBER_FMT "; expected " NUMBER_FMT "", /* LUA_NUMBER */ | 204 | "read " NUMBER_FMT "; expected " NUMBER_FMT "", /* LUA_NUMBER */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lundump.h,v 1.6 1998/06/13 16:54:15 lhf Exp $ | 2 | ** $Id: lundump.h,v 1.7 1998/06/25 15:50:09 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 | */ |
@@ -14,6 +14,7 @@ TProtoFunc* luaU_undump1(ZIO* Z); /* load one chunk */ | |||
14 | 14 | ||
15 | #define SIGNATURE "Lua" | 15 | #define SIGNATURE "Lua" |
16 | #define VERSION 0x31 /* last format change was in 3.1 */ | 16 | #define VERSION 0x31 /* last format change was in 3.1 */ |
17 | #define VERSION0 0x31 /* last major change was in 3.1 */ | ||
17 | 18 | ||
18 | #define IsMain(f) (f->lineDefined==0) | 19 | #define IsMain(f) (f->lineDefined==0) |
19 | 20 | ||
@@ -46,12 +47,35 @@ TProtoFunc* luaU_undump1(ZIO* Z); /* load one chunk */ | |||
46 | * dump and undump routines. | 47 | * dump and undump routines. |
47 | */ | 48 | */ |
48 | 49 | ||
49 | #define ID_NUMBER ID_REAL8 | 50 | #ifndef ID_NUMBER |
51 | #define ID_NUMBER ID_NATIVE | ||
52 | #endif | ||
50 | 53 | ||
51 | #if 0 | 54 | #if 0 |
52 | #define ID_NUMBER ID_REAL4 | ||
53 | #define ID_NUMBER ID_INT4 | 55 | #define ID_NUMBER ID_INT4 |
56 | #define ID_NUMBER ID_REAL4 | ||
57 | #define ID_NUMBER ID_REAL8 | ||
54 | #define ID_NUMBER ID_NATIVE | 58 | #define ID_NUMBER ID_NATIVE |
55 | #endif | 59 | #endif |
56 | 60 | ||
57 | #endif | 61 | #endif |
62 | |||
63 | #if ID_NUMBER==ID_REAL4 | ||
64 | #define DumpNumber DumpFloat | ||
65 | #define LoadNumber LoadFloat | ||
66 | #define SIZEOF_NUMBER 4 | ||
67 | #elif ID_NUMBER==ID_REAL8 | ||
68 | #define DumpNumber DumpDouble | ||
69 | #define LoadNumber LoadDouble | ||
70 | #define SIZEOF_NUMBER 8 | ||
71 | #elif ID_NUMBER==ID_INT4 | ||
72 | #define DumpNumber DumpLong | ||
73 | #define LoadNumber LoadLong | ||
74 | #define SIZEOF_NUMBER 4 | ||
75 | #elif ID_NUMBER==ID_NATIVE | ||
76 | #define DumpNumber DumpNative | ||
77 | #define LoadNumber LoadNative | ||
78 | #define SIZEOF_NUMBER sizeof(real) | ||
79 | #else | ||
80 | #error bad ID_NUMBER | ||
81 | #endif | ||