summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2004-12-27 19:52:23 +0000
committerpixel <pixel>2004-12-27 19:52:23 +0000
commitffbd44960ec46c3c0def38821623a62d696c6018 (patch)
tree1b8dca54fd64287cda5095348160011eed41f14a
parent73b826216433355c36cac2b679dbbe755df53284 (diff)
Updating lua to 5.0.2
-rw-r--r--lib/lua/include/lua.h6
-rw-r--r--lib/lua/includes/lgc.h4
-rw-r--r--lib/lua/src/LuaLib/lbaselib.c7
-rw-r--r--lib/lua/src/LuaLib/liolib.c6
-rw-r--r--lib/lua/src/ldo.c25
-rw-r--r--lib/lua/src/lgc.c23
-rw-r--r--lib/lua/src/lparser.c10
-rw-r--r--lib/lua/src/luacomp.c4
-rw-r--r--lib/lua/src/lvm.c14
9 files changed, 62 insertions, 37 deletions
diff --git a/lib/lua/include/lua.h b/lib/lua/include/lua.h
index a3def0e..2540709 100644
--- a/lib/lua/include/lua.h
+++ b/lib/lua/include/lua.h
@@ -1,5 +1,5 @@
/*
-** $Id: lua.h,v 1.6 2004-11-27 21:46:06 pixel Exp $
+** $Id: lua.h,v 1.7 2004-12-27 19:52:23 pixel Exp $
** Lua - An Extensible Extension Language
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
** http://www.lua.org mailto:info@lua.org
@@ -17,8 +17,8 @@
extern "C" {
#endif
-#define LUA_VERSION "Lua 5.0"
-#define LUA_COPYRIGHT "Copyright (C) 1994-2003 Tecgraf, PUC-Rio"
+#define LUA_VERSION "Lua 5.0.2"
+#define LUA_COPYRIGHT "Copyright (C) 1994-2004 Tecgraf, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
diff --git a/lib/lua/includes/lgc.h b/lib/lua/includes/lgc.h
index 43ae521..d3eb244 100644
--- a/lib/lua/includes/lgc.h
+++ b/lib/lua/includes/lgc.h
@@ -1,5 +1,5 @@
/*
-** $Id: lgc.h,v 1.4 2004-11-27 21:46:06 pixel Exp $
+** $Id: lgc.h,v 1.5 2004-12-27 19:52:23 pixel Exp $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@@ -15,7 +15,7 @@
if (G(L)->nblocks >= G(L)->GCthreshold) luaC_collectgarbage(L); }
-void luaC_separateudata (lua_State *L);
+size_t luaC_separateudata (lua_State *L);
void luaC_callGCTM (lua_State *L);
void luaC_sweep (lua_State *L, int all);
void luaC_collectgarbage (lua_State *L);
diff --git a/lib/lua/src/LuaLib/lbaselib.c b/lib/lua/src/LuaLib/lbaselib.c
index 11e5504..ea70d2e 100644
--- a/lib/lua/src/LuaLib/lbaselib.c
+++ b/lib/lua/src/LuaLib/lbaselib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbaselib.c,v 1.4 2004-11-27 21:46:10 pixel Exp $
+** $Id: lbaselib.c,v 1.5 2004-12-27 19:52:23 pixel Exp $
** Basic library
** See Copyright Notice in lua.h
*/
@@ -274,10 +274,11 @@ static int luaB_loadfile (lua_State *L) {
static int luaB_dofile (lua_State *L) {
const char *fname = luaL_optstring(L, 1, NULL);
+ int n = lua_gettop(L);
int status = luaL_loadfile(L, fname);
if (status != 0) lua_error(L);
lua_call(L, 0, LUA_MULTRET);
- return lua_gettop(L) - 1;
+ return lua_gettop(L) - n;
}
@@ -324,7 +325,7 @@ static int luaB_xpcall (lua_State *L) {
static int luaB_tostring (lua_State *L) {
- char buff[64];
+ char buff[128];
luaL_checkany(L, 1);
if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */
return 1; /* use its value */
diff --git a/lib/lua/src/LuaLib/liolib.c b/lib/lua/src/LuaLib/liolib.c
index 69e0a19..29c4821 100644
--- a/lib/lua/src/LuaLib/liolib.c
+++ b/lib/lua/src/LuaLib/liolib.c
@@ -1,5 +1,5 @@
/*
-** $Id: liolib.c,v 1.4 2004-11-27 21:46:10 pixel Exp $
+** $Id: liolib.c,v 1.5 2004-12-27 19:52:23 pixel Exp $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@@ -158,7 +158,7 @@ static int aux_close (lua_State *L) {
static int io_close (lua_State *L) {
- if (lua_isnone(L, 1)) {
+ if (lua_isnone(L, 1) && lua_type(L, lua_upvalueindex(1)) == LUA_TTABLE) {
lua_pushstring(L, IO_OUTPUT);
lua_rawget(L, lua_upvalueindex(1));
}
@@ -175,7 +175,7 @@ static int io_gc (lua_State *L) {
static int io_tostring (lua_State *L) {
- char buff[32];
+ char buff[128];
FILE **f = topfile(L, 1);
if (*f == NULL)
strcpy(buff, "closed");
diff --git a/lib/lua/src/ldo.c b/lib/lua/src/ldo.c
index aa4cf70..f1472b2 100644
--- a/lib/lua/src/ldo.c
+++ b/lib/lua/src/ldo.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldo.c,v 1.5 2004-11-27 21:46:07 pixel Exp $
+** $Id: ldo.c,v 1.6 2004-12-27 19:52:23 pixel Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -322,11 +322,11 @@ static void resume (lua_State *L, void *ud) {
int nargs = *cast(int *, ud);
CallInfo *ci = L->ci;
if (ci == L->base_ci) { /* no activation record? */
- if (nargs >= L->top - L->base)
- luaG_runerror(L, "cannot resume dead coroutine");
+ lua_assert(nargs < L->top - L->base);
luaD_precall(L, L->top - (nargs + 1)); /* start coroutine */
}
- else if (ci->state & CI_YIELD) { /* inside a yield? */
+ else { /* inside a yield */
+ lua_assert(ci->state & CI_YIELD);
if (ci->state & CI_C) { /* `common' yield? */
/* finish interrupted execution of `OP_CALL' */
int nresults;
@@ -341,18 +341,31 @@ static void resume (lua_State *L, void *ud) {
ci->state &= ~CI_YIELD;
}
}
- else
- luaG_runerror(L, "cannot resume non-suspended coroutine");
firstResult = luaV_execute(L);
if (firstResult != NULL) /* return? */
luaD_poscall(L, LUA_MULTRET, firstResult); /* finalize this coroutine */
}
+static int resume_error (lua_State *L, const char *msg) {
+ L->top = L->ci->base;
+ setsvalue2s(L->top, lusS_new(L, msg));
+ incr_top(L);
+ lua_unlock(L);
+ return LUA_ERRRUN;
+}
+
+
LUA_API int lua_resume (lua_State *L, int nargs) {
int status;
lu_byte old_allowhooks;
lua_lock(L);
+ if (L->ci == L->base_ci) {
+ if (nargs >= L->top - L->base)
+ return resume_error(L, "cannot resume dead coroutine");
+ }
+ else if (!(L->ci->state & CI_YIELD)) /* not inside a yield? */
+ return resume_error(L, "cannot resume non-suspended coroutine");
old_allowhooks = L->allowhook;
lua_assert(L->errfunc == 0 && L->nCcalls == 0);
status = luaD_rawrunprotected(L, resume, &nargs);
diff --git a/lib/lua/src/lgc.c b/lib/lua/src/lgc.c
index 15ddbb6..dc939c8 100644
--- a/lib/lua/src/lgc.c
+++ b/lib/lua/src/lgc.c
@@ -1,5 +1,5 @@
/*
-** $Id: lgc.c,v 1.4 2004-11-27 21:46:07 pixel Exp $
+** $Id: lgc.c,v 1.5 2004-12-27 19:52:23 pixel Exp $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@@ -110,7 +110,8 @@ static void marktmu (GCState *st) {
/* move `dead' udata that need finalization to list `tmudata' */
-void luaC_separateudata (lua_State *L) {
+size_t luaC_separateudata (lua_State *L) {
+ size_t deadmem = 0;
GCObject **p = &G(L)->rootudata;
GCObject *curr;
GCObject *collected = NULL; /* to collect udata with gc event */
@@ -125,6 +126,7 @@ void luaC_separateudata (lua_State *L) {
p = &curr->gch.next;
}
else { /* must call its gc method */
+ deadmem += sizeudata(gcotou(curr)->uv.len);
*p = curr->gch.next;
curr->gch.next = NULL; /* link `curr' at the end of `collected' list */
*lastcollected = curr;
@@ -134,6 +136,7 @@ void luaC_separateudata (lua_State *L) {
/* insert collected udata with gc event into `tmudata' list */
*lastcollected = G(L)->tmudata;
G(L)->tmudata = collected;
+ return deadmem;
}
@@ -244,7 +247,7 @@ static void traversestack (GCState *st, lua_State *L1) {
for (ci = L1->base_ci; ci <= L1->ci; ci++) {
lua_assert(ci->top <= L1->stack_last);
lua_assert(ci->state & (CI_C | CI_HASFRAME | CI_SAVEDPC));
- if (!(ci->state & CI_C) && lim < ci->top)
+ if (lim < ci->top)
lim = ci->top;
}
for (o = L1->stack; o < L1->top; o++)
@@ -387,7 +390,7 @@ static void sweepstrings (lua_State *L, int all) {
}
-static void checkSizes (lua_State *L) {
+static void checkSizes (lua_State *L, size_t deadmem) {
/* check size of string hash */
if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) &&
G(L)->strt.size > MINSTRTABSIZE*2)
@@ -397,7 +400,7 @@ static void checkSizes (lua_State *L) {
size_t newsize = luaZ_sizebuffer(&G(L)->buff) / 2;
luaZ_resizebuffer(L, &G(L)->buff, newsize);
}
- G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */
+ G(L)->GCthreshold = 2*G(L)->nblocks - deadmem; /* new threshold */
}
@@ -451,7 +454,8 @@ static void markroot (GCState *st, lua_State *L) {
}
-static void mark (lua_State *L) {
+static size_t mark (lua_State *L) {
+ size_t deadmem;
GCState st;
GCObject *wkv;
st.g = G(L);
@@ -464,7 +468,7 @@ static void mark (lua_State *L) {
wkv = st.wkv; /* keys must be cleared after preserving udata */
st.wkv = NULL;
st.wv = NULL;
- luaC_separateudata(L); /* separate userdata to be preserved */
+ deadmem = luaC_separateudata(L); /* separate userdata to be preserved */
marktmu(&st); /* mark `preserved' userdata */
propagatemarks(&st); /* remark, to propagate `preserveness' */
cleartablekeys(wkv);
@@ -473,13 +477,14 @@ static void mark (lua_State *L) {
cleartablevalues(st.wv);
cleartablekeys(st.wkv);
cleartablevalues(st.wkv);
+ return deadmem;
}
void luaC_collectgarbage (lua_State *L) {
- mark(L);
+ size_t deadmem = mark(L);
luaC_sweep(L, 0);
- checkSizes(L);
+ checkSizes(L, deadmem);
luaC_callGCTM(L);
}
diff --git a/lib/lua/src/lparser.c b/lib/lua/src/lparser.c
index a242338..5cd7018 100644
--- a/lib/lua/src/lparser.c
+++ b/lib/lua/src/lparser.c
@@ -1,5 +1,5 @@
/*
-** $Id: lparser.c,v 1.4 2004-11-27 21:46:07 pixel Exp $
+** $Id: lparser.c,v 1.5 2004-12-27 19:52:24 pixel Exp $
** Lua Parser
** See Copyright Notice in lua.h
*/
@@ -1141,11 +1141,15 @@ static void ifstat (LexState *ls, int line) {
static void localfunc (LexState *ls) {
expdesc v, b;
+ FuncState *fs = ls->fs;
new_localvar(ls, str_checkname(ls), 0);
- init_exp(&v, VLOCAL, ls->fs->freereg++);
+ init_exp(&v, VLOCAL, fs->freereg++);
+ luaK_reserveregs(fs, 1);
adjustlocalvars(ls, 1);
body(ls, &b, 0, ls->linenumber);
- luaK_storevar(ls->fs, &v, &b);
+ luaK_storevar(fs, &v, &b);
+ /* debug information will only see the variable after this point! */
+ getlocvar(fs, fs->nactvar - 1).startpc = fs->pc;
}
diff --git a/lib/lua/src/luacomp.c b/lib/lua/src/luacomp.c
index 87372a2..0009b24 100644
--- a/lib/lua/src/luacomp.c
+++ b/lib/lua/src/luacomp.c
@@ -1,5 +1,5 @@
/*
- ** $Id: luacomp.c,v 1.6 2004-11-27 21:46:07 pixel Exp $
+ ** $Id: luacomp.c,v 1.7 2004-12-27 19:52:24 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.
@@ -78,5 +78,7 @@ void luacmain(lua_State * L, int stripping, lua_Chunkwriter w, void *uD) {
f = combine(L, lua_gettop(L));
if (stripping)
strip(L, f);
+ lua_lock(L);
luaU_dump(L, f, w, uD);
+ lua_unlock(L);
}
diff --git a/lib/lua/src/lvm.c b/lib/lua/src/lvm.c
index 6c07b0f..adca9b2 100644
--- a/lib/lua/src/lvm.c
+++ b/lib/lua/src/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 1.5 2004-11-27 21:46:07 pixel Exp $
+** $Id: lvm.c,v 1.6 2004-12-27 19:52:24 pixel Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -66,7 +66,7 @@ int luaV_tostring (lua_State *L, StkId obj) {
static void traceexec (lua_State *L) {
lu_byte mask = L->hookmask;
- if (mask > LUA_MASKLINE) { /* instruction-hook set? */
+ if (mask > LUA_MASKCOUNT) { /* instruction-hook set? */
if (L->hookcount == 0) {
resethookcount(L);
luaD_callhook(L, LUA_HOOKCOUNT, -1);
@@ -399,10 +399,12 @@ StkId luaV_execute (lua_State *L) {
TObject *k;
const Instruction *pc;
callentry: /* entry point when calling new functions */
- L->ci->u.l.pc = &pc;
- if (L->hookmask & LUA_MASKCALL)
+ if (L->hookmask & LUA_MASKCALL) {
+ L->ci->u.l.pc = &pc;
luaD_callhook(L, LUA_HOOKCALL, -1);
+ }
retentry: /* entry point when returning to old functions */
+ L->ci->u.l.pc = &pc;
lua_assert(L->ci->state == CI_SAVEDPC ||
L->ci->state == (CI_SAVEDPC | CI_CALLING));
L->ci->state = CI_HASFRAME; /* activate frame */
@@ -677,9 +679,7 @@ StkId luaV_execute (lua_State *L) {
}
else { /* yes: continue its execution */
int nresults;
- lua_assert(ci->u.l.pc == &pc &&
- ttisfunction(ci->base - 1) &&
- (ci->state & CI_SAVEDPC));
+ lua_assert(ttisfunction(ci->base - 1) && (ci->state & CI_SAVEDPC));
lua_assert(GET_OPCODE(*(ci->u.l.savedpc - 1)) == OP_CALL);
nresults = GETARG_C(*(ci->u.l.savedpc - 1)) - 1;
luaD_poscall(L, nresults, ra);