summaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-01-30 15:26:44 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-01-30 15:26:44 -0200
commitd6fd33e76fdeb919fd91860aa9d0f9524e6d415a (patch)
treef2347c99a8d57564b22e622d405f5c3d03061982 /lgc.c
parent50e29525936be4891f9db090f293432913b5f7c0 (diff)
downloadlua-d6fd33e76fdeb919fd91860aa9d0f9524e6d415a.tar.gz
lua-d6fd33e76fdeb919fd91860aa9d0f9524e6d415a.tar.bz2
lua-d6fd33e76fdeb919fd91860aa9d0f9524e6d415a.zip
`eventtable' renamed to `metatable'
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/lgc.c b/lgc.c
index fe098467..facdaf0b 100644
--- a/lgc.c
+++ b/lgc.c
@@ -122,13 +122,12 @@ static void markobject (GCState *st, TObject *o) {
122} 122}
123 123
124 124
125static void checkstacksizes (lua_State *L, StkId lim) { 125static void checkstacksizes (lua_State *L) {
126 int used = L->ci - L->base_ci; /* number of `ci' in use */ 126 int used = L->ci - L->base_ci; /* number of `ci' in use */
127 if (4*used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) 127 if (4*used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)
128 luaD_reallocCI(L, L->size_ci/2); /* still big enough... */ 128 luaD_reallocCI(L, L->size_ci/2); /* still big enough... */
129 if (lim < L->top) lim = L->top; 129 used = L->top - L->stack; /* part of stack in use */
130 used = lim - L->stack; /* part of stack in use */ 130 if (2*(used+MAXSTACK) < L->stacksize && 2*BASIC_STACK_SIZE < L->stacksize)
131 if (3*used < L->stacksize && 2*BASIC_STACK_SIZE < L->stacksize)
132 luaD_reallocstack(L, L->stacksize/2); /* still big enough... */ 131 luaD_reallocstack(L, L->stacksize/2); /* still big enough... */
133} 132}
134 133
@@ -148,7 +147,7 @@ static void markstacks (GCState *st) {
148 lim = (L1->stack_last - L1->ci->base > MAXSTACK) ? L1->ci->base+MAXSTACK 147 lim = (L1->stack_last - L1->ci->base > MAXSTACK) ? L1->ci->base+MAXSTACK
149 : L1->stack_last; 148 : L1->stack_last;
150 for (; o<=lim; o++) setnilvalue(o); 149 for (; o<=lim; o++) setnilvalue(o);
151 checkstacksizes(L1, lim); 150 checkstacksizes(L1);
152 lua_assert(L1->previous->next == L1 && L1->next->previous == L1); 151 lua_assert(L1->previous->next == L1 && L1->next->previous == L1);
153 L1 = L1->next; 152 L1 = L1->next;
154 } while (L1 != st->L); 153 } while (L1 != st->L);
@@ -158,9 +157,9 @@ static void markstacks (GCState *st) {
158static void markudet (GCState *st) { 157static void markudet (GCState *st) {
159 Udata *u; 158 Udata *u;
160 for (u = G(st->L)->rootudata; u; u = u->uv.next) 159 for (u = G(st->L)->rootudata; u; u = u->uv.next)
161 marktable(st, u->uv.eventtable); 160 marktable(st, u->uv.metatable);
162 for (u = G(st->L)->tmudata; u; u = u->uv.next) 161 for (u = G(st->L)->tmudata; u; u = u->uv.next)
163 marktable(st, u->uv.eventtable); 162 marktable(st, u->uv.metatable);
164} 163}
165 164
166 165
@@ -176,8 +175,8 @@ static void traversetable (GCState *st, Table *h) {
176 const TObject *mode; 175 const TObject *mode;
177 int weakkey = 0; 176 int weakkey = 0;
178 int weakvalue = 0; 177 int weakvalue = 0;
179 marktable(st, h->eventtable); 178 marktable(st, h->metatable);
180 mode = fasttm(st->L, h->eventtable, TM_WEAKMODE); 179 mode = fasttm(st->L, h->metatable, TM_WEAKMODE);
181 if (mode) { /* weak table? must be cleared after GC... */ 180 if (mode) { /* weak table? must be cleared after GC... */
182 h->mark = st->toclear; /* put in the appropriate list */ 181 h->mark = st->toclear; /* put in the appropriate list */
183 st->toclear = h; 182 st->toclear = h;
@@ -204,10 +203,10 @@ static void traversetable (GCState *st, Table *h) {
204 203
205 204
206static void markall (GCState *st) { 205static void markall (GCState *st) {
207 lua_assert(hvalue(defaultet(st->L))->flags == cast(unsigned short, ~0)); 206 lua_assert(hvalue(defaultmeta(st->L))->flags == cast(unsigned short, ~0));
208 /* table is unchanged */ 207 /* table is unchanged */
209 markstacks(st); /* mark all stacks */ 208 markstacks(st); /* mark all stacks */
210 markudet(st); /* mark userdata's event tables */ 209 markudet(st); /* mark userdata's meta tables */
211 while (st->tmark) { /* traverse marked tables */ 210 while (st->tmark) { /* traverse marked tables */
212 Table *h = st->tmark; /* get first table from list */ 211 Table *h = st->tmark; /* get first table from list */
213 st->tmark = h->mark; /* remove it from list */ 212 st->tmark = h->mark; /* remove it from list */
@@ -333,7 +332,7 @@ static void collectudata (lua_State *L) {
333 } 332 }
334 else { 333 else {
335 *p = curr->uv.next; 334 *p = curr->uv.next;
336 if (fasttm(L, curr->uv.eventtable, TM_GC) != NULL) { /* gc event? */ 335 if (fasttm(L, curr->uv.metatable, TM_GC) != NULL) { /* gc event? */
337 curr->uv.next = NULL; /* link `curr' at the end of `collected' list */ 336 curr->uv.next = NULL; /* link `curr' at the end of `collected' list */
338 *lastcollected = curr; 337 *lastcollected = curr;
339 lastcollected = &curr->uv.next; 338 lastcollected = &curr->uv.next;
@@ -384,7 +383,7 @@ static void checkMbuffer (lua_State *L) {
384 383
385 384
386static void do1gcTM (lua_State *L, Udata *udata) { 385static void do1gcTM (lua_State *L, Udata *udata) {
387 const TObject *tm = fasttm(L, udata->uv.eventtable, TM_GC); 386 const TObject *tm = fasttm(L, udata->uv.metatable, TM_GC);
388 if (tm != NULL) { 387 if (tm != NULL) {
389 setobj(L->top, tm); 388 setobj(L->top, tm);
390 setuvalue(L->top+1, udata); 389 setuvalue(L->top+1, udata);
@@ -405,8 +404,8 @@ static void unprotectedcallGCTM (lua_State *L, void *pu) {
405 udata->uv.next = G(L)->rootudata; /* resurect it */ 404 udata->uv.next = G(L)->rootudata; /* resurect it */
406 G(L)->rootudata = udata; 405 G(L)->rootudata = udata;
407 do1gcTM(L, udata); 406 do1gcTM(L, udata);
408 /* mark udata as finalized (default event table) */ 407 /* mark udata as finalized (default meta table) */
409 uvalue(L->top-1)->uv.eventtable = hvalue(defaultet(L)); 408 uvalue(L->top-1)->uv.metatable = hvalue(defaultmeta(L));
410 unmarkud(uvalue(L->top-1)); 409 unmarkud(uvalue(L->top-1));
411 } 410 }
412 L->top--; 411 L->top--;
@@ -420,8 +419,8 @@ static void callGCTM (lua_State *L) {
420 Udata *udata; 419 Udata *udata;
421 if (luaD_runprotected(L, unprotectedcallGCTM, &udata) != 0) { 420 if (luaD_runprotected(L, unprotectedcallGCTM, &udata) != 0) {
422 /* `udata' generated an error during its gc */ 421 /* `udata' generated an error during its gc */
423 /* mark it as finalized (default event table) */ 422 /* mark it as finalized (default meta table) */
424 udata->uv.eventtable = hvalue(defaultet(L)); 423 udata->uv.metatable = hvalue(defaultmeta(L));
425 } 424 }
426 } 425 }
427 L->allowhooks = oldah; /* restore hooks */ 426 L->allowhooks = oldah; /* restore hooks */