diff options
Diffstat (limited to 'src/luac')
-rw-r--r-- | src/luac/dump.c | 47 | ||||
-rw-r--r-- | src/luac/luac.c | 5 | ||||
-rw-r--r-- | src/luac/print.c | 43 |
3 files changed, 49 insertions, 46 deletions
diff --git a/src/luac/dump.c b/src/luac/dump.c index 22db5e36..656cc293 100644 --- a/src/luac/dump.c +++ b/src/luac/dump.c @@ -3,9 +3,10 @@ ** thread and save bytecodes to file */ -char* rcs_dump="$Id: dump.c,v 1.12 1996/03/12 20:00:03 lhf Exp $"; +char* rcs_dump="$Id: dump.c,v 1.17 1996/11/18 11:18:29 lhf Exp $"; #include <stdio.h> +#include <stdlib.h> #include <string.h> #include "luac.h" @@ -104,38 +105,36 @@ static void ThreadCode(Byte* code, Byte* end) p+=3; break; case PUSHFLOAT: - p+=5; + p+=5; /* assumes sizeof(float)==4 */ break; case PUSHSELF: case PUSHSTRING: { - CodeWord c; + Word w; p++; - get_word(c,p); - c.w=SawStr(c.w,at); - p[-2]=c.m.c1; - p[-1]=c.m.c2; + get_word(w,p); + w=SawStr(w,at); + memcpy(p-2,&w,sizeof(w)); break; } case PUSHFUNCTION: { - CodeCode c; + TFunc* tf; p++; - get_code(c,p); - c.tf->marked=at; - c.tf->next=NULL; /* TODO: remove? */ - lastF=lastF->next=c.tf; + get_code(tf,p); + tf->marked=at; + tf->next=NULL; /* TODO: remove? */ + lastF=lastF->next=tf; break; } case PUSHGLOBAL: case STOREGLOBAL: { - CodeWord c; + Word w; p++; - get_word(c,p); - c.w=SawVar(c.w,at); - p[-2]=c.m.c1; - p[-1]=c.m.c2; + get_word(w,p); + w=SawVar(w,at); + memcpy(p-2,&w,sizeof(w)); break; } case STORERECORD: @@ -144,12 +143,11 @@ static void ThreadCode(Byte* code, Byte* end) p++; while (n--) { - CodeWord c; + Word w; at=p-code; - get_word(c,p); - c.w=SawStr(c.w,at); - p[-2]=c.m.c1; - p[-1]=c.m.c2; + get_word(w,p); + w=SawStr(w,at); + memcpy(p-2,&w,sizeof(w)); } break; } @@ -167,7 +165,7 @@ static void DumpWord(int i, FILE* D) fwrite(&w,sizeof(w),1,D); } -static void DumpBlock(char* b, int size, FILE* D) +static void DumpBlock(void* b, int size, FILE* D) { fwrite(b,size,1,D); } @@ -242,6 +240,9 @@ void DumpHeader(FILE* D) fputc(ID_CHUNK,D); fputs(SIGNATURE,D); fputc(VERSION,D); + fputc(sizeof(Word),D); + fputc(sizeof(float),D); + fputc(sizeof(TFunc*),D); fwrite(&w,sizeof(w),1,D); fwrite(&f,sizeof(f),1,D); } diff --git a/src/luac/luac.c b/src/luac/luac.c index aa71afcf..7546c1bb 100644 --- a/src/luac/luac.c +++ b/src/luac/luac.c @@ -3,9 +3,10 @@ ** lua compiler (saves bytecodes to files) */ -char* rcs_luac="$Id: luac.c,v 1.16 1996/03/13 17:33:03 lhf Exp $"; +char* rcs_luac="$Id: luac.c,v 1.18 1996/11/16 20:14:23 lhf Exp $"; #include <stdio.h> +#include <stdlib.h> #include <string.h> #include "luac.h" @@ -56,7 +57,7 @@ int main(int argc, char* argv[]) fprintf(stderr,"luac: will not overwrite input file \"%s\"\n",d); exit(1); } - D=(dumping) ? fopen(d,"wb") : stdout; /* must open in binary mode */ + D=(dumping) ? fopen(d,"wb") : stdout; /* must open in binary mode */ if (D==NULL) { fprintf(stderr,"luac: cannot open "); diff --git a/src/luac/print.c b/src/luac/print.c index 1b338931..0e1d2569 100644 --- a/src/luac/print.c +++ b/src/luac/print.c @@ -3,9 +3,10 @@ ** print bytecodes */ -char* rcs_print="$Id: print.c,v 1.6 1996/03/12 20:00:24 lhf Exp $"; +char* rcs_print="$Id: print.c,v 1.11 1996/11/18 11:24:16 lhf Exp $"; #include <stdio.h> +#include <stdlib.h> #include <string.h> #include "luac.h" #include "print.h" @@ -24,7 +25,7 @@ static void PrintCode(Byte* code, Byte* end) { OpCode op=(OpCode)*p; if (op>SETLINE) op=SETLINE+1; - printf("%6d\t%s",p-code,OpCodeName[op]); + printf("%6d\t%s",(int)(p-code),OpCodeName[op]); switch (op) { case PUSHNIL: @@ -109,44 +110,44 @@ static void PrintCode(Byte* code, Byte* end) case IFFUPJMP: case SETLINE: { - CodeWord c; + Word w; p++; - get_word(c,p); - printf("\t%d",c.w); + get_word(w,p); + printf("\t%d",w); break; } case PUSHFLOAT: { - CodeFloat c; + float f; p++; - get_float(c,p); - printf("\t%g",c.f); + get_float(f,p); + printf("\t%g",f); break; } case PUSHSELF: case PUSHSTRING: { - CodeWord c; + Word w; p++; - get_word(c,p); - printf("\t%d\t; \"%s\"",c.w,StrStr(c.w)); + get_word(w,p); + printf("\t%d\t; \"%s\"",w,StrStr(w)); break; } case PUSHFUNCTION: { - CodeCode c; + TFunc* tf; p++; - get_code(c,p); - printf("\t%p\t; \"%s\":%d",c.tf,c.tf->fileName,c.tf->lineDefined); + get_code(tf,p); + printf("\t%p\t; \"%s\":%d",tf,tf->fileName,tf->lineDefined); break; } case PUSHGLOBAL: case STOREGLOBAL: { - CodeWord c; + Word w; p++; - get_word(c,p); - printf("\t%d\t; %s",c.w,VarStr(c.w)); + get_word(w,p); + printf("\t%d\t; %s",w,VarStr(w)); break; } case STORELIST: @@ -161,10 +162,10 @@ static void PrintCode(Byte* code, Byte* end) p++; while (n--) { - CodeWord c; - printf("\n%6d\t FIELD",p-code); - get_word(c,p); - printf("\t%d\t; \"%s\"",c.w,StrStr(c.w)); + Word w; + printf("\n%6d\t FIELD",(int)(p-code)); + get_word(w,p); + printf("\t%d\t; \"%s\"",w,StrStr(w)); } break; } |