static void PrintHeader(const Proto* f) { const char* s=getstr(f->source); if (*s=='@' || *s=='=') s++; else if (*s==LUA_SIGNATURE[0]) s="(bstring)"; else s="(string)"; printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n", (f->linedefined==0)?"main":"function",s, f->linedefined,f->lastlinedefined, S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f)); printf("%d%s param%s, %d slot%s, %d upvalue%s, ", f->numparams,f->is_vararg?"+":"",SS(f->numparams), S(f->maxstacksize),S(f->nups)); printf("%d local%s, %d constant%s, %d function%s\n", S(f->sizelocvars),S(f->sizek),S(f->sizep)); }
mem_ASL(ASL *asl, unsigned int len) #endif { fint k; char *memNext; if (len >= 256) return M1alloc(len); #ifdef Double_Align len = (len + (sizeof(real)-1)) & ~(sizeof(real)-1); #else len = (len + (sizeof(int)-1)) & ~(sizeof(int)-1); #endif ACQUIRE_DTOA_LOCK(MEM_LOCK); memNext = asl->i.memNext; if (memNext + len >= asl->i.memLast) { memNext = (char *)M1alloc(k = Egulp*Sizeof(expr) + len); asl->i.memLast = memNext + k; } asl->i.memNext = memNext + len; FREE_DTOA_LOCK(MEM_LOCK); return memNext; }
static Proto* load(const char* filename) { Proto* tf; ZIO z; char source[512]; PHYSFS_file* f; /* Open the file */ f = efopen(filename, "r"); sprintf(source,"@%.*s",Sizeof(source)-2,filename); luaZ_Fopen(&z,f,source); /* Parse the lua code */ tf = luaY_parser(compile_lua_state,&z); /* Close the file */ my_fclose(f); return tf; }
static void PrintCode(const Proto* f) { const Instruction* code=f->code; int pc,n=f->sizecode; for (pc=0; pc<n; pc++) { Instruction i=code[pc]; OpCode o=GET_OPCODE(i); int a=GETARG_A(i); int b=GETARG_B(i); int c=GETARG_C(i); int bc=GETARG_Bx(i); int sbc=GETARG_sBx(i); int line=getline(f,pc); #if 0 printf("%0*lX",Sizeof(i)*2,i); #endif printf("\t%d\t",pc+1); if (line>0) printf("[%d]\t",line); else printf("[-]\t"); printf("%-9s\t",luaP_opnames[o]); switch (getOpMode(o)) { case iABC: printf("%d %d %d",a,b,c); break; case iABx: printf("%d %d",a,bc); break; case iAsBx: printf("%d %d",a,sbc); break; } switch (o) { case OP_LOADK: printf("\t; "); PrintConstant(f,bc); break; case OP_GETUPVAL: case OP_SETUPVAL: printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-"); break; case OP_GETGLOBAL: case OP_SETGLOBAL: printf("\t; %s",svalue(&f->k[bc])); break; case OP_GETTABLE: case OP_SELF: if (c>=MAXSTACK) { printf("\t; "); PrintConstant(f,c-MAXSTACK); } break; case OP_SETTABLE: case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: case OP_POW: case OP_EQ: case OP_LT: case OP_LE: if (b>=MAXSTACK || c>=MAXSTACK) { printf("\t; "); if (b>=MAXSTACK) PrintConstant(f,b-MAXSTACK); else printf("-"); printf(" "); if (c>=MAXSTACK) PrintConstant(f,c-MAXSTACK); } break; case OP_JMP: case OP_FORLOOP: case OP_TFORPREP: printf("\t; to %d",sbc+pc+2); break; case OP_CLOSURE: printf("\t; %p",VOID(f->p[bc])); break; default: break; } printf("\n"); } }
int ka_read_ASL(ASL *asl, EdRead *R, int mode, int **kap, size_t **kapZ) { int flags, *kai; size_t i, k, *ka, t; int j; unsigned Long u; k = asl->i.n_var0; if (!xscanf(R,"%d",&j) || j != k - 1) return 1; if ((i = k) < n_var) i = n_var; flags = asl->i.rflags; if (flags & ASL_use_Z) { *kap = kai = A_colstarts = 0; if (!(ka = A_colstartsZ)) A_colstartsZ = ka = (size_t*)M1alloc((i+1)*Sizeof(size_t)); *kapZ = ka + 1; } else { *kapZ = ka = A_colstartsZ = 0; if (!(kai = A_colstarts)) A_colstarts = kai = (int*)M1alloc((i+1)*Sizeof(int)); *kap = kai + 1; } if (sizeof(int) == sizeof(size_t)) { if (!ka) ka = (size_t*)kai; *ka++ = 0; *ka++ = 0; /* sic */ if (mode == 'K') { t = 0; while(--k > 0) { if (!xscanf(R, "%d", &u)) return 1; *ka++ = t += u; } } else { while(--k > 0) { if (!xscanf(R, "%d", &u)) return 1; *ka++ = u; } } } else if (flags & ASL_use_Z) { *ka++ = 0; *ka++ = 0; /* sic */ if (mode == 'K') { t = 0; while(--k > 0) { if (!xscanf(R, "%d", &u)) return 1; *ka++ = t += u; } } else { while(--k > 0) { if (!xscanf(R, "%d", &u)) return 1; *ka++ = u; } } } else { *kai++ = 0; *kai++ = 0; /* sic */ if (mode == 'K') { t = 0; while(--k > 0) { if (!xscanf(R, "%d", &u)) return 1; *kai++ = (int)(t += u); } } else { while(--k > 0) { if (!xscanf(R, "%d", &u)) return 1; *kai++ = (int)u; } } } return 0; }