aboutsummaryrefslogtreecommitdiff
path: root/table.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-07-30 19:00:50 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-07-30 19:00:50 -0300
commit0892f0e5b75c51f1fee07276a3ba13301b83409e (patch)
tree9f3b9ec92f26c05a85c826ffc5f803fda2f48867 /table.c
parent1d7857bc635c0bfe7c5b1f325d31feb7660e9a5a (diff)
downloadlua-0892f0e5b75c51f1fee07276a3ba13301b83409e.tar.gz
lua-0892f0e5b75c51f1fee07276a3ba13301b83409e.tar.bz2
lua-0892f0e5b75c51f1fee07276a3ba13301b83409e.zip
BIG CHANGE: functions have their own "constant table".
Diffstat (limited to 'table.c')
-rw-r--r--table.c60
1 files changed, 23 insertions, 37 deletions
diff --git a/table.c b/table.c
index 47ecd2e2..7420f68e 100644
--- a/table.c
+++ b/table.c
@@ -3,7 +3,7 @@
3** Module to control static tables 3** Module to control static tables
4*/ 4*/
5 5
6char *rcs_table="$Id: table.c,v 2.72 1997/06/17 18:09:31 roberto Exp roberto $"; 6char *rcs_table="$Id: table.c,v 2.73 1997/07/07 16:44:26 roberto Exp roberto $";
7 7
8#include "luamem.h" 8#include "luamem.h"
9#include "auxlib.h" 9#include "auxlib.h"
@@ -24,14 +24,17 @@ Symbol *lua_table = NULL;
24Word lua_ntable = 0; 24Word lua_ntable = 0;
25static Long lua_maxsymbol = 0; 25static Long lua_maxsymbol = 0;
26 26
27TaggedString **lua_constant = NULL;
28Word lua_nconstant = 0;
29static Long lua_maxconstant = 0;
30
31 27
32#define GARBAGE_BLOCK 100 28#define GARBAGE_BLOCK 100
33 29
34 30
31static TaggedString *luaI_createfixedstring (char *name)
32{
33 TaggedString *ts = luaI_createstring(name);
34 luaI_fixstring(ts);
35 return ts;
36}
37
35void luaI_initsymbol (void) 38void luaI_initsymbol (void)
36{ 39{
37 lua_maxsymbol = BUFFER_BLOCK; 40 lua_maxsymbol = BUFFER_BLOCK;
@@ -40,16 +43,11 @@ void luaI_initsymbol (void)
40} 43}
41 44
42 45
43/*
44** Initialise constant table with pre-defined constants
45*/
46void luaI_initconstant (void) 46void luaI_initconstant (void)
47{ 47{
48 lua_maxconstant = BUFFER_BLOCK; 48 /* pre-register mem error messages, to avoid loop when error arises */
49 lua_constant = newvector(lua_maxconstant, TaggedString *); 49 luaI_createfixedstring(tableEM);
50 /* pre-register mem error messages, to avoid loop when error arises */ 50 luaI_createfixedstring(memEM);
51 luaI_findconstantbyname(tableEM);
52 luaI_findconstantbyname(memEM);
53} 51}
54 52
55 53
@@ -79,35 +77,25 @@ Word luaI_findsymbolbyname (char *name)
79} 77}
80 78
81 79
82/* 80void luaI_releasestring (TaggedString *t)
83** Given a tree node, check it is has a correspondent constant index. If not,
84** allocate it.
85*/
86Word luaI_findconstant (TaggedString *t)
87{ 81{
88 if (t->u.s.constindex == NOT_USED) 82 if (t->marked == 2) /* string has temporary mark? */
89 { 83 t->marked = 0;
90 if (lua_nconstant == lua_maxconstant)
91 lua_maxconstant = growvector(&lua_constant, lua_maxconstant, TaggedString *,
92 constantEM, MAX_WORD);
93 t->u.s.constindex = lua_nconstant;
94 lua_constant[lua_nconstant] = t;
95 lua_nconstant++;
96 }
97 return t->u.s.constindex;
98} 84}
99 85
100 86
101Word luaI_findconstantbyname (char *name) 87void luaI_fixstring (TaggedString *t)
102{ 88{
103 return luaI_findconstant(luaI_createfixedstring(name)); 89 if (t->marked < 3)
90 t->marked = 3; /* avoid GC */
104} 91}
105 92
106TaggedString *luaI_createfixedstring (char *name) 93
94TaggedString *luaI_createtempstring (char *name)
107{ 95{
108 TaggedString *ts = lua_createstring(name); 96 TaggedString *ts = luaI_createstring(name);
109 if (!ts->marked) 97 if (!ts->marked)
110 ts->marked = 2; /* avoid GC */ 98 ts->marked = 2; /* avoid (temporarily) GC */
111 return ts; 99 return ts;
112} 100}
113 101
@@ -131,9 +119,6 @@ static char *lua_travsymbol (int (*fn)(TObject *))
131} 119}
132 120
133 121
134/*
135** Mark an object if it is a string or a unmarked array.
136*/
137int lua_markobject (TObject *o) 122int lua_markobject (TObject *o)
138{/* if already marked, does not change mark value */ 123{/* if already marked, does not change mark value */
139 if (ttype(o) == LUA_T_USERDATA || 124 if (ttype(o) == LUA_T_USERDATA ||
@@ -143,7 +128,7 @@ int lua_markobject (TObject *o)
143 lua_hashmark (avalue(o)); 128 lua_hashmark (avalue(o));
144 else if ((o->ttype == LUA_T_FUNCTION || o->ttype == LUA_T_MARK) 129 else if ((o->ttype == LUA_T_FUNCTION || o->ttype == LUA_T_MARK)
145 && !o->value.tf->marked) 130 && !o->value.tf->marked)
146 o->value.tf->marked = 1; 131 luaI_funcmark(o->value.tf);
147 return 0; 132 return 0;
148} 133}
149 134
@@ -208,6 +193,7 @@ long lua_collectgarbage (long limit)
208 luaI_hashfree(freetable); 193 luaI_hashfree(freetable);
209 luaI_strfree(freestr); 194 luaI_strfree(freestr);
210 luaI_funcfree(freefunc); 195 luaI_funcfree(freefunc);
196/*printf("total %d coletados %d\n", (int)gc_nentity, (int)recovered);*/
211 return recovered; 197 return recovered;
212} 198}
213 199