diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-06-18 13:52:04 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-06-18 13:52:04 -0300 |
commit | 112c9d53ab47e77fd09d4ecb9b11d432ed906c88 (patch) | |
tree | f2fb14e67049257686b84ee369e1ecbebbe491be /lundump.c | |
parent | 07894514587e5cada05c5ea85ee714f85eec9127 (diff) | |
download | lua-112c9d53ab47e77fd09d4ecb9b11d432ed906c88.tar.gz lua-112c9d53ab47e77fd09d4ecb9b11d432ed906c88.tar.bz2 lua-112c9d53ab47e77fd09d4ecb9b11d432ed906c88.zip |
new version by lhf
Diffstat (limited to 'lundump.c')
-rw-r--r-- | lundump.c | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -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) */ |
70 | static float LoadFloat(ZIO* Z) | 68 | static 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) */ |
79 | static double LoadDouble(ZIO* Z) | 79 | static 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 | ||
98 | static Byte* LoadCode(ZIO* Z) | 99 | static 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 | ||