summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorpixel <pixel>2004-04-27 11:23:29 +0000
committerpixel <pixel>2004-04-27 11:23:29 +0000
commitc5f2cd8f54bdd7be60dca04071868216ca897726 (patch)
treea4300a87209d07d4652f5af2ab4af6f53cf7379b /lib
parent2a7ee340df72d9e357a94d3ecf671a62d5956a92 (diff)
Ugh... since when this bug is in place ?
Diffstat (limited to 'lib')
-rw-r--r--lib/Buffer.cc8
-rw-r--r--lib/lua/src/luacomp.c95
2 files changed, 57 insertions, 46 deletions
diff --git a/lib/Buffer.cc b/lib/Buffer.cc
index 16966e4..216a1f6 100644
--- a/lib/Buffer.cc
+++ b/lib/Buffer.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: Buffer.cc,v 1.22 2003-12-12 12:45:20 pixel Exp $ */
+/* $Id: Buffer.cc,v 1.23 2004-04-27 11:23:29 pixel Exp $ */
#include <string.h>
#ifdef HAVE_CONFIG_H
@@ -71,6 +71,7 @@ ssize_t Buffer::read(void *buf, size_t count) throw (GeneralException) {
int numblocks = (bufsiz / realloc_threshold) - (ptr / realloc_threshold);
memmove(buffer, buffer + (bufsiz - numblocks * realloc_threshold), numblocks * realloc_threshold);
ptr -= (bufsiz - numblocks * realloc_threshold);
+ wptr -= (bufsiz - numblocks * realloc_threshold);
realsiz -= (bufsiz - numblocks * realloc_threshold);
buffer = (Byte *) realloc(buffer, bufsiz = (numblocks * realloc_threshold));
}
@@ -200,3 +201,8 @@ off_t Buffer::wseek(off_t off, int wheel) throw (GeneralException) {
off_t Buffer::wtell() const {
return wptr;
}
+
+void Buffer::reset() {
+ free(buffer);
+ realsiz = bufsiz = ptr = wptr = 0;
+}
diff --git a/lib/lua/src/luacomp.c b/lib/lua/src/luacomp.c
index 4781bff..a2d5036 100644
--- a/lib/lua/src/luacomp.c
+++ b/lib/lua/src/luacomp.c
@@ -1,8 +1,10 @@
/*
-** $Id: luacomp.c,v 1.3 2004-01-26 15:32:51 pixel Exp $
-** Lua compiler (saves bytecodes to files; also list bytecodes)
-** See Copyright Notice in lua.h
-*/
+ ** $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>
@@ -19,57 +21,60 @@
#include "lundump.h"
#ifndef PROGNAME
-#define PROGNAME "luacomp" /* program name */
+#define PROGNAME "luacomp" /* program name */
#endif
-static const char* progname=PROGNAME; /* actual program name */
+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 * 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 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]);
+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) {
Proto * f;
+
f = combine(L, lua_gettop(L));
if (stripping)
strip(L, f);