diff options
-rw-r--r-- | undump.c | 19 |
1 files changed, 12 insertions, 7 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.2 1996/02/23 22:00:26 lhf Exp lhf $"; | 6 | char *rcs_undump="$Id: undump.c,v 1.3 1996/02/24 03:46:57 lhf Exp lhf $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <string.h> | 9 | #include <string.h> |
@@ -55,6 +55,7 @@ static char* LoadString(FILE *D) | |||
55 | } | 55 | } |
56 | 56 | ||
57 | static TFunc *Main=NULL; | 57 | static TFunc *Main=NULL; |
58 | static TFunc *lastF=NULL; | ||
58 | 59 | ||
59 | static void LoadFunction(FILE *D) | 60 | static void LoadFunction(FILE *D) |
60 | { | 61 | { |
@@ -64,14 +65,16 @@ static void LoadFunction(FILE *D) | |||
64 | tf->lineDefined=LoadWord(D); | 65 | tf->lineDefined=LoadWord(D); |
65 | tf->fileName=LoadString(D); | 66 | tf->fileName=LoadString(D); |
66 | tf->code=LoadBlock(tf->size,D); | 67 | tf->code=LoadBlock(tf->size,D); |
68 | tf->next=NULL; | ||
67 | if (tf->lineDefined==0) /* new main */ | 69 | if (tf->lineDefined==0) /* new main */ |
68 | Main=tf; | 70 | Main=lastF=tf; |
69 | else /* fix PUSHFUNCTION */ | 71 | else /* fix PUSHFUNCTION */ |
70 | { | 72 | { |
71 | CodeCode c; | 73 | CodeCode c; |
72 | Byte *p=Main->code+tf->marked; /* TODO: tf->marked=? */ | 74 | Byte *p=Main->code+tf->marked; /* TODO: tf->marked=? */ |
73 | c.tf=tf; | 75 | c.tf=tf; |
74 | *p++=c.m.c1; *p++=c.m.c2; *p++=c.m.c3; *p++=c.m.c4; | 76 | *p++=c.m.c1; *p++=c.m.c2; *p++=c.m.c3; *p++=c.m.c4; |
77 | lastF->next=tf; lastF=tf; | ||
75 | } | 78 | } |
76 | while (1) /* unthread */ | 79 | while (1) /* unthread */ |
77 | { | 80 | { |
@@ -92,8 +95,6 @@ static void LoadFunction(FILE *D) | |||
92 | } | 95 | } |
93 | else | 96 | else |
94 | { | 97 | { |
95 | printf("tf=%p\n",tf); | ||
96 | PrintFunction(tf); /* TODO: remove */ | ||
97 | ungetc(c,D); | 98 | ungetc(c,D); |
98 | return; | 99 | return; |
99 | } | 100 | } |
@@ -122,10 +123,14 @@ static void LoadChunk(FILE *D) | |||
122 | int c=getc(D); | 123 | int c=getc(D); |
123 | if (c=='F') LoadFunction(D); else { ungetc(c,D); break; } | 124 | if (c=='F') LoadFunction(D); else { ungetc(c,D); break; } |
124 | } | 125 | } |
125 | PrintFunction(Main); /* TODO: run Main */ | 126 | { /* TODO: run Main? */ |
127 | TFunc *tf; | ||
128 | for (tf=Main; tf!=NULL; tf=tf->next) | ||
129 | PrintFunction(tf); | ||
130 | } | ||
126 | } | 131 | } |
127 | 132 | ||
128 | void Undump(FILE *D) | 133 | void luaI_undump(FILE *D) |
129 | { | 134 | { |
130 | while (1) | 135 | while (1) |
131 | { | 136 | { |
@@ -138,6 +143,6 @@ void Undump(FILE *D) | |||
138 | 143 | ||
139 | int main(int argc, char* argv[]) | 144 | int main(int argc, char* argv[]) |
140 | { | 145 | { |
141 | Undump(stdin); | 146 | luaI_undump(stdin); |
142 | return 0; | 147 | return 0; |
143 | } | 148 | } |