diff options
author | pixel <pixel> | 2004-11-27 21:35:19 +0000 |
---|---|---|
committer | pixel <pixel> | 2004-11-27 21:35:19 +0000 |
commit | 3f7070bf177b743be0eeb8c404a620f72eb15ab6 (patch) | |
tree | a22fa7d0a1fd362bfc858f8e7e2062fdd5b252ce /lib/lua/src/luacomp.c | |
parent | 6ba597d46a93aaa9a17eb8a9fe8f3bcdedf686c0 (diff) |
Large dos2unix commit...
Diffstat (limited to 'lib/lua/src/luacomp.c')
-rw-r--r-- | lib/lua/src/luacomp.c | 164 |
1 files changed, 82 insertions, 82 deletions
diff --git a/lib/lua/src/luacomp.c b/lib/lua/src/luacomp.c index a2d5036..bac561b 100644 --- a/lib/lua/src/luacomp.c +++ b/lib/lua/src/luacomp.c @@ -1,82 +1,82 @@ -/* - ** $Id: luacomp.c,v 1.4 2004-04-27 11:23:30 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. - ** See Copyright Notice in lua.h - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "lua.h" -#include "lauxlib.h" - -#include "lfunc.h" -#include "lmem.h" -#include "lobject.h" -#include "lopcodes.h" -#include "lstring.h" -#include "lundump.h" - -#ifndef PROGNAME -#define PROGNAME "luacomp" /* program name */ -#endif - -const char * progname = PROGNAME; /* actual program name */ - -static Proto * toproto(lua_State * L, int i) { - const Closure * c = (const Closure *) lua_topointer(L, i); - - return c->l.p; -} - -static Proto * combine(lua_State * L, int n) { - if (n == 1) - return toproto(L, -1); - else { - int i, pc = 0; - Proto * f = luaF_newproto(L); - - f->source = luaS_newliteral(L, "=(" PROGNAME ")"); - f->maxstacksize = 1; - f->p = luaM_newvector(L, n, Proto *); - f->sizep = n; - f->sizecode = 2 * n + 1; - f->code = luaM_newvector(L, f->sizecode, Instruction); - for (i = 0; i < n; i++) { - f->p[i] = toproto(L, i - n); - f->code[pc++] = CREATE_ABx(OP_CLOSURE, 0, i); - f->code[pc++] = CREATE_ABC(OP_CALL, 0, 1, 1); - } - f->code[pc++] = CREATE_ABC(OP_RETURN, 0, 1, 0); - return f; - } -} - -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) { - Proto * f; - - f = combine(L, lua_gettop(L)); - if (stripping) - strip(L, f); - luaU_dump(L, f, w, uD); -} +/*
+ ** $Id: luacomp.c,v 1.5 2004-11-27 21:35:20 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.
+ ** See Copyright Notice in lua.h
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "lua.h"
+#include "lauxlib.h"
+
+#include "lfunc.h"
+#include "lmem.h"
+#include "lobject.h"
+#include "lopcodes.h"
+#include "lstring.h"
+#include "lundump.h"
+
+#ifndef PROGNAME
+#define PROGNAME "luacomp" /* program name */
+#endif
+
+const char * progname = PROGNAME; /* actual program name */
+
+static Proto * toproto(lua_State * L, int i) {
+ const Closure * c = (const Closure *) lua_topointer(L, i);
+
+ return c->l.p;
+}
+
+static Proto * combine(lua_State * L, int n) {
+ if (n == 1)
+ return toproto(L, -1);
+ else {
+ int i, pc = 0;
+ Proto * f = luaF_newproto(L);
+
+ f->source = luaS_newliteral(L, "=(" PROGNAME ")");
+ f->maxstacksize = 1;
+ f->p = luaM_newvector(L, n, Proto *);
+ f->sizep = n;
+ f->sizecode = 2 * n + 1;
+ f->code = luaM_newvector(L, f->sizecode, Instruction);
+ for (i = 0; i < n; i++) {
+ f->p[i] = toproto(L, i - n);
+ f->code[pc++] = CREATE_ABx(OP_CLOSURE, 0, i);
+ f->code[pc++] = CREATE_ABC(OP_CALL, 0, 1, 1);
+ }
+ f->code[pc++] = CREATE_ABC(OP_RETURN, 0, 1, 0);
+ return f;
+ }
+}
+
+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) {
+ Proto * f;
+
+ f = combine(L, lua_gettop(L));
+ if (stripping)
+ strip(L, f);
+ luaU_dump(L, f, w, uD);
+}
|