aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-11-29 18:22:22 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-11-29 18:22:22 -0200
commit413fc7334bf8ceaea71417d73edef15c99d3a793 (patch)
tree50e762d979ad8e80681902cdeb8aa42b041ae323 /lgc.c
parentfca0a12e23f964006ce43d35ab86b27c6bbb0a48 (diff)
downloadlua-413fc7334bf8ceaea71417d73edef15c99d3a793.tar.gz
lua-413fc7334bf8ceaea71417d73edef15c99d3a793.tar.bz2
lua-413fc7334bf8ceaea71417d73edef15c99d3a793.zip
new implementation for lua upvalues (sugested by E.T.): simpler and solves
a bug for multi-stacks
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c50
1 files changed, 20 insertions, 30 deletions
diff --git a/lgc.c b/lgc.c
index 418ccd6c..5ea01c77 100644
--- a/lgc.c
+++ b/lgc.c
@@ -65,10 +65,10 @@ static void markclosure (GCState *st, Closure *cl) {
65 lua_assert(cl->l.nupvalues == cl->l.p->nupvalues); 65 lua_assert(cl->l.nupvalues == cl->l.p->nupvalues);
66 protomark(cl->l.p); 66 protomark(cl->l.p);
67 for (i=0; i<cl->l.nupvalues; i++) { /* mark its upvalues */ 67 for (i=0; i<cl->l.nupvalues; i++) { /* mark its upvalues */
68 TObject *u = cl->l.upvals[i]; 68 UpVal *u = cl->l.upvals[i];
69 if (isclosed(u)) { 69 if (!u->mark) {
70 ttype(u-1) = LUA_TNIL; /* temporary value (to mark as visited) */ 70 u->mark = 1;
71 markobject(st, u); 71 markobject(st, u->v);
72 } 72 }
73 } 73 }
74 } 74 }
@@ -101,7 +101,7 @@ static void markobject (GCState *st, TObject *o) {
101 break; 101 break;
102 } 102 }
103 default: { 103 default: {
104 lua_assert(0 <= ttype(o) && ttype(o) <= LUA_TUPVAL); 104 lua_assert(ttype(o) == LUA_TNIL || ttype(o) == LUA_TNUMBER);
105 break; 105 break;
106 } 106 }
107 } 107 }
@@ -241,7 +241,8 @@ static void collectproto (lua_State *L) {
241} 241}
242 242
243 243
244static void collectclosure (lua_State *L, Closure **p) { 244static void collectclosures (lua_State *L) {
245 Closure **p = &G(L)->rootcl;
245 Closure *curr; 246 Closure *curr;
246 while ((curr = *p) != NULL) { 247 while ((curr = *p) != NULL) {
247 if (curr->c.marked) { 248 if (curr->c.marked) {
@@ -256,13 +257,19 @@ static void collectclosure (lua_State *L, Closure **p) {
256} 257}
257 258
258 259
259static void collectclosures (lua_State *L) { 260static void collectupval (lua_State *L) {
260 lua_State *L1 = L; 261 UpVal **v = &G(L)->rootupval;
261 do { /* for each thread */ 262 UpVal *curr;
262 collectclosure(L1, &L1->opencl); 263 while ((curr = *v) != NULL) {
263 L1 = L1->next; 264 if (curr->mark) {
264 } while (L1 != L); 265 curr->mark = 0;
265 collectclosure(L, &G(L)->rootcl); 266 v = &curr->next; /* next */
267 }
268 else {
269 *v = curr->next; /* next */
270 luaM_freelem(L, curr);
271 }
272 }
266} 273}
267 274
268 275
@@ -282,23 +289,6 @@ static void collecttable (lua_State *L) {
282} 289}
283 290
284 291
285static void collectupval (lua_State *L) {
286 TObject **v = &G(L)->rootupval;
287 TObject *curr;
288 while ((curr = *v) != NULL) {
289 if (ttype(curr) == LUA_TNIL) { /* was marked? */
290 ttype(curr) = LUA_HEAPUPVAL; /* unmark */
291 v = &vvalue(curr); /* next */
292 }
293 else {
294 lua_assert(ttype(curr) == LUA_HEAPUPVAL);
295 *v = vvalue(curr); /* next */
296 luaM_freearray(L, curr, 2, TObject);
297 }
298 }
299}
300
301
302static void collectudata (lua_State *L, int keep) { 292static void collectudata (lua_State *L, int keep) {
303 Udata **p = &G(L)->rootudata; 293 Udata **p = &G(L)->rootudata;
304 Udata *curr; 294 Udata *curr;