/* ** $Id: luac.c,v 1.28 2000/11/06 20:06:27 lhf Exp $ ** lua compiler (saves bytecodes to files; also list binary files) ** See Copyright Notice in lua.h */ #include #include #include #include "lparser.h" #include "lstate.h" #include "lzio.h" #include "luac.h" #define OUTPUT "luac.out" /* default output file */ static void usage(const char* message, const char* arg); static int doargs(int argc, const char* argv[]); static Proto* load(const char* filename); static FILE* efopen(const char* name, const char* mode); static void strip(Proto* tf); static Proto* combine(Proto** P, int n); lua_State* lua_state=NULL; /* lazy! */ static int listing=0; /* list bytecodes? */ static int dumping=1; /* dump bytecodes? */ static int stripping=0; /* strip debug information? */ static int testing=0; /* test integrity? */ static const char* output=OUTPUT; /* output file name */ #define IS(s) (strcmp(argv[i],s)==0) int main(int argc, const char* argv[]) { Proto** P,*tf; int i=doargs(argc,argv); argc-=i; argv+=i; if (argc<=0) usage("no input files given",NULL); L=lua_open(0); P=luaM_newvector(L,argc,Proto*); for (i=0; isource=luaS_new(L,"=(luac)"); tf->maxstacksize=1; tf->kproto=P; tf->nkproto=n; tf->ncode=2*n+1; tf->code=luaM_newvector(L,tf->ncode,Instruction); for (i=0; icode[pc++]=CREATE_AB(OP_CLOSURE,i,0); tf->code[pc++]=CREATE_AB(OP_CALL,0,0); } tf->code[pc++]=OP_END; return tf; } } static void strip(Proto* tf) { int i,n=tf->nkproto; tf->lineinfo=NULL; tf->nlineinfo=0; tf->source=luaS_new(L,"=(none)"); tf->locvars=NULL; tf->nlocvars=0; for (i=0; ikproto[i]); } static FILE* efopen(const char* name, const char* mode) { FILE* f=fopen(name,mode); if (f==NULL) { fprintf(stderr,"luac: cannot open %sput file ",*mode=='r' ? "in" : "out"); perror(name); exit(1); } return f; } void luaU_testchunk(const Proto* Main) { UNUSED(Main); fprintf(stderr,"luac: -t not operational in this version\n"); exit(1); }