aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-06-25 13:48:44 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-06-25 13:48:44 -0300
commit07008b5d45da78180c1a0513d63367b7bc228bf4 (patch)
treeb49b068a0a9cc6f8d43994e9c5d0039605774308
parent8f31eda6495763f9e3de77747ef0b3c74e891b10 (diff)
downloadlua-07008b5d45da78180c1a0513d63367b7bc228bf4.tar.gz
lua-07008b5d45da78180c1a0513d63367b7bc228bf4.tar.bz2
lua-07008b5d45da78180c1a0513d63367b7bc228bf4.zip
details (by lhf)
-rw-r--r--lundump.c36
-rw-r--r--lundump.h30
2 files changed, 38 insertions, 28 deletions
diff --git a/lundump.c b/lundump.c
index a5bd4a35..ed4bd19c 100644
--- a/lundump.c
+++ b/lundump.c
@@ -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
33static void unexpectedEOZ(ZIO* Z) 23static 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 */
diff --git a/lundump.h b/lundump.h
index d9bc8668..e9014d7b 100644
--- a/lundump.h
+++ b/lundump.h
@@ -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