diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-23 14:17:25 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-23 14:17:25 -0300 |
commit | 39b79783297bee79db9853b63d199e120a009a8f (patch) | |
tree | c738c621c4c28d8822c2f785400786301985273b /lundump.c | |
parent | d164e2294f73d8e69f00d95a66014514b2dd0ec0 (diff) | |
download | lua-39b79783297bee79db9853b63d199e120a009a8f.tar.gz lua-39b79783297bee79db9853b63d199e120a009a8f.tar.bz2 lua-39b79783297bee79db9853b63d199e120a009a8f.zip |
first (big) step to support wide chars
Diffstat (limited to 'lundump.c')
-rw-r--r-- | lundump.c | 50 |
1 files changed, 25 insertions, 25 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lundump.c,v 1.37 2000/12/28 12:59:41 roberto Exp roberto $ | 2 | ** $Id: lundump.c,v 1.38 2001/01/15 16:13:24 roberto Exp roberto $ |
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,15 +15,15 @@ | |||
15 | 15 | ||
16 | #define LoadByte ezgetc | 16 | #define LoadByte ezgetc |
17 | 17 | ||
18 | static const char* ZNAME (ZIO* Z) | 18 | static const l_char* ZNAME (ZIO* Z) |
19 | { | 19 | { |
20 | const char* s=zname(Z); | 20 | const l_char* s=zname(Z); |
21 | return (*s=='@') ? s+1 : s; | 21 | return (*s==l_c('@')) ? s+1 : s; |
22 | } | 22 | } |
23 | 23 | ||
24 | static void unexpectedEOZ (lua_State* L, ZIO* Z) | 24 | static void unexpectedEOZ (lua_State* L, ZIO* Z) |
25 | { | 25 | { |
26 | luaO_verror(L,"unexpected end of file in `%.99s'",ZNAME(Z)); | 26 | luaO_verror(L,l_s("unexpected end of file in `%.99s'"),ZNAME(Z)); |
27 | } | 27 | } |
28 | 28 | ||
29 | static int ezgetc (lua_State* L, ZIO* Z) | 29 | static int ezgetc (lua_State* L, ZIO* Z) |
@@ -43,9 +43,9 @@ static void LoadBlock (lua_State* L, void* b, size_t size, ZIO* Z, int swap) | |||
43 | { | 43 | { |
44 | if (swap) | 44 | if (swap) |
45 | { | 45 | { |
46 | char *p=(char *) b+size-1; | 46 | l_char *p=(l_char *) b+size-1; |
47 | int n=size; | 47 | int n=size; |
48 | while (n--) *p--=(char)ezgetc(L,Z); | 48 | while (n--) *p--=(l_char)ezgetc(L,Z); |
49 | } | 49 | } |
50 | else | 50 | else |
51 | ezread(L,Z,b,size); | 51 | ezread(L,Z,b,size); |
@@ -55,12 +55,12 @@ static void LoadVector (lua_State* L, void* b, int m, size_t size, ZIO* Z, int s | |||
55 | { | 55 | { |
56 | if (swap) | 56 | if (swap) |
57 | { | 57 | { |
58 | char *q=(char *) b; | 58 | l_char *q=(l_char *) b; |
59 | while (m--) | 59 | while (m--) |
60 | { | 60 | { |
61 | char *p=q+size-1; | 61 | l_char *p=q+size-1; |
62 | int n=size; | 62 | int n=size; |
63 | while (n--) *p--=(char)ezgetc(L,Z); | 63 | while (n--) *p--=(l_char)ezgetc(L,Z); |
64 | q+=size; | 64 | q+=size; |
65 | } | 65 | } |
66 | } | 66 | } |
@@ -96,9 +96,9 @@ static TString* LoadString (lua_State* L, ZIO* Z, int swap) | |||
96 | return NULL; | 96 | return NULL; |
97 | else | 97 | else |
98 | { | 98 | { |
99 | char* s=luaO_openspace(L,size); | 99 | l_char* s=luaO_openspace(L,size); |
100 | LoadBlock(L,s,size,Z,0); | 100 | LoadBlock(L,s,size,Z,0); |
101 | return luaS_newlstr(L,s,size-1); /* remove trailing '\0' */ | 101 | return luaS_newlstr(L,s,size-1); /* remove trailing l_c('\0') */ |
102 | } | 102 | } |
103 | } | 103 | } |
104 | 104 | ||
@@ -171,18 +171,18 @@ static Proto* LoadFunction (lua_State* L, ZIO* Z, int swap) | |||
171 | 171 | ||
172 | static void LoadSignature (lua_State* L, ZIO* Z) | 172 | static void LoadSignature (lua_State* L, ZIO* Z) |
173 | { | 173 | { |
174 | const char* s=SIGNATURE; | 174 | const l_char* s=SIGNATURE; |
175 | while (*s!=0 && ezgetc(L,Z)==*s) | 175 | while (*s!=0 && ezgetc(L,Z)==*s) |
176 | ++s; | 176 | ++s; |
177 | if (*s!=0) luaO_verror(L,"bad signature in `%.99s'",ZNAME(Z)); | 177 | if (*s!=0) luaO_verror(L,l_s("bad signature in `%.99s'"),ZNAME(Z)); |
178 | } | 178 | } |
179 | 179 | ||
180 | static void TestSize (lua_State* L, int s, const char* what, ZIO* Z) | 180 | static void TestSize (lua_State* L, int s, const l_char* what, ZIO* Z) |
181 | { | 181 | { |
182 | int r=ezgetc(L,Z); | 182 | int r=ezgetc(L,Z); |
183 | if (r!=s) | 183 | if (r!=s) |
184 | luaO_verror(L,"virtual machine mismatch in `%.99s':\n" | 184 | luaO_verror(L,l_s("virtual machine mismatch in `%.99s':\n") |
185 | " %.20s is %d but read %d",ZNAME(Z),what,s,r); | 185 | l_s(" %.20s is %d but read %d"),ZNAME(Z),what,s,r); |
186 | } | 186 | } |
187 | 187 | ||
188 | #define TESTSIZE(s) TestSize(L,s,#s,Z) | 188 | #define TESTSIZE(s) TestSize(L,s,#s,Z) |
@@ -195,12 +195,12 @@ static int LoadHeader (lua_State* L, ZIO* Z) | |||
195 | LoadSignature(L,Z); | 195 | LoadSignature(L,Z); |
196 | version=ezgetc(L,Z); | 196 | version=ezgetc(L,Z); |
197 | if (version>VERSION) | 197 | if (version>VERSION) |
198 | luaO_verror(L,"`%.99s' too new:\n" | 198 | luaO_verror(L,l_s("`%.99s' too new:\n") |
199 | " read version %d.%d; expected at most %d.%d", | 199 | l_s(" read version %d.%d; expected at most %d.%d"), |
200 | ZNAME(Z),V(version),V(VERSION)); | 200 | ZNAME(Z),V(version),V(VERSION)); |
201 | if (version<VERSION0) /* check last major change */ | 201 | if (version<VERSION0) /* check last major change */ |
202 | luaO_verror(L,"`%.99s' too old:\n" | 202 | luaO_verror(L,l_s("`%.99s' too old:\n") |
203 | " read version %d.%d; expected at least %d.%d", | 203 | l_s(" read version %d.%d; expected at least %d.%d"), |
204 | ZNAME(Z),V(version),V(VERSION)); | 204 | ZNAME(Z),V(version),V(VERSION)); |
205 | swap=(luaU_endianess()!=ezgetc(L,Z)); /* need to swap bytes? */ | 205 | swap=(luaU_endianess()!=ezgetc(L,Z)); /* need to swap bytes? */ |
206 | TESTSIZE(sizeof(int)); | 206 | TESTSIZE(sizeof(int)); |
@@ -212,8 +212,8 @@ static int LoadHeader (lua_State* L, ZIO* Z) | |||
212 | TESTSIZE(sizeof(lua_Number)); | 212 | TESTSIZE(sizeof(lua_Number)); |
213 | f=LoadNumber(L,Z,swap); | 213 | f=LoadNumber(L,Z,swap); |
214 | if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */ | 214 | if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */ |
215 | luaO_verror(L,"unknown number format in `%.99s':\n" | 215 | luaO_verror(L,l_s("unknown number format in `%.99s':\n") |
216 | " read " NUMBER_FMT "; expected " NUMBER_FMT, ZNAME(Z),f,tf); | 216 | l_s(" read ") NUMBER_FMT l_s("; expected ") NUMBER_FMT, ZNAME(Z),f,tf); |
217 | return swap; | 217 | return swap; |
218 | } | 218 | } |
219 | 219 | ||
@@ -234,7 +234,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z) | |||
234 | tf=LoadChunk(L,Z); | 234 | tf=LoadChunk(L,Z); |
235 | c=zgetc(Z); | 235 | c=zgetc(Z); |
236 | if (c!=EOZ) | 236 | if (c!=EOZ) |
237 | luaO_verror(L,"`%.99s' apparently contains more than one chunk",ZNAME(Z)); | 237 | luaO_verror(L,l_s("`%.99s' apparently contains more than one chunk"),ZNAME(Z)); |
238 | return tf; | 238 | return tf; |
239 | } | 239 | } |
240 | 240 | ||
@@ -244,5 +244,5 @@ Proto* luaU_undump (lua_State* L, ZIO* Z) | |||
244 | int luaU_endianess (void) | 244 | int luaU_endianess (void) |
245 | { | 245 | { |
246 | int x=1; | 246 | int x=1; |
247 | return *(char*)&x; | 247 | return *(l_char*)&x; |
248 | } | 248 | } |