diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-08 16:32:53 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-08 16:32:53 -0300 |
commit | 11a70220670f25a9929439f0b27331f09f05235c (patch) | |
tree | c4a962b5a3e53ac6df8894fb3ad2248c4a1256cb /lgc.c | |
parent | 35a6ed283881f313152457f24cc6c677122d5058 (diff) | |
download | lua-11a70220670f25a9929439f0b27331f09f05235c.tar.gz lua-11a70220670f25a9929439f0b27331f09f05235c.tar.bz2 lua-11a70220670f25a9929439f0b27331f09f05235c.zip |
global variables are stored in a Lua table
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 31 |
1 files changed, 2 insertions, 29 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.46 2000/03/30 20:55:50 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.47 2000/04/14 18:12:35 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 | */ |
@@ -77,18 +77,6 @@ static void hashmark (lua_State *L, Hash *h) { | |||
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
80 | static void travglobal (lua_State *L) { | ||
81 | GlobalVar *gv; | ||
82 | for (gv=L->rootglobal; gv; gv=gv->next) { | ||
83 | LUA_ASSERT(L, gv->name->u.s.gv == gv, "inconsistent global name"); | ||
84 | if (gv->value.ttype != TAG_NIL) { | ||
85 | strmark(L, gv->name); /* cannot collect non nil global variables */ | ||
86 | markobject(L, &gv->value); | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | |||
91 | |||
92 | static void travstack (lua_State *L) { | 80 | static void travstack (lua_State *L) { |
93 | int i; | 81 | int i; |
94 | for (i = (L->top-1)-L->stack; i>=0; i--) | 82 | for (i = (L->top-1)-L->stack; i>=0; i--) |
@@ -174,20 +162,6 @@ static void collecttable (lua_State *L) { | |||
174 | 162 | ||
175 | 163 | ||
176 | /* | 164 | /* |
177 | ** remove from the global list globals whose names will be collected | ||
178 | ** (the global itself is freed when its name is freed) | ||
179 | */ | ||
180 | static void clear_global_list (lua_State *L, int limit) { | ||
181 | GlobalVar **p = &L->rootglobal; | ||
182 | GlobalVar *next; | ||
183 | while ((next = *p) != NULL) { | ||
184 | if (next->name->marked >= limit) p = &next->next; | ||
185 | else *p = next->next; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | |||
190 | /* | ||
191 | ** collect all elements with `marked' < `limit'. | 165 | ** collect all elements with `marked' < `limit'. |
192 | ** with limit=1, that means all unmarked elements; | 166 | ** with limit=1, that means all unmarked elements; |
193 | ** with limit=MAX_INT, that means all elements. | 167 | ** with limit=MAX_INT, that means all elements. |
@@ -196,7 +170,6 @@ static void collectstring (lua_State *L, int limit) { | |||
196 | TObject o; /* to call userdata `gc' tag method */ | 170 | TObject o; /* to call userdata `gc' tag method */ |
197 | int i; | 171 | int i; |
198 | ttype(&o) = TAG_USERDATA; | 172 | ttype(&o) = TAG_USERDATA; |
199 | clear_global_list(L, limit); | ||
200 | for (i=0; i<NUM_HASHS; i++) { /* for each hash table */ | 173 | for (i=0; i<NUM_HASHS; i++) { /* for each hash table */ |
201 | stringtable *tb = &L->string_root[i]; | 174 | stringtable *tb = &L->string_root[i]; |
202 | int j; | 175 | int j; |
@@ -228,7 +201,7 @@ static void collectstring (lua_State *L, int limit) { | |||
228 | 201 | ||
229 | static void markall (lua_State *L) { | 202 | static void markall (lua_State *L) { |
230 | travstack(L); /* mark stack objects */ | 203 | travstack(L); /* mark stack objects */ |
231 | travglobal(L); /* mark global variable values and names */ | 204 | hashmark(L, L->gt); /* mark global variable values and names */ |
232 | travlock(L); /* mark locked objects */ | 205 | travlock(L); /* mark locked objects */ |
233 | luaT_travtagmethods(L, markobject); /* mark tag methods */ | 206 | luaT_travtagmethods(L, markobject); /* mark tag methods */ |
234 | } | 207 | } |