aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-06-18 13:52:04 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-06-18 13:52:04 -0300
commit112c9d53ab47e77fd09d4ecb9b11d432ed906c88 (patch)
treef2fb14e67049257686b84ee369e1ecbebbe491be
parent07894514587e5cada05c5ea85ee714f85eec9127 (diff)
downloadlua-112c9d53ab47e77fd09d4ecb9b11d432ed906c88.tar.gz
lua-112c9d53ab47e77fd09d4ecb9b11d432ed906c88.tar.bz2
lua-112c9d53ab47e77fd09d4ecb9b11d432ed906c88.zip
new version by lhf
-rw-r--r--lundump.c21
-rw-r--r--lundump.h38
2 files changed, 32 insertions, 27 deletions
diff --git a/lundump.c b/lundump.c
index 37a53977..a5bd4a35 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,10 +1,11 @@
1/* 1/*
2** $Id: lundump.c,v 1.7 1998/03/05 15:45:08 lhf Exp lhf $ 2** $Id: lundump.c,v 1.9 1998/06/13 16:54:15 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
8#include "lauxlib.h" 9#include "lauxlib.h"
9#include "lfunc.h" 10#include "lfunc.h"
10#include "lmem.h" 11#include "lmem.h"
@@ -15,11 +16,7 @@
15#define LoadNative(t,D) LoadBlock(&t,sizeof(t),D) 16#define LoadNative(t,D) LoadBlock(&t,sizeof(t),D)
16 17
17/* LUA_NUMBER */ 18/* LUA_NUMBER */
18/* if you change the definition of real, make sure you set ID_NUMBER 19/* see comment in lundump.h */
19* accordingly lundump.h, specially if sizeof(long)!=4.
20* for types other than the ones listed below, you'll have to write your own
21* dump and undump routines.
22*/
23 20
24#if ID_NUMBER==ID_REAL4 21#if ID_NUMBER==ID_REAL4
25 #define LoadNumber LoadFloat 22 #define LoadNumber LoadFloat
@@ -65,20 +62,23 @@ static unsigned long LoadLong(ZIO* Z)
65 return (hi<<16)|lo; 62 return (hi<<16)|lo;
66} 63}
67 64
65#if ID_NUMBER==ID_REAL4
68/* LUA_NUMBER */ 66/* LUA_NUMBER */
69/* assumes sizeof(long)==4 and sizeof(float)==4 (IEEE) */ 67/* assumes sizeof(long)==4 and sizeof(float)==4 (IEEE) */
70static float LoadFloat(ZIO* Z) 68static float LoadFloat(ZIO* Z)
71{ 69{
72 long l=LoadLong(Z); 70 unsigned long l=LoadLong(Z);
73 float f=*(float*)&l; 71 float f=*(float*)&l;
74 return f; 72 return f;
75} 73}
74#endif
76 75
76#if ID_NUMBER==ID_REAL8
77/* LUA_NUMBER */ 77/* LUA_NUMBER */
78/* assumes sizeof(long)==4 and sizeof(double)==8 (IEEE) */ 78/* assumes sizeof(long)==4 and sizeof(double)==8 (IEEE) */
79static double LoadDouble(ZIO* Z) 79static double LoadDouble(ZIO* Z)
80{ 80{
81 long l[2]; 81 unsigned long l[2];
82 double f; 82 double f;
83 int x=1; 83 int x=1;
84 if (*(char*)&x==1) /* little-endian */ 84 if (*(char*)&x==1) /* little-endian */
@@ -94,10 +94,11 @@ static double LoadDouble(ZIO* Z)
94 f=*(double*)l; 94 f=*(double*)l;
95 return f; 95 return f;
96} 96}
97#endif
97 98
98static Byte* LoadCode(ZIO* Z) 99static Byte* LoadCode(ZIO* Z)
99{ 100{
100 long size=LoadLong(Z); 101 unsigned long size=LoadLong(Z);
101 unsigned int s=size; 102 unsigned int s=size;
102 void* b; 103 void* b;
103 if (s!=size) luaL_verror("code too long (%ld bytes) in %s",size,zname(Z)); 104 if (s!=size) luaL_verror("code too long (%ld bytes) in %s",size,zname(Z));
@@ -214,7 +215,7 @@ static void LoadHeader(ZIO* Z)
214 f=LoadNumber(Z); 215 f=LoadNumber(Z);
215 if (f!=tf) 216 if (f!=tf)
216 luaL_verror("unknown number representation in %s: " 217 luaL_verror("unknown number representation in %s: "
217 "read %g; expected %g", /* LUA_NUMBER */ 218 "read " NUMBER_FMT "; expected " NUMBER_FMT "", /* LUA_NUMBER */
218 zname(Z),(double)f,(double)tf); 219 zname(Z),(double)f,(double)tf);
219} 220}
220 221
diff --git a/lundump.h b/lundump.h
index 7e5b286c..d9bc8668 100644
--- a/lundump.h
+++ b/lundump.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.h,v 1.5 1998/02/06 20:05:39 lhf Exp lhf $ 2** $Id: lundump.h,v 1.6 1998/06/13 16:54:15 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*/
@@ -22,32 +22,36 @@ TProtoFunc* luaU_undump1(ZIO* Z); /* load one chunk */
22#define ID_STR 'S' 22#define ID_STR 'S'
23#define ID_FUN 'F' 23#define ID_FUN 'F'
24 24
25#define ID_INT4 'l' 25/* number representation */
26#define ID_REAL4 'f' 26#define ID_INT4 'l' /* 4-byte integers */
27#define ID_REAL8 'd' 27#define ID_REAL4 'f' /* 4-byte reals */
28#define ID_NATIVE '?' 28#define ID_REAL8 'd' /* 8-byte reals */
29#define ID_NATIVE '?' /* whatever your machine uses */
29 30
30/* 31/*
31* use a multiple of PI for testing number representation. 32* use a multiple of PI for testing number representation.
32* multiplying by 10E8 gives notrivial integer values. 33* multiplying by 1E8 gives notrivial integer values.
33*/ 34*/
34#define TEST_NUMBER 3.14159265358979323846E8 35#define TEST_NUMBER 3.14159265358979323846E8
35 36
36/* LUA_NUMBER */ 37/* LUA_NUMBER
37/* if you change the definition of real, make sure you set ID_NUMBER 38* choose one below for the number representation in precompiled chunks.
38* accordingly, specially if sizeof(long)!=4. 39* the default is ID_REAL8 because the default for LUA_NUM_TYPE is double.
40* if your machine does not use IEEE 754, use ID_NATIVE.
41* the next version will support conversion to/from IEEE 754.
42*
43* if you change LUA_NUM_TYPE, make sure you set ID_NUMBER accordingly,
44* specially if sizeof(long)!=4.
39* for types other than the ones listed below, you'll have to write your own 45* for types other than the ones listed below, you'll have to write your own
40* dump and undump routines. 46* dump and undump routines.
41*/ 47*/
42 48
43#if real==float 49#define ID_NUMBER ID_REAL8
44 #define ID_NUMBER ID_REAL4 50
45#elif real==double 51#if 0
46 #define ID_NUMBER ID_REAL8 52#define ID_NUMBER ID_REAL4
47#elif real==long 53#define ID_NUMBER ID_INT4
48 #define ID_NUMBER ID_INT4 54#define ID_NUMBER ID_NATIVE
49#else
50 #define ID_NUMBER ID_NATIVE
51#endif 55#endif
52 56
53#endif 57#endif