diff options
author | Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> | 1996-03-06 13:01:08 -0300 |
---|---|---|
committer | Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> | 1996-03-06 13:01:08 -0300 |
commit | 9a6cccb08c4701755787bfface1933cf052fd59a (patch) | |
tree | 71550ee9284d5f07a76e7342e35588a8964fe6dd | |
parent | b58225e93b32af07612c2aa1675f50961094d4e0 (diff) | |
download | lua-9a6cccb08c4701755787bfface1933cf052fd59a.tar.gz lua-9a6cccb08c4701755787bfface1933cf052fd59a.tar.bz2 lua-9a6cccb08c4701755787bfface1933cf052fd59a.zip |
removed support for local vars
-rw-r--r-- | undump.c | 62 |
1 files changed, 25 insertions, 37 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** load bytecodes from files | 3 | ** load bytecodes from files |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_undump="$Id: undump.c,v 1.7 1996/03/01 03:43:50 lhf Exp lhf $"; | 6 | char* rcs_undump="$Id: undump.c,v 1.8 1996/03/06 01:41:18 lhf Exp lhf $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <string.h> | 9 | #include <string.h> |
@@ -12,23 +12,23 @@ char *rcs_undump="$Id: undump.c,v 1.7 1996/03/01 03:43:50 lhf Exp lhf $"; | |||
12 | static int swapword=0; | 12 | static int swapword=0; |
13 | static int swapfloat=0; | 13 | static int swapfloat=0; |
14 | 14 | ||
15 | static void warn(char *s) /* TODO: remove */ | 15 | static void warn(char* s) /* TODO: remove */ |
16 | { | 16 | { |
17 | fprintf(stderr,"undump: %s\n",s); | 17 | fprintf(stderr,"undump: %s\n",s); |
18 | } | 18 | } |
19 | 19 | ||
20 | static void panic(char *s) /* TODO: remove */ | 20 | static void panic(char* s) /* TODO: remove */ |
21 | { | 21 | { |
22 | warn(s); | 22 | warn(s); |
23 | exit(1); | 23 | exit(1); |
24 | } | 24 | } |
25 | 25 | ||
26 | static void Unthread(Byte *code, int i, int v) | 26 | static void Unthread(Byte* code, int i, int v) |
27 | { | 27 | { |
28 | while (i!=0) | 28 | while (i!=0) |
29 | { | 29 | { |
30 | CodeWord c; | 30 | CodeWord c; |
31 | Byte *p=code+i; | 31 | Byte* p=code+i; |
32 | get_word(c,p); | 32 | get_word(c,p); |
33 | i=c.w; | 33 | i=c.w; |
34 | c.w=v; | 34 | c.w=v; |
@@ -37,38 +37,39 @@ static void Unthread(Byte *code, int i, int v) | |||
37 | } | 37 | } |
38 | } | 38 | } |
39 | 39 | ||
40 | static int LoadWord(FILE *D) | 40 | static int LoadWord(FILE* D) |
41 | { | 41 | { |
42 | Word w; | 42 | Word w; |
43 | fread(&w,sizeof(w),1,D); | 43 | fread(&w,sizeof(w),1,D); |
44 | if (swapword) | 44 | if (swapword) |
45 | { | 45 | { |
46 | Byte *p=&w; | 46 | Byte* p=&w; |
47 | Byte t; | 47 | Byte t; |
48 | t=p[0]; p[0]=p[1]; p[1]=t; | 48 | t=p[0]; p[0]=p[1]; p[1]=t; |
49 | } | 49 | } |
50 | return w; | 50 | return w; |
51 | } | 51 | } |
52 | 52 | ||
53 | static char* LoadBlock(int size, FILE *D) | 53 | static char* LoadBlock(int size, FILE* D) |
54 | { | 54 | { |
55 | char *b=luaI_malloc(size); | 55 | char* b=luaI_malloc(size); |
56 | fread(b,size,1,D); | 56 | fread(b,size,1,D); |
57 | return b; | 57 | return b; |
58 | } | 58 | } |
59 | 59 | ||
60 | static char* LoadString(FILE *D) | 60 | static char* LoadString(FILE* D) |
61 | { | 61 | { |
62 | return LoadBlock(LoadWord(D),D); | 62 | return LoadBlock(LoadWord(D),D); |
63 | } | 63 | } |
64 | 64 | ||
65 | static TFunc *Main=NULL; | 65 | static TFunc* Main=NULL; |
66 | static TFunc *lastF=NULL; | 66 | static TFunc* lastF=NULL; |
67 | 67 | ||
68 | static void LoadFunction(FILE *D) | 68 | static void LoadFunction(FILE* D) |
69 | { | 69 | { |
70 | TFunc *tf=new(TFunc); | 70 | TFunc* tf=new(TFunc); |
71 | tf->next=NULL; | 71 | tf->next=NULL; |
72 | tf->locvars=NULL; | ||
72 | tf->size=LoadWord(D); /* TODO: Long? */ | 73 | tf->size=LoadWord(D); /* TODO: Long? */ |
73 | tf->lineDefined=LoadWord(D); | 74 | tf->lineDefined=LoadWord(D); |
74 | if (IsMain(tf)) /* new main */ | 75 | if (IsMain(tf)) /* new main */ |
@@ -79,7 +80,7 @@ static void LoadFunction(FILE *D) | |||
79 | else /* fix PUSHFUNCTION */ | 80 | else /* fix PUSHFUNCTION */ |
80 | { | 81 | { |
81 | CodeCode c; | 82 | CodeCode c; |
82 | Byte *p; | 83 | Byte* p; |
83 | tf->marked=LoadWord(D); | 84 | tf->marked=LoadWord(D); |
84 | tf->fileName=Main->fileName; | 85 | tf->fileName=Main->fileName; |
85 | p=Main->code+tf->marked; | 86 | p=Main->code+tf->marked; |
@@ -98,30 +99,17 @@ static void LoadFunction(FILE *D) | |||
98 | if (c==ID_VAR) /* global var */ | 99 | if (c==ID_VAR) /* global var */ |
99 | { | 100 | { |
100 | int i=LoadWord(D); | 101 | int i=LoadWord(D); |
101 | char *s=LoadString(D); | 102 | char* s=LoadString(D); |
102 | int v=luaI_findsymbolbyname(s); /* TODO: free s? */ | 103 | int v=luaI_findsymbolbyname(s); /* TODO: free s? */ |
103 | Unthread(tf->code,i,v); | 104 | Unthread(tf->code,i,v); |
104 | } | 105 | } |
105 | else if (c==ID_STR) /* constant string */ | 106 | else if (c==ID_STR) /* constant string */ |
106 | { | 107 | { |
107 | int i=LoadWord(D); | 108 | int i=LoadWord(D); |
108 | char *s=LoadString(D); | 109 | char* s=LoadString(D); |
109 | int v=luaI_findconstantbyname(s); /* TODO: free s? */ | 110 | int v=luaI_findconstantbyname(s); /* TODO: free s? */ |
110 | Unthread(tf->code,i,v); | 111 | Unthread(tf->code,i,v); |
111 | } | 112 | } |
112 | else if (c==ID_LOC) /* local vars */ | ||
113 | { | ||
114 | int n=LoadWord(D); | ||
115 | LocVar *v; | ||
116 | if (n==0) continue; | ||
117 | tf->locvars=v=newvector(n,LocVar); | ||
118 | while (n--) | ||
119 | { | ||
120 | LocLoc(v)=LoadWord(D); | ||
121 | LoadString(D); /* TODO: how to save it? */ | ||
122 | ++v; | ||
123 | } | ||
124 | } | ||
125 | else | 113 | else |
126 | { | 114 | { |
127 | ungetc(c,D); | 115 | ungetc(c,D); |
@@ -130,15 +118,15 @@ static void LoadFunction(FILE *D) | |||
130 | } | 118 | } |
131 | } | 119 | } |
132 | 120 | ||
133 | static void LoadSignature(FILE *D) | 121 | static void LoadSignature(FILE* D) |
134 | { | 122 | { |
135 | char *s=SIGNATURE; | 123 | char* s=SIGNATURE; |
136 | while (*s!=0 && getc(D)==*s) | 124 | while (*s!=0 && getc(D)==*s) |
137 | ++s; | 125 | ++s; |
138 | if (*s!=0) panic("bad signature"); | 126 | if (*s!=0) panic("bad signature"); |
139 | } | 127 | } |
140 | 128 | ||
141 | static void LoadHeader(FILE *D) /* TODO: error handling */ | 129 | static void LoadHeader(FILE* D) /* TODO: error handling */ |
142 | { | 130 | { |
143 | Word w,tw=TEST_WORD; | 131 | Word w,tw=TEST_WORD; |
144 | float f,tf=TEST_FLOAT; | 132 | float f,tf=TEST_FLOAT; |
@@ -158,7 +146,7 @@ static void LoadHeader(FILE *D) /* TODO: error handling */ | |||
158 | } | 146 | } |
159 | } | 147 | } |
160 | 148 | ||
161 | static void LoadChunk(FILE *D) | 149 | static void LoadChunk(FILE* D) |
162 | { | 150 | { |
163 | LoadHeader(D); | 151 | LoadHeader(D); |
164 | while (1) | 152 | while (1) |
@@ -168,14 +156,14 @@ static void LoadChunk(FILE *D) | |||
168 | } | 156 | } |
169 | #if 1 | 157 | #if 1 |
170 | { /* TODO: run Main? */ | 158 | { /* TODO: run Main? */ |
171 | TFunc *tf; | 159 | TFunc* tf; |
172 | for (tf=Main; tf!=NULL; tf=tf->next) | 160 | for (tf=Main; tf!=NULL; tf=tf->next) |
173 | PrintFunction(tf); | 161 | PrintFunction(tf); |
174 | } | 162 | } |
175 | #endif | 163 | #endif |
176 | } | 164 | } |
177 | 165 | ||
178 | void luaI_undump(FILE *D) | 166 | void luaI_undump(FILE* D) |
179 | { | 167 | { |
180 | while (1) | 168 | while (1) |
181 | { | 169 | { |
@@ -192,7 +180,7 @@ void luaI_undump(FILE *D) | |||
192 | int main(int argc, char* argv[]) | 180 | int main(int argc, char* argv[]) |
193 | { | 181 | { |
194 | char* fn=(argc>1)? argv[1] : "luac.out"; | 182 | char* fn=(argc>1)? argv[1] : "luac.out"; |
195 | FILE *f=freopen(fn,"rb",stdin); | 183 | FILE* f=freopen(fn,"rb",stdin); |
196 | if (f==NULL) | 184 | if (f==NULL) |
197 | { | 185 | { |
198 | fprintf(stderr,"undump: cannot open "); | 186 | fprintf(stderr,"undump: cannot open "); |