diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-09-26 12:02:26 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-09-26 12:02:26 -0300 |
| commit | a580480b07cdf7201306b246deeb2fe84f2c25a9 (patch) | |
| tree | 30e9d4798228156eea5be2589834f1ff2db4355e /lgc.c | |
| parent | 0dd6d1080e7f58eb17cb8a2ad3fc5801ed7c0532 (diff) | |
| download | lua-a580480b07cdf7201306b246deeb2fe84f2c25a9.tar.gz lua-a580480b07cdf7201306b246deeb2fe84f2c25a9.tar.bz2 lua-a580480b07cdf7201306b246deeb2fe84f2c25a9.zip | |
new implementation for globals: Global value is stored in TaggedString
Diffstat (limited to 'lgc.c')
| -rw-r--r-- | lgc.c | 31 |
1 files changed, 21 insertions, 10 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: $ | 2 | ** $Id: lgc.c,v 1.1 1997/09/16 19:25:59 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 | */ |
| @@ -8,7 +8,6 @@ | |||
| 8 | #include "ldo.h" | 8 | #include "ldo.h" |
| 9 | #include "lfunc.h" | 9 | #include "lfunc.h" |
| 10 | #include "lgc.h" | 10 | #include "lgc.h" |
| 11 | #include "lglobal.h" | ||
| 12 | #include "lmem.h" | 11 | #include "lmem.h" |
| 13 | #include "lobject.h" | 12 | #include "lobject.h" |
| 14 | #include "lstring.h" | 13 | #include "lstring.h" |
| @@ -91,7 +90,7 @@ static int ismarked (TObject *o) | |||
| 91 | { | 90 | { |
| 92 | switch (o->ttype) { | 91 | switch (o->ttype) { |
| 93 | case LUA_T_STRING: case LUA_T_USERDATA: | 92 | case LUA_T_STRING: case LUA_T_USERDATA: |
| 94 | return o->value.ts->marked; | 93 | return o->value.ts->head.marked; |
| 95 | case LUA_T_FUNCTION: | 94 | case LUA_T_FUNCTION: |
| 96 | return o->value.cl->head.marked; | 95 | return o->value.cl->head.marked; |
| 97 | case LUA_T_PROTO: | 96 | case LUA_T_PROTO: |
| @@ -129,10 +128,11 @@ static void strcallIM (TaggedString *l) | |||
| 129 | { | 128 | { |
| 130 | TObject o; | 129 | TObject o; |
| 131 | ttype(&o) = LUA_T_USERDATA; | 130 | ttype(&o) = LUA_T_USERDATA; |
| 132 | for (; l; l=l->uu.next) { | 131 | for (; l; l=(TaggedString *)l->head.next) |
| 133 | tsvalue(&o) = l; | 132 | if (l->constindex == -1) { /* is userdata? */ |
| 134 | luaD_gcIM(&o); | 133 | tsvalue(&o) = l; |
| 135 | } | 134 | luaD_gcIM(&o); |
| 135 | } | ||
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | 138 | ||
| @@ -164,8 +164,8 @@ static GCnode *listcollect (GCnode **root) | |||
| 164 | 164 | ||
| 165 | static void strmark (TaggedString *s) | 165 | static void strmark (TaggedString *s) |
| 166 | { | 166 | { |
| 167 | if (!s->marked) | 167 | if (!s->head.marked) |
| 168 | s->marked = 1; | 168 | s->head.marked = 1; |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | 171 | ||
| @@ -215,6 +215,17 @@ static void hashmark (Hash *h) | |||
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | 217 | ||
| 218 | static void globalmark (void) | ||
| 219 | { | ||
| 220 | TaggedString *g; | ||
| 221 | for (g=(TaggedString *)luaS_root.next; g; g=(TaggedString *)g->head.next) | ||
| 222 | if (g->u.globalval.ttype != LUA_T_NIL) { | ||
| 223 | markobject(&g->u.globalval); | ||
| 224 | strmark(g); /* cannot collect non nil global variables */ | ||
| 225 | } | ||
| 226 | } | ||
| 227 | |||
| 228 | |||
| 218 | static int markobject (TObject *o) | 229 | static int markobject (TObject *o) |
| 219 | { | 230 | { |
| 220 | switch (ttype(o)) { | 231 | switch (ttype(o)) { |
| @@ -253,7 +264,7 @@ long luaC_threshold = GARBAGE_BLOCK; | |||
| 253 | static void markall (void) | 264 | static void markall (void) |
| 254 | { | 265 | { |
| 255 | luaD_travstack(markobject); /* mark stack objects */ | 266 | luaD_travstack(markobject); /* mark stack objects */ |
| 256 | luaG_travsymbol(markobject); /* mark symbol table objects */ | 267 | globalmark(); /* mark global variable values and names */ |
| 257 | travlock(); /* mark locked objects */ | 268 | travlock(); /* mark locked objects */ |
| 258 | luaT_travtagmethods(markobject); /* mark fallbacks */ | 269 | luaT_travtagmethods(markobject); /* mark fallbacks */ |
| 259 | } | 270 | } |
