removed support for local vars

This commit is contained in:
Luiz Henrique de Figueiredo 1996-03-06 13:01:08 -03:00
parent b58225e93b
commit 9a6cccb08c
1 changed files with 25 additions and 37 deletions

View File

@ -3,7 +3,7 @@
** load bytecodes from files ** load bytecodes from files
*/ */
char *rcs_undump="$Id: undump.c,v 1.7 1996/03/01 03:43:50 lhf Exp lhf $"; char* rcs_undump="$Id: undump.c,v 1.8 1996/03/06 01:41:18 lhf Exp lhf $";
#include <stdio.h> #include <stdio.h>
#include <string.h> #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 $";
static int swapword=0; static int swapword=0;
static int swapfloat=0; static int swapfloat=0;
static void warn(char *s) /* TODO: remove */ static void warn(char* s) /* TODO: remove */
{ {
fprintf(stderr,"undump: %s\n",s); fprintf(stderr,"undump: %s\n",s);
} }
static void panic(char *s) /* TODO: remove */ static void panic(char* s) /* TODO: remove */
{ {
warn(s); warn(s);
exit(1); exit(1);
} }
static void Unthread(Byte *code, int i, int v) static void Unthread(Byte* code, int i, int v)
{ {
while (i!=0) while (i!=0)
{ {
CodeWord c; CodeWord c;
Byte *p=code+i; Byte* p=code+i;
get_word(c,p); get_word(c,p);
i=c.w; i=c.w;
c.w=v; c.w=v;
@ -37,38 +37,39 @@ static void Unthread(Byte *code, int i, int v)
} }
} }
static int LoadWord(FILE *D) static int LoadWord(FILE* D)
{ {
Word w; Word w;
fread(&w,sizeof(w),1,D); fread(&w,sizeof(w),1,D);
if (swapword) if (swapword)
{ {
Byte *p=&w; Byte* p=&w;
Byte t; Byte t;
t=p[0]; p[0]=p[1]; p[1]=t; t=p[0]; p[0]=p[1]; p[1]=t;
} }
return w; return w;
} }
static char* LoadBlock(int size, FILE *D) static char* LoadBlock(int size, FILE* D)
{ {
char *b=luaI_malloc(size); char* b=luaI_malloc(size);
fread(b,size,1,D); fread(b,size,1,D);
return b; return b;
} }
static char* LoadString(FILE *D) static char* LoadString(FILE* D)
{ {
return LoadBlock(LoadWord(D),D); return LoadBlock(LoadWord(D),D);
} }
static TFunc *Main=NULL; static TFunc* Main=NULL;
static TFunc *lastF=NULL; static TFunc* lastF=NULL;
static void LoadFunction(FILE *D) static void LoadFunction(FILE* D)
{ {
TFunc *tf=new(TFunc); TFunc* tf=new(TFunc);
tf->next=NULL; tf->next=NULL;
tf->locvars=NULL;
tf->size=LoadWord(D); /* TODO: Long? */ tf->size=LoadWord(D); /* TODO: Long? */
tf->lineDefined=LoadWord(D); tf->lineDefined=LoadWord(D);
if (IsMain(tf)) /* new main */ if (IsMain(tf)) /* new main */
@ -79,7 +80,7 @@ static void LoadFunction(FILE *D)
else /* fix PUSHFUNCTION */ else /* fix PUSHFUNCTION */
{ {
CodeCode c; CodeCode c;
Byte *p; Byte* p;
tf->marked=LoadWord(D); tf->marked=LoadWord(D);
tf->fileName=Main->fileName; tf->fileName=Main->fileName;
p=Main->code+tf->marked; p=Main->code+tf->marked;
@ -98,30 +99,17 @@ static void LoadFunction(FILE *D)
if (c==ID_VAR) /* global var */ if (c==ID_VAR) /* global var */
{ {
int i=LoadWord(D); int i=LoadWord(D);
char *s=LoadString(D); char* s=LoadString(D);
int v=luaI_findsymbolbyname(s); /* TODO: free s? */ int v=luaI_findsymbolbyname(s); /* TODO: free s? */
Unthread(tf->code,i,v); Unthread(tf->code,i,v);
} }
else if (c==ID_STR) /* constant string */ else if (c==ID_STR) /* constant string */
{ {
int i=LoadWord(D); int i=LoadWord(D);
char *s=LoadString(D); char* s=LoadString(D);
int v=luaI_findconstantbyname(s); /* TODO: free s? */ int v=luaI_findconstantbyname(s); /* TODO: free s? */
Unthread(tf->code,i,v); Unthread(tf->code,i,v);
} }
else if (c==ID_LOC) /* local vars */
{
int n=LoadWord(D);
LocVar *v;
if (n==0) continue;
tf->locvars=v=newvector(n,LocVar);
while (n--)
{
LocLoc(v)=LoadWord(D);
LoadString(D); /* TODO: how to save it? */
++v;
}
}
else else
{ {
ungetc(c,D); ungetc(c,D);
@ -130,15 +118,15 @@ static void LoadFunction(FILE *D)
} }
} }
static void LoadSignature(FILE *D) static void LoadSignature(FILE* D)
{ {
char *s=SIGNATURE; char* s=SIGNATURE;
while (*s!=0 && getc(D)==*s) while (*s!=0 && getc(D)==*s)
++s; ++s;
if (*s!=0) panic("bad signature"); if (*s!=0) panic("bad signature");
} }
static void LoadHeader(FILE *D) /* TODO: error handling */ static void LoadHeader(FILE* D) /* TODO: error handling */
{ {
Word w,tw=TEST_WORD; Word w,tw=TEST_WORD;
float f,tf=TEST_FLOAT; float f,tf=TEST_FLOAT;
@ -158,7 +146,7 @@ static void LoadHeader(FILE *D) /* TODO: error handling */
} }
} }
static void LoadChunk(FILE *D) static void LoadChunk(FILE* D)
{ {
LoadHeader(D); LoadHeader(D);
while (1) while (1)
@ -168,14 +156,14 @@ static void LoadChunk(FILE *D)
} }
#if 1 #if 1
{ /* TODO: run Main? */ { /* TODO: run Main? */
TFunc *tf; TFunc* tf;
for (tf=Main; tf!=NULL; tf=tf->next) for (tf=Main; tf!=NULL; tf=tf->next)
PrintFunction(tf); PrintFunction(tf);
} }
#endif #endif
} }
void luaI_undump(FILE *D) void luaI_undump(FILE* D)
{ {
while (1) while (1)
{ {
@ -192,7 +180,7 @@ void luaI_undump(FILE *D)
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
char* fn=(argc>1)? argv[1] : "luac.out"; char* fn=(argc>1)? argv[1] : "luac.out";
FILE *f=freopen(fn,"rb",stdin); FILE* f=freopen(fn,"rb",stdin);
if (f==NULL) if (f==NULL)
{ {
fprintf(stderr,"undump: cannot open "); fprintf(stderr,"undump: cannot open ");