Browse Source

name changes to avoid name collision between macros and variables

v5-2
Roberto Ierusalimschy 22 years ago
parent
commit
ab9e062928
  1. 8
      ldebug.c
  2. 6
      lfunc.c
  3. 4
      lfunc.h
  4. 46
      lgc.c
  5. 3
      lobject.h
  6. 6
      lstate.c
  7. 72
      ltable.c
  8. 8
      ltable.h

8
ldebug.c

@ -1,5 +1,5 @@
/*
** $Id: ldebug.c,v 1.147 2003/02/27 12:32:30 roberto Exp roberto $
** $Id: ldebug.c,v 1.148 2003/03/18 12:24:38 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@ -178,9 +178,9 @@ static const char *travglobals (lua_State *L, const TObject *o) {
Table *g = hvalue(gt(L));
int i = sizenode(g);
while (i--) {
Node *n = node(g, i);
if (luaO_rawequalObj(o, val(n)) && ttisstring(key(n)))
return getstr(tsvalue(key(n)));
Node *n = gnode(g, i);
if (luaO_rawequalObj(o, gval(n)) && ttisstring(gkey(n)))
return getstr(tsvalue(gkey(n)));
}
return NULL;
}

6
lfunc.c

@ -1,5 +1,5 @@
/*
** $Id: lfunc.c,v 1.65 2002/12/19 11:11:55 roberto Exp roberto $
** $Id: lfunc.c,v 1.66 2003/02/11 10:46:24 roberto Exp roberto $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
@ -35,11 +35,11 @@ Closure *luaF_newCclosure (lua_State *L, int nelems) {
}
Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *gt) {
Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e) {
Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems)));
luaC_link(L, valtogco(c), LUA_TFUNCTION);
c->l.isC = 0;
c->l.g = *gt;
c->l.g = *e;
c->l.nupvalues = cast(lu_byte, nelems);
return c;
}

4
lfunc.h

@ -1,5 +1,5 @@
/*
** $Id: lfunc.h,v 1.19 2001/11/29 20:22:22 roberto Exp roberto $
** $Id: lfunc.h,v 1.20 2002/06/20 20:41:46 roberto Exp roberto $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
@ -13,7 +13,7 @@
Proto *luaF_newproto (lua_State *L);
Closure *luaF_newCclosure (lua_State *L, int nelems);
Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *gt);
Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e);
UpVal *luaF_findupval (lua_State *L, StkId level);
void luaF_close (lua_State *L, StkId level);
void luaF_freeproto (lua_State *L, Proto *f);

46
lgc.c

@ -1,5 +1,5 @@
/*
** $Id: lgc.c,v 1.168 2003/02/10 17:32:50 roberto Exp roberto $
** $Id: lgc.c,v 1.169 2003/02/11 10:46:24 roberto Exp roberto $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@ -27,7 +27,7 @@ typedef struct GCState {
GCObject *wk; /* list of traversed key-weak tables (to be cleared) */
GCObject *wv; /* list of traversed value-weak tables */
GCObject *wkv; /* list of traversed key-value weak tables */
global_State *G;
global_State *g;
} GCState;
@ -102,7 +102,7 @@ static void reallymarkobject (GCState *st, GCObject *o) {
static void marktmu (GCState *st) {
GCObject *u;
for (u = st->G->tmudata; u; u = u->gch.next) {
for (u = st->g->tmudata; u; u = u->gch.next) {
unmark(u); /* may be marked, if left from previous GC */
reallymarkobject(st, u);
}
@ -138,9 +138,9 @@ void luaC_separateudata (lua_State *L) {
static void removekey (Node *n) {
setnilvalue(val(n)); /* remove corresponding value ... */
if (iscollectable(key(n)))
setttype(key(n), LUA_TNONE); /* dead key; remove it */
setnilvalue(gval(n)); /* remove corresponding value ... */
if (iscollectable(gkey(n)))
setttype(gkey(n), LUA_TNONE); /* dead key; remove it */
}
@ -150,8 +150,8 @@ static void traversetable (GCState *st, Table *h) {
int weakvalue = 0;
const TObject *mode;
markvalue(st, h->metatable);
lua_assert(h->lsizenode || h->node == st->G->dummynode);
mode = gfasttm(st->G, h->metatable, TM_MODE);
lua_assert(h->lsizenode || h->node == st->g->dummynode);
mode = gfasttm(st->g, h->metatable, TM_MODE);
if (mode && ttisstring(mode)) { /* is there a weak mode? */
weakkey = (strchr(svalue(mode), 'k') != NULL);
weakvalue = (strchr(svalue(mode), 'v') != NULL);
@ -167,17 +167,17 @@ static void traversetable (GCState *st, Table *h) {
}
}
if (!weakvalue) {
i = sizearray(h);
i = h->sizearray;
while (i--)
markobject(st, &h->array[i]);
}
i = sizenode(h);
while (i--) {
Node *n = node(h, i);
if (!ttisnil(val(n))) {
lua_assert(!ttisnil(key(n)));
condmarkobject(st, key(n), !weakkey);
condmarkobject(st, val(n), !weakvalue);
Node *n = gnode(h, i);
if (!ttisnil(gval(n))) {
lua_assert(!ttisnil(gkey(n)));
condmarkobject(st, gkey(n), !weakkey);
condmarkobject(st, gval(n), !weakvalue);
}
}
}
@ -303,8 +303,8 @@ static void cleartablekeys (GCObject *l) {
int i = sizenode(h);
lua_assert(h->marked & KEYWEAK);
while (i--) {
Node *n = node(h, i);
if (!valismarked(key(n))) /* key was collected? */
Node *n = gnode(h, i);
if (!valismarked(gkey(n))) /* key was collected? */
removekey(n); /* remove entry from table */
}
l = h->gclist;
@ -318,7 +318,7 @@ static void cleartablekeys (GCObject *l) {
static void cleartablevalues (GCObject *l) {
while (l) {
Table *h = gcotoh(l);
int i = sizearray(h);
int i = h->sizearray;
lua_assert(h->marked & VALUEWEAK);
while (i--) {
TObject *o = &h->array[i];
@ -327,8 +327,8 @@ static void cleartablevalues (GCObject *l) {
}
i = sizenode(h);
while (i--) {
Node *n = node(h, i);
if (!valismarked(val(n))) /* value was collected? */
Node *n = gnode(h, i);
if (!valismarked(gval(n))) /* value was collected? */
removekey(n); /* remove entry from table */
}
l = h->gclist;
@ -441,11 +441,11 @@ void luaC_sweep (lua_State *L, int all) {
/* mark root set */
static void markroot (GCState *st, lua_State *L) {
global_State *G = st->G;
global_State *g = st->g;
markobject(st, defaultmeta(L));
markobject(st, registry(L));
traversestack(st, G->mainthread);
if (L != G->mainthread) /* another thread is running? */
traversestack(st, g->mainthread);
if (L != g->mainthread) /* another thread is running? */
markvalue(st, L); /* cannot collect it */
}
@ -453,7 +453,7 @@ static void markroot (GCState *st, lua_State *L) {
static void mark (lua_State *L) {
GCState st;
GCObject *wkv;
st.G = G(L);
st.g = G(L);
st.tmark = NULL;
st.wkv = st.wk = st.wv = NULL;
markroot(&st, L);

3
lobject.h

@ -1,5 +1,5 @@
/*
** $Id: lobject.h,v 1.157 2003/02/11 10:46:24 roberto Exp roberto $
** $Id: lobject.h,v 1.158 2003/02/18 16:02:56 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@ -316,7 +316,6 @@ typedef struct Table {
#define twoto(x) (1<<(x))
#define sizenode(t) (twoto((t)->lsizenode))
#define sizearray(t) ((t)->sizearray)

6
lstate.c

@ -1,5 +1,5 @@
/*
** $Id: lstate.c,v 1.120 2003/02/13 16:07:57 roberto Exp roberto $
** $Id: lstate.c,v 1.121 2003/02/28 19:45:15 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@ -104,8 +104,8 @@ static void f_luaopen (lua_State *L, void *ud) {
g->rootgc = NULL;
g->rootudata = NULL;
g->tmudata = NULL;
setnilvalue(key(g->dummynode));
setnilvalue(val(g->dummynode));
setnilvalue(gkey(g->dummynode));
setnilvalue(gval(g->dummynode));
g->dummynode->next = NULL;
g->nblocks = sizeof(lua_State) + sizeof(global_State);
stack_init(L, L); /* init stack */

72
ltable.c

@ -1,5 +1,5 @@
/*
** $Id: ltable.c,v 1.127 2003/02/13 16:08:32 roberto Exp roberto $
** $Id: ltable.c,v 1.128 2003/02/20 20:12:39 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@ -56,15 +56,15 @@
#define hashnum(t,n) \
(node(t, lmod(cast(lu_hash, cast(ls_hash, n)), sizenode(t))))
#define hashstr(t,str) (node(t, lmod((str)->tsv.hash, sizenode(t))))
#define hashboolean(t,p) (node(t, lmod(p, sizenode(t))))
(gnode(t, lmod(cast(lu_hash, cast(ls_hash, n)), sizenode(t))))
#define hashstr(t,str) (gnode(t, lmod((str)->tsv.hash, sizenode(t))))
#define hashboolean(t,p) (gnode(t, lmod(p, sizenode(t))))
/*
** avoid modulus by power of 2 for pointers, as they tend to have many
** 2 factors.
*/
#define hashpointer(t,p) (node(t, (IntPoint(p) % ((sizenode(t)-1)|1))))
#define hashpointer(t,p) (gnode(t, (IntPoint(p) % ((sizenode(t)-1)|1))))
/*
@ -122,7 +122,7 @@ static int luaH_index (lua_State *L, Table *t, StkId key) {
if (v == &luaO_nilobject)
luaG_runerror(L, "invalid key for `next'");
i = cast(int, (cast(const lu_byte *, v) -
cast(const lu_byte *, val(node(t, 0)))) / sizeof(Node));
cast(const lu_byte *, gval(gnode(t, 0)))) / sizeof(Node));
return i + t->sizearray; /* hash elements are numbered after array ones */
}
}
@ -138,9 +138,9 @@ int luaH_next (lua_State *L, Table *t, StkId key) {
}
}
for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */
if (!ttisnil(val(node(t, i)))) { /* a non-nil value? */
setobj2s(key, key(node(t, i)));
setobj2s(key+1, val(node(t, i)));
if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */
setobj2s(key, gkey(gnode(t, i)));
setobj2s(key+1, gval(gnode(t, i)));
return 1;
}
}
@ -201,8 +201,8 @@ static void numuse (const Table *t, int *narray, int *nhash) {
i = sizenode(t);
while (i--) {
Node *n = &t->node[i];
if (!ttisnil(val(n))) {
int k = arrayindex(key(n));
if (!ttisnil(gval(n))) {
int k = arrayindex(gkey(n));
if (k >= 0) { /* is `key' an appropriate array index? */
nums[luaO_log2(k-1)+1]++; /* count as such */
(*narray)++;
@ -230,20 +230,20 @@ static void setnodevector (lua_State *L, Table *t, int lsize) {
luaG_runerror(L, "table overflow");
if (lsize == 0) { /* no elements to hash part? */
t->node = G(L)->dummynode; /* use common `dummynode' */
lua_assert(ttisnil(key(t->node))); /* assert invariants: */
lua_assert(ttisnil(val(t->node)));
lua_assert(ttisnil(gkey(t->node))); /* assert invariants: */
lua_assert(ttisnil(gval(t->node)));
lua_assert(t->node->next == NULL); /* (`dummynode' must be empty) */
}
else {
t->node = luaM_newvector(L, size, Node);
for (i=0; i<size; i++) {
t->node[i].next = NULL;
setnilvalue(key(node(t, i)));
setnilvalue(val(node(t, i)));
setnilvalue(gkey(gnode(t, i)));
setnilvalue(gval(gnode(t, i)));
}
}
t->lsizenode = cast(lu_byte, lsize);
t->firstfree = node(t, size-1); /* first free position to be used */
t->firstfree = gnode(t, size-1); /* first free position to be used */
}
@ -259,8 +259,8 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
lua_assert(t->node == G(L)->dummynode);
temp[0] = t->node[0]; /* copy it to `temp' */
nold = temp;
setnilvalue(key(G(L)->dummynode)); /* restate invariant */
setnilvalue(val(G(L)->dummynode));
setnilvalue(gkey(G(L)->dummynode)); /* restate invariant */
setnilvalue(gval(G(L)->dummynode));
lua_assert(G(L)->dummynode->next == NULL);
}
if (nasize > oldasize) /* array part must grow? */
@ -281,8 +281,8 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
/* re-insert elements in hash part */
for (i = twoto(oldhsize) - 1; i >= 0; i--) {
Node *old = nold+i;
if (!ttisnil(val(old)))
setobjt2t(luaH_set(L, t, key(old)), val(old));
if (!ttisnil(gval(old)))
setobjt2t(luaH_set(L, t, gkey(old)), gval(old));
}
if (oldhsize)
luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */
@ -332,7 +332,7 @@ void luaH_free (lua_State *L, Table *t) {
** (because gc can call `remove' during a table traversal)
*/
void luaH_remove (Table *t, Node *e) {
Node *mp = luaH_mainposition(t, key(e));
Node *mp = luaH_mainposition(t, gkey(e));
if (e != mp) { /* element not in its main position? */
while (mp->next != e) mp = mp->next; /* find previous */
mp->next = e->next; /* remove `e' from its list */
@ -340,8 +340,8 @@ void luaH_remove (Table *t, Node *e) {
else {
if (e->next != NULL) ??
}
lua_assert(ttisnil(val(node)));
setnilvalue(key(e)); /* clear node `e' */
lua_assert(ttisnil(gval(node)));
setnilvalue(gkey(e)); /* clear node `e' */
e->next = NULL;
}
#endif
@ -357,8 +357,8 @@ void luaH_remove (Table *t, Node *e) {
static TObject *newkey (lua_State *L, Table *t, const TObject *key) {
TObject *val;
Node *mp = luaH_mainposition(t, key);
if (!ttisnil(val(mp))) { /* main position is not free? */
Node *othern = luaH_mainposition(t, key(mp)); /* `mp' of colliding node */
if (!ttisnil(gval(mp))) { /* main position is not free? */
Node *othern = luaH_mainposition(t, gkey(mp)); /* `mp' of colliding node */
Node *n = t->firstfree; /* get a free place */
if (othern != mp) { /* is colliding node out of its main position? */
/* yes; move colliding node into free position */
@ -366,7 +366,7 @@ static TObject *newkey (lua_State *L, Table *t, const TObject *key) {
othern->next = n; /* redo the chain with `n' in place of `mp' */
*n = *mp; /* copy colliding node into free pos. (mp->next also goes) */
mp->next = NULL; /* now `mp' is free */
setnilvalue(val(mp));
setnilvalue(gval(mp));
}
else { /* colliding node is in its own main position */
/* new node will go into free position */
@ -375,16 +375,16 @@ static TObject *newkey (lua_State *L, Table *t, const TObject *key) {
mp = n;
}
}
setobj2t(key(mp), key); /* write barrier */
lua_assert(ttisnil(val(mp)));
setobj2t(gkey(mp), key); /* write barrier */
lua_assert(ttisnil(gval(mp)));
for (;;) { /* correct `firstfree' */
if (ttisnil(key(t->firstfree)))
return val(mp); /* OK; table still has a free place */
if (ttisnil(gkey(t->firstfree)))
return gval(mp); /* OK; table still has a free place */
else if (t->firstfree == t->node) break; /* cannot decrement from here */
else (t->firstfree)--;
}
/* no more free places; must create one */
setbvalue(val(mp), 0); /* avoid new key being removed */
setbvalue(gval(mp), 0); /* avoid new key being removed */
rehash(L, t); /* grow table */
val = cast(TObject *, luaH_get(t, key)); /* get new position */
lua_assert(ttisboolean(val));
@ -401,7 +401,7 @@ static const TObject *luaH_getany (Table *t, const TObject *key) {
else {
Node *n = luaH_mainposition(t, key);
do { /* check whether `key' is somewhere in the chain */
if (luaO_rawequalObj(key(n), key)) return val(n); /* that's it */
if (luaO_rawequalObj(gkey(n), key)) return gval(n); /* that's it */
else n = n->next;
} while (n);
return &luaO_nilobject;
@ -418,8 +418,8 @@ const TObject *luaH_getnum (Table *t, int key) {
else {
Node *n = hashnum(t, key);
do { /* check whether `key' is somewhere in the chain */
if (ttisnumber(key(n)) && nvalue(key(n)) == (lua_Number)key)
return val(n); /* that's it */
if (ttisnumber(gkey(n)) && nvalue(gkey(n)) == (lua_Number)key)
return gval(n); /* that's it */
else n = n->next;
} while (n);
return &luaO_nilobject;
@ -433,8 +433,8 @@ const TObject *luaH_getnum (Table *t, int key) {
const TObject *luaH_getstr (Table *t, TString *key) {
Node *n = hashstr(t, key);
do { /* check whether `key' is somewhere in the chain */
if (ttisstring(key(n)) && tsvalue(key(n)) == key)
return val(n); /* that's it */
if (ttisstring(gkey(n)) && tsvalue(gkey(n)) == key)
return gval(n); /* that's it */
else n = n->next;
} while (n);
return &luaO_nilobject;

8
ltable.h

@ -1,5 +1,5 @@
/*
** $Id: ltable.h,v 1.42 2002/05/27 20:35:40 roberto Exp roberto $
** $Id: ltable.h,v 1.43 2002/11/07 16:03:33 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@ -10,9 +10,9 @@
#include "lobject.h"
#define node(t,i) (&(t)->node[i])
#define key(n) (&(n)->i_key)
#define val(n) (&(n)->i_val)
#define gnode(t,i) (&(t)->node[i])
#define gkey(n) (&(n)->i_key)
#define gval(n) (&(n)->i_val)
const TObject *luaH_getnum (Table *t, int key);

Loading…
Cancel
Save