diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-05 09:14:08 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-05 09:14:08 -0300 |
commit | 001f2bdd0e2f8803889c1b5164b57a51e44aef5b (patch) | |
tree | d200cf4d708be3c61e64640c45b47050c9c6a375 /lgc.c | |
parent | cd2ddaded97f7f2b2af02cecfd165cf70e6f83f4 (diff) | |
download | lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.tar.gz lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.tar.bz2 lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.zip |
new definition for types-tags
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 60 |
1 files changed, 28 insertions, 32 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.68 2000/09/29 12:42:13 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.69 2000/10/02 14:47:43 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -24,7 +24,7 @@ typedef struct GCState { | |||
24 | 24 | ||
25 | 25 | ||
26 | 26 | ||
27 | static int markobject (GCState *st, TObject *o); | 27 | static void markobject (GCState *st, TObject *o); |
28 | 28 | ||
29 | 29 | ||
30 | /* mark a string; marks larger than 1 cannot be changed */ | 30 | /* mark a string; marks larger than 1 cannot be changed */ |
@@ -73,39 +73,36 @@ static void marktagmethods (lua_State *L, GCState *st) { | |||
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | static int markobject (GCState *st, TObject *o) { | 76 | static void markclosure (GCState *st, Closure *cl) { |
77 | if (!ismarked(cl)) { | ||
78 | if (!cl->isC) | ||
79 | protomark(cl->f.l); | ||
80 | cl->mark = st->cmark; /* chain it for later traversal */ | ||
81 | st->cmark = cl; | ||
82 | } | ||
83 | } | ||
84 | |||
85 | |||
86 | static void markobject (GCState *st, TObject *o) { | ||
77 | switch (ttype(o)) { | 87 | switch (ttype(o)) { |
78 | case TAG_USERDATA: case TAG_STRING: | 88 | case LUA_TUSERDATA: case LUA_TSTRING: |
79 | strmark(tsvalue(o)); | 89 | strmark(tsvalue(o)); |
80 | break; | 90 | break; |
81 | case TAG_TABLE: { | 91 | case LUA_TMARK: |
92 | markclosure(st, infovalue(o)->func); | ||
93 | break; | ||
94 | case LUA_TFUNCTION: | ||
95 | markclosure(st, clvalue(o)); | ||
96 | break; | ||
97 | case LUA_TTABLE: { | ||
82 | if (!ismarked(hvalue(o))) { | 98 | if (!ismarked(hvalue(o))) { |
83 | hvalue(o)->mark = st->tmark; /* chain it in list of marked */ | 99 | hvalue(o)->mark = st->tmark; /* chain it in list of marked */ |
84 | st->tmark = hvalue(o); | 100 | st->tmark = hvalue(o); |
85 | } | 101 | } |
86 | break; | 102 | break; |
87 | } | 103 | } |
88 | case TAG_LMARK: { | ||
89 | Closure *cl = infovalue(o)->func; | ||
90 | if (!ismarked(cl)) { | ||
91 | protomark(cl->f.l); | ||
92 | cl->mark = st->cmark; /* chain it for later traversal */ | ||
93 | st->cmark = cl; | ||
94 | } | ||
95 | break; | ||
96 | } | ||
97 | case TAG_LCLOSURE: | ||
98 | protomark(clvalue(o)->f.l); | ||
99 | /* go through */ | ||
100 | case TAG_CCLOSURE: case TAG_CMARK: | ||
101 | if (!ismarked(clvalue(o))) { | ||
102 | clvalue(o)->mark = st->cmark; /* chain it for later traversal */ | ||
103 | st->cmark = clvalue(o); | ||
104 | } | ||
105 | break; | ||
106 | default: break; /* numbers, etc */ | 104 | default: break; /* numbers, etc */ |
107 | } | 105 | } |
108 | return 0; | ||
109 | } | 106 | } |
110 | 107 | ||
111 | 108 | ||
@@ -131,8 +128,8 @@ static void markall (lua_State *L) { | |||
131 | st.tmark = h->mark; /* remove it from list */ | 128 | st.tmark = h->mark; /* remove it from list */ |
132 | for (i=0; i<h->size; i++) { | 129 | for (i=0; i<h->size; i++) { |
133 | Node *n = node(h, i); | 130 | Node *n = node(h, i); |
134 | if (ttype(key(n)) != TAG_NIL) { | 131 | if (ttype(key(n)) != LUA_TNIL) { |
135 | if (ttype(val(n)) == TAG_NIL) | 132 | if (ttype(val(n)) == LUA_TNIL) |
136 | luaH_remove(h, key(n)); /* dead element; try to remove it */ | 133 | luaH_remove(h, key(n)); /* dead element; try to remove it */ |
137 | markobject(&st, &n->key); | 134 | markobject(&st, &n->key); |
138 | markobject(&st, &n->val); | 135 | markobject(&st, &n->val); |
@@ -147,11 +144,11 @@ static void markall (lua_State *L) { | |||
147 | static int hasmark (const TObject *o) { | 144 | static int hasmark (const TObject *o) { |
148 | /* valid only for locked objects */ | 145 | /* valid only for locked objects */ |
149 | switch (o->ttype) { | 146 | switch (o->ttype) { |
150 | case TAG_STRING: case TAG_USERDATA: | 147 | case LUA_TSTRING: case LUA_TUSERDATA: |
151 | return tsvalue(o)->marked; | 148 | return tsvalue(o)->marked; |
152 | case TAG_TABLE: | 149 | case LUA_TTABLE: |
153 | return ismarked(hvalue(o)); | 150 | return ismarked(hvalue(o)); |
154 | case TAG_LCLOSURE: case TAG_CCLOSURE: | 151 | case LUA_TFUNCTION: |
155 | return ismarked(clvalue(o)); | 152 | return ismarked(clvalue(o)); |
156 | default: /* number */ | 153 | default: /* number */ |
157 | return 1; | 154 | return 1; |
@@ -271,7 +268,6 @@ static void collectudata (lua_State *L, int all) { | |||
271 | } | 268 | } |
272 | else { /* collect */ | 269 | else { /* collect */ |
273 | int tag = next->u.d.tag; | 270 | int tag = next->u.d.tag; |
274 | if (tag > L->last_tag) tag = TAG_USERDATA; | ||
275 | *p = next->nexthash; | 271 | *p = next->nexthash; |
276 | next->nexthash = L->IMtable[tag].collected; /* chain udata */ | 272 | next->nexthash = L->IMtable[tag].collected; /* chain udata */ |
277 | L->IMtable[tag].collected = next; | 273 | L->IMtable[tag].collected = next; |
@@ -297,7 +293,7 @@ static void checkMbuffer (lua_State *L) { | |||
297 | 293 | ||
298 | static void callgcTM (lua_State *L, const TObject *o) { | 294 | static void callgcTM (lua_State *L, const TObject *o) { |
299 | const TObject *im = luaT_getimbyObj(L, o, IM_GC); | 295 | const TObject *im = luaT_getimbyObj(L, o, IM_GC); |
300 | if (ttype(im) != TAG_NIL) { | 296 | if (ttype(im) != LUA_TNIL) { |
301 | int oldah = L->allowhooks; | 297 | int oldah = L->allowhooks; |
302 | L->allowhooks = 0; /* stop debug hooks during GC tag methods */ | 298 | L->allowhooks = 0; /* stop debug hooks during GC tag methods */ |
303 | luaD_checkstack(L, 2); | 299 | luaD_checkstack(L, 2); |
@@ -313,7 +309,7 @@ static void callgcTM (lua_State *L, const TObject *o) { | |||
313 | static void callgcTMudata (lua_State *L) { | 309 | static void callgcTMudata (lua_State *L) { |
314 | int tag; | 310 | int tag; |
315 | TObject o; | 311 | TObject o; |
316 | ttype(&o) = TAG_USERDATA; | 312 | ttype(&o) = LUA_TUSERDATA; |
317 | L->GCthreshold = 2*L->nblocks; /* avoid GC during tag methods */ | 313 | L->GCthreshold = 2*L->nblocks; /* avoid GC during tag methods */ |
318 | for (tag=L->last_tag; tag>=0; tag--) { /* for each tag (in reverse order) */ | 314 | for (tag=L->last_tag; tag>=0; tag--) { /* for each tag (in reverse order) */ |
319 | TString *udata; | 315 | TString *udata; |