mirror of https://github.com/rusefi/lua.git
uses ID_* constants
simplified signature checking loads local vars
This commit is contained in:
parent
870967ca77
commit
cec1ffb80b
55
undump.c
55
undump.c
|
@ -3,7 +3,7 @@
|
||||||
** load bytecodes from files
|
** load bytecodes from files
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_undump="$Id: undump.c,v 1.5 1996/02/26 19:44:17 lhf Exp lhf $";
|
char *rcs_undump="$Id: undump.c,v 1.6 1996/02/28 23:10:46 lhf Exp lhf $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -11,7 +11,7 @@ char *rcs_undump="$Id: undump.c,v 1.5 1996/02/26 19:44:17 lhf Exp lhf $";
|
||||||
|
|
||||||
static void warn(char *s) /* TODO: remove */
|
static void warn(char *s) /* TODO: remove */
|
||||||
{
|
{
|
||||||
fprintf(stderr,"luac: %s\n",s);
|
fprintf(stderr,"undump: %s\n",s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void panic(char *s) /* TODO: remove */
|
static void panic(char *s) /* TODO: remove */
|
||||||
|
@ -73,45 +73,67 @@ static void LoadFunction(FILE *D)
|
||||||
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; /* TODO: tf->marked=? */
|
p=Main->code+tf->marked;
|
||||||
c.tf=tf;
|
c.tf=tf;
|
||||||
*p++=c.m.c1; *p++=c.m.c2; *p++=c.m.c3; *p++=c.m.c4;
|
*p++=c.m.c1; *p++=c.m.c2; *p++=c.m.c3; *p++=c.m.c4;
|
||||||
lastF->next=tf; lastF=tf;
|
lastF=lastF->next=tf;
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
|
tf->marked=0; /* TODO: is this ok? */
|
||||||
|
#endif
|
||||||
tf->code=LoadBlock(tf->size,D);
|
tf->code=LoadBlock(tf->size,D);
|
||||||
while (1) /* unthread */
|
while (1) /* unthread */
|
||||||
{
|
{
|
||||||
int c=getc(D);
|
int c=getc(D);
|
||||||
if (c=='V')
|
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=='S')
|
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);
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void LoadSignature(FILE *D)
|
||||||
|
{
|
||||||
|
char *s=SIGNATURE;
|
||||||
|
while (*s!=0 && getc(D)==*s)
|
||||||
|
++s;
|
||||||
|
if (*s!=0) panic("bad signature");
|
||||||
|
}
|
||||||
|
|
||||||
static void LoadHeader(FILE *D) /* TODO: error handling */
|
static void LoadHeader(FILE *D) /* TODO: error handling */
|
||||||
{
|
{
|
||||||
char *s=LoadString(D);
|
|
||||||
Word w,tw=TEST_WORD;
|
Word w,tw=TEST_WORD;
|
||||||
float f,tf=TEST_FLOAT;
|
float f,tf=TEST_FLOAT;
|
||||||
if (strcmp(s,SIGNATURE)!=0) panic("bad signature");
|
LoadSignature(D);
|
||||||
luaI_free(s);
|
getc(D); /* skip version */
|
||||||
getc(D); /* skip version */
|
|
||||||
fread(&w,sizeof(w),1,D); /* a word for testing byte ordering */
|
fread(&w,sizeof(w),1,D); /* a word for testing byte ordering */
|
||||||
if (w!=tw) warn("different byte order");
|
if (w!=tw) warn("different byte order");
|
||||||
fread(&f,sizeof(f),1,D); /* a float for testing byte ordering */
|
fread(&f,sizeof(f),1,D); /* a float for testing byte ordering */
|
||||||
|
@ -124,7 +146,7 @@ static void LoadChunk(FILE *D)
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
int c=getc(D);
|
int c=getc(D);
|
||||||
if (c=='F') LoadFunction(D); else { ungetc(c,D); break; }
|
if (c==ID_FUN) LoadFunction(D); else { ungetc(c,D); break; }
|
||||||
}
|
}
|
||||||
#if 1
|
#if 1
|
||||||
{ /* TODO: run Main? */
|
{ /* TODO: run Main? */
|
||||||
|
@ -140,9 +162,12 @@ void luaI_undump(FILE *D)
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
int c=getc(D);
|
int c=getc(D);
|
||||||
if (c==ESC) LoadChunk(D); else
|
if (c==ID_CHUNK)
|
||||||
if (c==EOF) return; else
|
LoadChunk(D);
|
||||||
panic("not a lua binary file");
|
else if (c==EOF)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
panic("not a lua binary file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue