diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-02-14 10:35:51 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-02-14 10:35:51 -0300 |
| commit | d1608c597e2f45021d43c56050aff08e5d417699 (patch) | |
| tree | e6b0a07e68384cd9707e7dda6864dd8664e2ee99 /tree.c | |
| parent | 0f4903a5d79fb594115c5603072d0dce77b2b84e (diff) | |
| download | lua-d1608c597e2f45021d43c56050aff08e5d417699.tar.gz lua-d1608c597e2f45021d43c56050aff08e5d417699.tar.bz2 lua-d1608c597e2f45021d43c56050aff08e5d417699.zip | |
reserved words are stored in main string table; "marked" field is
used to indicate its type.
Table initializations centralized by "tree.c".
Diffstat (limited to 'tree.c')
| -rw-r--r-- | tree.c | 27 |
1 files changed, 19 insertions, 8 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_tree="$Id: tree.c,v 1.15 1996/01/26 18:03:19 roberto Exp $"; | 6 | char *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 | ||
| 29 | static int initialized = 0; | ||
| 30 | |||
| 28 | static stringtable string_root[NUM_HASHS]; | 31 | static stringtable string_root[NUM_HASHS]; |
| 29 | 32 | ||
| 30 | static TaggedString EMPTY = {NOT_USED, NOT_USED, 0, 0, {0}}; | 33 | static TaggedString EMPTY = {NOT_USED, NOT_USED, 0, 0, {0}}; |
| 31 | 34 | ||
| 35 | |||
| 32 | static unsigned long hash (char *str) | 36 | static 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 | ||
| 44 | static void initialize (void) | ||
| 45 | { | ||
| 46 | initialized = 1; | ||
| 47 | luaI_addReserved(); | ||
| 48 | luaI_initsymbol(); | ||
| 49 | luaI_initconstant(); | ||
| 50 | } | ||
| 51 | |||
| 52 | |||
| 40 | static void grow (stringtable *tb) | 53 | static 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 | ||
| 100 | TaggedString *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; |
