diff options
Diffstat (limited to 'lib/lua/src/luacomp.c')
-rw-r--r-- | lib/lua/src/luacomp.c | 45 |
1 files changed, 14 insertions, 31 deletions
diff --git a/lib/lua/src/luacomp.c b/lib/lua/src/luacomp.c index 0009b24..1246869 100644 --- a/lib/lua/src/luacomp.c +++ b/lib/lua/src/luacomp.c @@ -1,5 +1,5 @@ /* - ** $Id: luacomp.c,v 1.7 2004-12-27 19:52:24 pixel Exp $ + ** $Id: luacomp.c,v 1.8 2007-07-27 10:05:54 pixel Exp $ ** Lua compiler (saves bytecodes to files; also list bytecodes) ** Highly hacked by Nicolas "Pixel" Noble to be transformed into a ** small form-factor LUA compiler. @@ -19,6 +19,7 @@ #include "lopcodes.h" #include "lstring.h" #include "lundump.h" +#include "ldo.h" #ifndef PROGNAME #define PROGNAME "luacomp" /* program name */ @@ -26,27 +27,26 @@ const char * progname = PROGNAME; /* actual program name */ -static Proto * toproto(lua_State * L, int i) { - const Closure * c = (const Closure *) lua_topointer(L, i); +#define toproto(L, i) (clvalue(L->top + (i))->l.p) - return c->l.p; -} - -static Proto * combine(lua_State * L, int n) { +static const Proto * combine(lua_State * L, int n) { if (n == 1) return toproto(L, -1); else { int i, pc = 0; Proto * f = luaF_newproto(L); + setptvalue2s(L, L->top, f); incr_top(L); f->source = luaS_newliteral(L, "=(" PROGNAME ")"); f->maxstacksize = 1; + pc = 2 * n + 1; + f->code = luaM_newvector(L, pc, Instruction); + f->sizecode = pc; f->p = luaM_newvector(L, n, Proto *); f->sizep = n; - f->sizecode = 2 * n + 1; - f->code = luaM_newvector(L, f->sizecode, Instruction); + pc = 0; for (i = 0; i < n; i++) { - f->p[i] = toproto(L, i - n); + f->p[i] = toproto(L, i - n - 1); f->code[pc++] = CREATE_ABx(OP_CLOSURE, 0, i); f->code[pc++] = CREATE_ABC(OP_CALL, 0, 1, 1); } @@ -55,30 +55,13 @@ static Proto * combine(lua_State * L, int n) { } } -static void strip(lua_State * L, Proto * f) { - int i, n = f->sizep; - luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); - luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); - - luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); - f->lineinfo = NULL; - f->sizelineinfo = 0; - f->locvars = NULL; - f->sizelocvars = 0; - f->upvalues = NULL; - f->sizeupvalues = 0; - f->source = luaS_newliteral(L, "=(none)"); - for (i = 0; i < n; i++) - strip(L, f->p[i]); -} - -void luacmain(lua_State * L, int stripping, lua_Chunkwriter w, void *uD) { +void luacmain(lua_State * L, int stripping, lua_Chunkwriter w, void *uD, int listing) { Proto * f; f = combine(L, lua_gettop(L)); - if (stripping) - strip(L, f); + if (listing) + luaU_print(f, listing > 1); lua_lock(L); - luaU_dump(L, f, w, uD); + luaU_dump(L, f, w, uD, stripping); lua_unlock(L); } |