Skip to content

Commit

Permalink
Import Lua 5.2.1 (work1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lua Team authored and ittner committed Mar 21, 2012
1 parent 50763c8 commit 903b0bf
Show file tree
Hide file tree
Showing 22 changed files with 325 additions and 139 deletions.
2 changes: 1 addition & 1 deletion README
@@ -1,5 +1,5 @@

This is Lua 5.2, released on 12 Dec 2011.
This is Lua 5.2.1, released on xx xxx 2012.

For installation instructions, license details, and
further information about Lua, see doc/readme.html.
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Expand Up @@ -56,7 +56,7 @@ o: $(ALL_O)
a: $(ALL_A)

$(LUA_A): $(BASE_O)
$(AR) $@ $?
$(AR) $@ $(BASE_O)
$(RANLIB) $@

$(LUA_T): $(LUA_O) $(LUA_A)
Expand Down
9 changes: 6 additions & 3 deletions src/lauxlib.c
@@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.240 2011/12/06 16:33:55 roberto Exp $
** $Id: lauxlib.c,v 1.242 2012/03/19 22:57:14 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
Expand Down Expand Up @@ -616,8 +616,10 @@ static int skipBOM (LoadF *lf) {
static int skipcomment (LoadF *lf, int *cp) {
int c = *cp = skipBOM(lf);
if (c == '#') { /* first line is a comment (Unix exec. file)? */
while ((c = getc(lf->f)) != EOF && c != '\n') ; /* skip first line */
*cp = getc(lf->f); /* skip end-of-line */
do { /* skip first line */
c = getc(lf->f);
} while (c != EOF && c != '\n') ;
*cp = getc(lf->f); /* skip end-of-line, if present */
return 1; /* there was a comment */
}
else return 0; /* no comment */
Expand Down Expand Up @@ -843,6 +845,7 @@ LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
** Returns with only the table at the stack.
*/
LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
luaL_checkversion(L);
luaL_checkstack(L, nup, "too many upvalues");
for (; l->name != NULL; l++) { /* fill the table with given functions */
int i;
Expand Down
21 changes: 14 additions & 7 deletions src/ldblib.c
@@ -1,5 +1,5 @@
/*
** $Id: ldblib.c,v 1.131 2011/10/24 14:54:05 roberto Exp $
** $Id: ldblib.c,v 1.132 2012/01/19 20:14:44 roberto Exp $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
Expand Down Expand Up @@ -253,14 +253,15 @@ static int db_upvaluejoin (lua_State *L) {
}


#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY);
#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)


static void hookf (lua_State *L, lua_Debug *ar) {
static const char *const hooknames[] =
{"call", "return", "line", "count", "tail call"};
gethooktable(L);
lua_rawgetp(L, -1, L);
lua_pushthread(L);
lua_rawget(L, -2);
if (lua_isfunction(L, -1)) {
lua_pushstring(L, hooknames[(int)ar->event]);
if (ar->currentline >= 0)
Expand Down Expand Up @@ -306,10 +307,15 @@ static int db_sethook (lua_State *L) {
count = luaL_optint(L, arg+3, 0);
func = hookf; mask = makemask(smask, count);
}
gethooktable(L);
if (gethooktable(L) == 0) { /* creating hook table? */
lua_pushstring(L, "k");
lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
lua_pushvalue(L, -1);
lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
}
lua_pushthread(L1); lua_xmove(L1, L, 1);
lua_pushvalue(L, arg+1);
lua_rawsetp(L, -2, L1); /* set new hook */
lua_pop(L, 1); /* remove hook table */
lua_rawset(L, -3); /* set new hook */
lua_sethook(L1, func, mask, count); /* set hooks */
return 0;
}
Expand All @@ -325,7 +331,8 @@ static int db_gethook (lua_State *L) {
lua_pushliteral(L, "external hook");
else {
gethooktable(L);
lua_rawgetp(L, -1, L1); /* get hook */
lua_pushthread(L1); lua_xmove(L1, L, 1);
lua_rawget(L, -2); /* get hook */
lua_remove(L, -2); /* remove hook table */
}
lua_pushstring(L, unmakemask(mask, buff));
Expand Down
13 changes: 8 additions & 5 deletions src/ldebug.c
@@ -1,5 +1,5 @@
/*
** $Id: ldebug.c,v 2.88 2011/11/30 12:43:51 roberto Exp $
** $Id: ldebug.c,v 2.89 2012/01/20 22:05:50 roberto Exp $
** Debug Interface
** See Copyright Notice in lua.h
*/
Expand Down Expand Up @@ -30,6 +30,9 @@



#define noLuaClosure(f) ((f) == NULL || (f)->c.tt == LUA_TCCL)


static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);


Expand Down Expand Up @@ -173,7 +176,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {


static void funcinfo (lua_Debug *ar, Closure *cl) {
if (cl == NULL || cl->c.isC) {
if (noLuaClosure(cl)) {
ar->source = "=[C]";
ar->linedefined = -1;
ar->lastlinedefined = -1;
Expand All @@ -191,7 +194,7 @@ static void funcinfo (lua_Debug *ar, Closure *cl) {


static void collectvalidlines (lua_State *L, Closure *f) {
if (f == NULL || f->c.isC) {
if (noLuaClosure(f)) {
setnilvalue(L->top);
incr_top(L);
}
Expand All @@ -210,7 +213,7 @@ static void collectvalidlines (lua_State *L, Closure *f) {


static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
Closure *f, CallInfo *ci) {
Closure *f, CallInfo *ci) {
int status = 1;
for (; *what; what++) {
switch (*what) {
Expand All @@ -224,7 +227,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
}
case 'u': {
ar->nups = (f == NULL) ? 0 : f->c.nupvalues;
if (f == NULL || f->c.isC) {
if (noLuaClosure(f)) {
ar->isvararg = 1;
ar->nparams = 0;
}
Expand Down
7 changes: 4 additions & 3 deletions src/ldump.c
@@ -1,5 +1,5 @@
/*
** $Id: ldump.c,v 1.19 2011/11/23 17:48:18 lhf Exp $
** $Id: ldump.c,v 1.20 2012/03/21 18:11:35 lhf Exp $
** save precompiled Lua chunks
** See Copyright Notice in lua.h
*/
Expand Down Expand Up @@ -84,8 +84,8 @@ static void DumpConstants(const Proto* f, DumpState* D)
for (i=0; i<n; i++)
{
const TValue* o=&f->k[i];
DumpChar(ttype(o),D);
switch (ttype(o))
DumpChar(ttypenv(o),D);
switch (ttypenv(o))
{
case LUA_TNIL:
break;
Expand All @@ -98,6 +98,7 @@ static void DumpConstants(const Proto* f, DumpState* D)
case LUA_TSTRING:
DumpString(rawtsvalue(o),D);
break;
default: lua_assert(0);
}
}
n=f->sizep;
Expand Down
15 changes: 3 additions & 12 deletions src/lfunc.c
@@ -1,5 +1,5 @@
/*
** $Id: lfunc.c,v 2.27 2010/06/30 14:11:17 roberto Exp $
** $Id: lfunc.c,v 2.28 2012/01/20 22:05:50 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
Expand All @@ -21,17 +21,15 @@


Closure *luaF_newCclosure (lua_State *L, int n) {
Closure *c = &luaC_newobj(L, LUA_TFUNCTION, sizeCclosure(n), NULL, 0)->cl;
c->c.isC = 1;
Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n), NULL, 0)->cl;
c->c.nupvalues = cast_byte(n);
return c;
}


Closure *luaF_newLclosure (lua_State *L, Proto *p) {
int n = p->sizeupvalues;
Closure *c = &luaC_newobj(L, LUA_TFUNCTION, sizeLclosure(n), NULL, 0)->cl;
c->l.isC = 0;
Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n), NULL, 0)->cl;
c->l.p = p;
c->l.nupvalues = cast_byte(n);
while (n--) c->l.upvals[n] = NULL;
Expand Down Expand Up @@ -146,13 +144,6 @@ void luaF_freeproto (lua_State *L, Proto *f) {
}


void luaF_freeclosure (lua_State *L, Closure *c) {
int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) :
sizeLclosure(c->l.nupvalues);
luaM_freemem(L, c, size);
}


/*
** Look for n-th local variable at line `line' in function `func'.
** Returns NULL if not found.
Expand Down
3 changes: 1 addition & 2 deletions src/lfunc.h
@@ -1,5 +1,5 @@
/*
** $Id: lfunc.h,v 2.6 2010/06/04 13:06:15 roberto Exp $
** $Id: lfunc.h,v 2.7 2012/01/20 22:05:50 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
Expand All @@ -25,7 +25,6 @@ LUAI_FUNC UpVal *luaF_newupval (lua_State *L);
LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
LUAI_FUNC void luaF_close (lua_State *L, StkId level);
LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c);
LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv);
LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
int pc);
Expand Down
90 changes: 57 additions & 33 deletions src/lgc.c
@@ -1,5 +1,5 @@
/*
** $Id: lgc.c,v 2.116 2011/12/02 13:18:41 roberto Exp $
** $Id: lgc.c,v 2.119 2012/01/25 21:05:40 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
*/
Expand Down Expand Up @@ -65,7 +65,11 @@
#define white2gray(x) resetbits(gch(x)->marked, WHITEBITS)
#define black2gray(x) resetbit(gch(x)->marked, BLACKBIT)

#define stringmark(s) ((void)((s) && resetbits((s)->tsv.marked, WHITEBITS)))
/*
** dirty trick: we know that 'reallymarkobject' does not use 'g' when
** object is a string
*/
#define stringmark(s) markobject(NULL, s)


#define isfinalized(x) testbit(gch(x)->marked, FINALIZEDBIT)
Expand Down Expand Up @@ -217,7 +221,8 @@ void luaC_checkupvalcolor (global_State *g, UpVal *uv) {
GCObject *luaC_newobj (lua_State *L, int tt, size_t sz, GCObject **list,
int offset) {
global_State *g = G(L);
GCObject *o = obj2gco(cast(char *, luaM_newobject(L, tt, sz)) + offset);
char *raw = cast(char *, luaM_newobject(L, novariant(tt), sz));
GCObject *o = obj2gco(raw + offset);
if (list == NULL)
list = &g->allgc; /* standard list for collectable objects */
gch(o)->marked = luaC_white(g);
Expand All @@ -239,18 +244,18 @@ GCObject *luaC_newobj (lua_State *L, int tt, size_t sz, GCObject **list,


/*
** mark an object. Userdata and closed upvalues are visited and turned
** black here. Strings remain gray (it is the same as making them
** black). Other objects are marked gray and added to appropriate list
** to be visited (and turned black) later. (Open upvalues are already
** linked in 'headuv' list.)
** mark an object. Userdata, strings, and closed upvalues are visited
** and turned black here. Other objects are marked gray and added
** to appropriate list to be visited (and turned black) later. (Open
** upvalues are already linked in 'headuv' list.)
*/
static void reallymarkobject (global_State *g, GCObject *o) {
lua_assert(iswhite(o) && !isdead(g, o));
white2gray(o);
switch (gch(o)->tt) {
case LUA_TSTRING: {
return; /* for strings, gray is as good as black */
case LUA_TSHRSTR:
case LUA_TLNGSTR: {
gray2black(o);
return; /* nothing else to mark */
}
case LUA_TUSERDATA: {
Table *mt = gco2u(o)->metatable;
Expand All @@ -266,8 +271,13 @@ static void reallymarkobject (global_State *g, GCObject *o) {
gray2black(o); /* make it black */
return;
}
case LUA_TFUNCTION: {
gco2cl(o)->c.gclist = g->gray;
case LUA_TLCL: {
gco2lcl(o)->gclist = g->gray;
g->gray = o;
break;
}
case LUA_TCCL: {
gco2ccl(o)->gclist = g->gray;
g->gray = o;
break;
}
Expand Down Expand Up @@ -470,20 +480,20 @@ static int traverseproto (global_State *g, Proto *f) {
}


static int traverseclosure (global_State *g, Closure *cl) {
if (cl->c.isC) {
int i;
for (i=0; i<cl->c.nupvalues; i++) /* mark its upvalues */
markvalue(g, &cl->c.upvalue[i]);
}
else {
int i;
lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues);
markobject(g, cl->l.p); /* mark its prototype */
for (i=0; i<cl->l.nupvalues; i++) /* mark its upvalues */
markobject(g, cl->l.upvals[i]);
}
return TRAVCOST + cl->c.nupvalues;
static int traverseCclosure (global_State *g, CClosure *cl) {
int i;
for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */
markvalue(g, &cl->upvalue[i]);
return TRAVCOST + cl->nupvalues;
}

static int traverseLclosure (global_State *g, LClosure *cl) {
int i;
lua_assert(cl->nupvalues == cl->p->sizeupvalues);
markobject(g, cl->p); /* mark its prototype */
for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */
markobject(g, cl->upvals[i]);
return TRAVCOST + cl->nupvalues;
}


Expand Down Expand Up @@ -517,10 +527,15 @@ static int propagatemark (global_State *g) {
g->gray = h->gclist;
return traversetable(g, h);
}
case LUA_TFUNCTION: {
Closure *cl = gco2cl(o);
g->gray = cl->c.gclist;
return traverseclosure(g, cl);
case LUA_TLCL: {
LClosure *cl = gco2lcl(o);
g->gray = cl->gclist;
return traverseLclosure(g, cl);
}
case LUA_TCCL: {
CClosure *cl = gco2ccl(o);
g->gray = cl->gclist;
return traverseCclosure(g, cl);
}
case LUA_TTHREAD: {
lua_State *th = gco2th(o);
Expand Down Expand Up @@ -640,13 +655,22 @@ static void clearvalues (GCObject *l, GCObject *f) {
static void freeobj (lua_State *L, GCObject *o) {
switch (gch(o)->tt) {
case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;
case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break;
case LUA_TLCL: {
luaM_freemem(L, o, sizeLclosure(gco2lcl(o)->nupvalues));
break;
}
case LUA_TCCL: {
luaM_freemem(L, o, sizeCclosure(gco2ccl(o)->nupvalues));
break;
}
case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break;
case LUA_TTABLE: luaH_free(L, gco2t(o)); break;
case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break;
case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break;
case LUA_TSTRING: {
case LUA_TSHRSTR:
G(L)->strt.nuse--;
/* go through */
case LUA_TLNGSTR: {
luaM_freemem(L, o, sizestring(gco2ts(o)));
break;
}
Expand Down

0 comments on commit 903b0bf

Please sign in to comment.