summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--undump.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/undump.c b/undump.c
index cf96a784..3d7f3fe6 100644
--- a/undump.c
+++ b/undump.c
@@ -3,7 +3,7 @@
3** load bytecodes from files 3** load bytecodes from files
4*/ 4*/
5 5
6char *rcs_undump="$Id: undump.c,v 1.2 1996/02/23 22:00:26 lhf Exp lhf $"; 6char *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
57static TFunc *Main=NULL; 57static TFunc *Main=NULL;
58static TFunc *lastF=NULL;
58 59
59static void LoadFunction(FILE *D) 60static 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 {
95printf("tf=%p\n",tf);
96PrintFunction(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 }
125PrintFunction(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
128void Undump(FILE *D) 133void luaI_undump(FILE *D)
129{ 134{
130 while (1) 135 while (1)
131 { 136 {
@@ -138,6 +143,6 @@ void Undump(FILE *D)
138 143
139int main(int argc, char* argv[]) 144int main(int argc, char* argv[])
140{ 145{
141 Undump(stdin); 146 luaI_undump(stdin);
142 return 0; 147 return 0;
143} 148}