aboutsummaryrefslogtreecommitdiff
path: root/lundump.c
diff options
context:
space:
mode:
Diffstat (limited to 'lundump.c')
-rw-r--r--lundump.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/lundump.c b/lundump.c
index 7aa0a93d..3dd01ba4 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 1.26 2000/02/17 19:17:44 lhf Exp lhf $ 2** $Id: lundump.c,v 1.18 2000/03/03 14:58:26 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*/
@@ -50,7 +50,7 @@ static unsigned long LoadLong (lua_State* L, ZIO* Z)
50 return (hi<<16)|lo; 50 return (hi<<16)|lo;
51} 51}
52 52
53static real LoadNumber (lua_State* L, ZIO* Z) 53static Number LoadNumber (lua_State* L, ZIO* Z)
54{ 54{
55 char b[256]; 55 char b[256];
56 int size=ezgetc(L,Z); 56 int size=ezgetc(L,Z);
@@ -67,15 +67,15 @@ static int LoadInt (lua_State* L, ZIO* Z, const char* message)
67 return i; 67 return i;
68} 68}
69 69
70static void LoadCode (lua_State* L, TProtoFunc* tf, ZIO* Z) 70static void LoadCode (lua_State* L, Proto* tf, ZIO* Z)
71{ 71{
72 int size=LoadInt(L,Z,"code too long (%lu bytes) in %.255s"); 72 int size=LoadInt(L,Z,"code too long (%lu bytes) in %.255s");
73 tf->code=luaM_newvector(L,size,Instruction); 73 tf->code=luaM_newvector(L,size,Instruction);
74 LoadBlock(L,tf->code,size*sizeof(tf->code[0]),Z); 74 LoadBlock(L,tf->code,size*sizeof(tf->code[0]),Z);
75 if (tf->code[size-1]!=ENDCODE) luaL_verror(L,"bad code in %.255s",zname(Z)); 75 if (tf->code[size-1]!=OP_END) luaL_verror(L,"bad code in %.255s",zname(Z));
76} 76}
77 77
78static TaggedString* LoadString (lua_State* L, ZIO* Z) 78static TString* LoadString (lua_State* L, ZIO* Z)
79{ 79{
80 long size=LoadLong(L,Z); 80 long size=LoadLong(L,Z);
81 if (size==0) 81 if (size==0)
@@ -88,7 +88,7 @@ static TaggedString* LoadString (lua_State* L, ZIO* Z)
88 } 88 }
89} 89}
90 90
91static void LoadLocals (lua_State* L, TProtoFunc* tf, ZIO* Z) 91static void LoadLocals (lua_State* L, Proto* tf, ZIO* Z)
92{ 92{
93 int i,n=LoadInt(L,Z,"too many locals (%lu) in %.255s"); 93 int i,n=LoadInt(L,Z,"too many locals (%lu) in %.255s");
94 if (n==0) return; 94 if (n==0) return;
@@ -102,21 +102,21 @@ static void LoadLocals (lua_State* L, TProtoFunc* tf, ZIO* Z)
102 tf->locvars[i].varname=NULL; 102 tf->locvars[i].varname=NULL;
103} 103}
104 104
105static TProtoFunc* LoadFunction (lua_State* L, ZIO* Z, int native); 105static Proto* LoadFunction (lua_State* L, ZIO* Z, int native);
106 106
107static void LoadConstants (lua_State* L, TProtoFunc* tf, ZIO* Z, int native) 107static void LoadConstants (lua_State* L, Proto* tf, ZIO* Z, int native)
108{ 108{
109 int i,n; 109 int i,n;
110 tf->nkstr=n=LoadInt(L,Z,"too many strings (%lu) in %.255s"); 110 tf->nkstr=n=LoadInt(L,Z,"too many strings (%lu) in %.255s");
111 if (n>0) 111 if (n>0)
112 { 112 {
113 tf->kstr=luaM_newvector(L,n,TaggedString*); 113 tf->kstr=luaM_newvector(L,n,TString*);
114 for (i=0; i<n; i++) tf->kstr[i]=LoadString(L,Z); 114 for (i=0; i<n; i++) tf->kstr[i]=LoadString(L,Z);
115 } 115 }
116 tf->nknum=n=LoadInt(L,Z,"too many numbers (%lu) in %.255s"); 116 tf->nknum=n=LoadInt(L,Z,"too many numbers (%lu) in %.255s");
117 if (n>0) 117 if (n>0)
118 { 118 {
119 tf->knum=luaM_newvector(L,n,real); 119 tf->knum=luaM_newvector(L,n,Number);
120 if (native) 120 if (native)
121 LoadBlock(L,tf->knum,n*sizeof(tf->knum[0]),Z); 121 LoadBlock(L,tf->knum,n*sizeof(tf->knum[0]),Z);
122 else 122 else
@@ -125,14 +125,14 @@ static void LoadConstants (lua_State* L, TProtoFunc* tf, ZIO* Z, int native)
125 tf->nkproto=n=LoadInt(L,Z,"too many functions (%lu) in %.255s"); 125 tf->nkproto=n=LoadInt(L,Z,"too many functions (%lu) in %.255s");
126 if (n>0) 126 if (n>0)
127 { 127 {
128 tf->kproto=luaM_newvector(L,n,TProtoFunc*); 128 tf->kproto=luaM_newvector(L,n,Proto*);
129 for (i=0; i<n; i++) tf->kproto[i]=LoadFunction(L,Z,native); 129 for (i=0; i<n; i++) tf->kproto[i]=LoadFunction(L,Z,native);
130 } 130 }
131} 131}
132 132
133static TProtoFunc* LoadFunction (lua_State* L, ZIO* Z, int native) 133static Proto* LoadFunction (lua_State* L, ZIO* Z, int native)
134{ 134{
135 TProtoFunc* tf=luaF_newproto(L); 135 Proto* tf=luaF_newproto(L);
136 tf->lineDefined=LoadInt(L,Z,"lineDefined too large (%lu) in %.255s"); 136 tf->lineDefined=LoadInt(L,Z,"lineDefined too large (%lu) in %.255s");
137 tf->source=LoadString(L,Z); 137 tf->source=LoadString(L,Z);
138 if (tf->source==NULL) tf->source=luaS_new(L,zname(Z)); 138 if (tf->source==NULL) tf->source=luaS_new(L,zname(Z));
@@ -172,12 +172,12 @@ static int LoadHeader (lua_State* L, ZIO* Z)
172 native=(sizeofR!=0); 172 native=(sizeofR!=0);
173 if (native) /* test number representation */ 173 if (native) /* test number representation */
174 { 174 {
175 if (sizeofR!=sizeof(real)) 175 if (sizeofR!=sizeof(Number))
176 luaL_verror(L,"unknown number size in %.255s: read %d; expected %d", 176 luaL_verror(L,"unknown number size in %.255s: read %d; expected %d",
177 zname(Z),sizeofR,(int)sizeof(real)); 177 zname(Z),sizeofR,(int)sizeof(Number));
178 else 178 else
179 { 179 {
180 real f=0,tf=TEST_NUMBER; 180 Number f=0,tf=TEST_NUMBER;
181 LoadBlock(L,&f,sizeof(f),Z); 181 LoadBlock(L,&f,sizeof(f),Z);
182 if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */ 182 if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */
183 luaL_verror(L,"unknown number format in %.255s: " 183 luaL_verror(L,"unknown number format in %.255s: "
@@ -188,7 +188,7 @@ static int LoadHeader (lua_State* L, ZIO* Z)
188 return native; 188 return native;
189} 189}
190 190
191static TProtoFunc* LoadChunk (lua_State* L, ZIO* Z) 191static Proto* LoadChunk (lua_State* L, ZIO* Z)
192{ 192{
193 return LoadFunction(L,Z,LoadHeader(L,Z)); 193 return LoadFunction(L,Z,LoadHeader(L,Z));
194} 194}
@@ -197,7 +197,7 @@ static TProtoFunc* LoadChunk (lua_State* L, ZIO* Z)
197** load one chunk from a file or buffer 197** load one chunk from a file or buffer
198** return main if ok and NULL at EOF 198** return main if ok and NULL at EOF
199*/ 199*/
200TProtoFunc* luaU_undump1 (lua_State* L, ZIO* Z) 200Proto* luaU_undump1 (lua_State* L, ZIO* Z)
201{ 201{
202 int c=zgetc(Z); 202 int c=zgetc(Z);
203 if (c==ID_CHUNK) 203 if (c==ID_CHUNK)