aboutsummaryrefslogtreecommitdiff
path: root/tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/tree.c b/tree.c
index 3b82dc9a..66577a78 100644
--- a/tree.c
+++ b/tree.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_tree="$Id: tree.c,v 1.15 1996/01/26 18:03:19 roberto Exp $"; 6char *rcs_tree="$Id: tree.c,v 1.16 1996/02/12 18:32:40 roberto Exp roberto $";
7 7
8 8
9#include <string.h> 9#include <string.h>
@@ -11,6 +11,7 @@ char *rcs_tree="$Id: tree.c,v 1.15 1996/01/26 18:03:19 roberto Exp $";
11#include "mem.h" 11#include "mem.h"
12#include "lua.h" 12#include "lua.h"
13#include "tree.h" 13#include "tree.h"
14#include "lex.h"
14#include "hash.h" 15#include "hash.h"
15#include "table.h" 16#include "table.h"
16 17
@@ -25,10 +26,13 @@ typedef struct {
25 TaggedString **hash; 26 TaggedString **hash;
26} stringtable; 27} stringtable;
27 28
29static int initialized = 0;
30
28static stringtable string_root[NUM_HASHS]; 31static stringtable string_root[NUM_HASHS];
29 32
30static TaggedString EMPTY = {NOT_USED, NOT_USED, 0, 0, {0}}; 33static TaggedString EMPTY = {NOT_USED, NOT_USED, 0, 0, {0}};
31 34
35
32static unsigned long hash (char *str) 36static unsigned long hash (char *str)
33{ 37{
34 unsigned long h = 0; 38 unsigned long h = 0;
@@ -37,6 +41,15 @@ static unsigned long hash (char *str)
37 return h; 41 return h;
38} 42}
39 43
44static void initialize (void)
45{
46 initialized = 1;
47 luaI_addReserved();
48 luaI_initsymbol();
49 luaI_initconstant();
50}
51
52
40static void grow (stringtable *tb) 53static void grow (stringtable *tb)
41{ 54{
42 int newsize = luaI_redimension(tb->size); 55 int newsize = luaI_redimension(tb->size);
@@ -69,7 +82,11 @@ static TaggedString *insert (char *str, stringtable *tb)
69 int i; 82 int i;
70 int j = -1; 83 int j = -1;
71 if ((Long)tb->nuse*3 >= (Long)tb->size*2) 84 if ((Long)tb->nuse*3 >= (Long)tb->size*2)
85 {
86 if (!initialized)
87 initialize();
72 grow(tb); 88 grow(tb);
89 }
73 i = h%tb->size; 90 i = h%tb->size;
74 while (tb->hash[i]) 91 while (tb->hash[i])
75 { 92 {
@@ -97,12 +114,6 @@ TaggedString *lua_createstring (char *str)
97 return insert(str, &string_root[(unsigned)str[0]%NUM_HASHS]); 114 return insert(str, &string_root[(unsigned)str[0]%NUM_HASHS]);
98} 115}
99 116
100TaggedString *luaI_createfixedstring (char *str)
101{
102 TaggedString *ts = lua_createstring(str);
103 ts->marked = 2; /* to avoid GC */
104 return ts;
105}
106 117
107/* 118/*
108** Garbage collection function. 119** Garbage collection function.
@@ -119,7 +130,7 @@ Long lua_strcollector (void)
119 for (j=0; j<tb->size; j++) 130 for (j=0; j<tb->size; j++)
120 { 131 {
121 TaggedString *t = tb->hash[j]; 132 TaggedString *t = tb->hash[j];
122 if (t != NULL && t != &EMPTY && t->marked != 2) 133 if (t != NULL && t != &EMPTY && t->marked <= 1)
123 { 134 {
124 if (t->marked) 135 if (t->marked)
125 t->marked = 0; 136 t->marked = 0;