diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-23 12:32:00 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-23 12:32:00 -0200 |
| commit | d490555ec9d5efb886211f735694d4e7dd0c166d (patch) | |
| tree | f9b75cdc3a6d4132dddc884280ae218a7f9beb5c /table.c | |
| parent | ad0ec203f60df5e2f8a3b294c9e8c1014280b8f1 (diff) | |
| download | lua-d490555ec9d5efb886211f735694d4e7dd0c166d.tar.gz lua-d490555ec9d5efb886211f735694d4e7dd0c166d.tar.bz2 lua-d490555ec9d5efb886211f735694d4e7dd0c166d.zip | |
garbage collection tag for strings organized in struct TaggedString
Diffstat (limited to 'table.c')
| -rw-r--r-- | table.c | 24 |
1 files changed, 13 insertions, 11 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Module to control static tables | 3 | ** Module to control static tables |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_table="$Id: table.c,v 2.21 1994/11/18 19:27:38 roberto Exp roberto $"; | 6 | char *rcs_table="$Id: table.c,v 2.22 1994/11/21 21:41:09 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | 9 | ||
| @@ -17,13 +17,15 @@ char *rcs_table="$Id: table.c,v 2.21 1994/11/18 19:27:38 roberto Exp roberto $"; | |||
| 17 | #include "fallback.h" | 17 | #include "fallback.h" |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | #define MAX_WORD 0xFFFD | ||
| 21 | |||
| 20 | #define BUFFER_BLOCK 256 | 22 | #define BUFFER_BLOCK 256 |
| 21 | 23 | ||
| 22 | Symbol *lua_table; | 24 | Symbol *lua_table; |
| 23 | static Word lua_ntable = 0; | 25 | static Word lua_ntable = 0; |
| 24 | static Long lua_maxsymbol = 0; | 26 | static Long lua_maxsymbol = 0; |
| 25 | 27 | ||
| 26 | char **lua_constant; | 28 | TaggedString **lua_constant; |
| 27 | static Word lua_nconstant = 0; | 29 | static Word lua_nconstant = 0; |
| 28 | static Long lua_maxconstant = 0; | 30 | static Long lua_maxconstant = 0; |
| 29 | 31 | ||
| @@ -79,7 +81,7 @@ static void lua_initsymbol (void) | |||
| 79 | void lua_initconstant (void) | 81 | void lua_initconstant (void) |
| 80 | { | 82 | { |
| 81 | lua_maxconstant = BUFFER_BLOCK; | 83 | lua_maxconstant = BUFFER_BLOCK; |
| 82 | lua_constant = newvector(lua_maxconstant, char *); | 84 | lua_constant = newvector(lua_maxconstant, TaggedString *); |
| 83 | } | 85 | } |
| 84 | 86 | ||
| 85 | 87 | ||
| @@ -92,7 +94,7 @@ int luaI_findsymbol (TreeNode *t) | |||
| 92 | { | 94 | { |
| 93 | if (lua_table == NULL) | 95 | if (lua_table == NULL) |
| 94 | lua_initsymbol(); | 96 | lua_initsymbol(); |
| 95 | if (t->varindex == UNMARKED_STRING) | 97 | if (t->varindex == NOT_USED) |
| 96 | { | 98 | { |
| 97 | if (lua_ntable == lua_maxsymbol) | 99 | if (lua_ntable == lua_maxsymbol) |
| 98 | { | 100 | { |
| @@ -124,17 +126,17 @@ int luaI_findconstant (TreeNode *t) | |||
| 124 | { | 126 | { |
| 125 | if (lua_constant == NULL) | 127 | if (lua_constant == NULL) |
| 126 | lua_initconstant(); | 128 | lua_initconstant(); |
| 127 | if (t->constindex == UNMARKED_STRING) | 129 | if (t->constindex == NOT_USED) |
| 128 | { | 130 | { |
| 129 | if (lua_nconstant == lua_maxconstant) | 131 | if (lua_nconstant == lua_maxconstant) |
| 130 | { | 132 | { |
| 131 | lua_maxconstant *= 2; | 133 | lua_maxconstant *= 2; |
| 132 | if (lua_maxconstant > MAX_WORD) | 134 | if (lua_maxconstant > MAX_WORD) |
| 133 | lua_error("constant table overflow"); | 135 | lua_error("constant table overflow"); |
| 134 | lua_constant = growvector(lua_constant, lua_maxconstant, char*); | 136 | lua_constant = growvector(lua_constant, lua_maxconstant, TaggedString *); |
| 135 | } | 137 | } |
| 136 | t->constindex = lua_nconstant; | 138 | t->constindex = lua_nconstant; |
| 137 | lua_constant[lua_nconstant] = t->str; | 139 | lua_constant[lua_nconstant] = &(t->ts); |
| 138 | lua_nconstant++; | 140 | lua_nconstant++; |
| 139 | } | 141 | } |
| 140 | return t->constindex; | 142 | return t->constindex; |
| @@ -157,10 +159,10 @@ void lua_travsymbol (void (*fn)(Object *)) | |||
| 157 | */ | 159 | */ |
| 158 | void lua_markobject (Object *o) | 160 | void lua_markobject (Object *o) |
| 159 | { | 161 | { |
| 160 | if (tag(o) == LUA_T_STRING && indexstring(svalue(o)) == UNMARKED_STRING) | 162 | if (tag(o) == LUA_T_STRING && !tsvalue(o)->marked) |
| 161 | indexstring(svalue(o)) = MARKED_STRING; | 163 | tsvalue(o)->marked = 1; |
| 162 | else if (tag(o) == LUA_T_ARRAY) | 164 | else if (tag(o) == LUA_T_ARRAY) |
| 163 | lua_hashmark (avalue(o)); | 165 | lua_hashmark (avalue(o)); |
| 164 | } | 166 | } |
| 165 | 167 | ||
| 166 | 168 | ||
| @@ -247,7 +249,7 @@ static void lua_nextvar (void) | |||
| 247 | { | 249 | { |
| 248 | Object name; | 250 | Object name; |
| 249 | tag(&name) = LUA_T_STRING; | 251 | tag(&name) = LUA_T_STRING; |
| 250 | svalue(&name) = next->str; | 252 | tsvalue(&name) = &(next->ts); |
| 251 | luaI_pushobject(&name); | 253 | luaI_pushobject(&name); |
| 252 | luaI_pushobject(&s_object(next->varindex)); | 254 | luaI_pushobject(&s_object(next->varindex)); |
| 253 | } | 255 | } |
