aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1995-10-17 09:53:53 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1995-10-17 09:53:53 -0200
commit15f40fddca66301a53f8b0adf41958c7e9add945 (patch)
treec3fa93174286f0ce55b43e49610bd9ffffe60408
parent970995c3f258101ae90be4bcb762b6d38bb2b2fd (diff)
downloadlua-15f40fddca66301a53f8b0adf41958c7e9add945.tar.gz
lua-15f40fddca66301a53f8b0adf41958c7e9add945.tar.bz2
lua-15f40fddca66301a53f8b0adf41958c7e9add945.zip
'nextvar' now traverses the symbol array, instead of the constant tree.
-rw-r--r--tree.c42
-rw-r--r--tree.h4
2 files changed, 14 insertions, 32 deletions
diff --git a/tree.c b/tree.c
index c34b0560..4710ac44 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.12 1994/12/20 21:20:36 roberto Exp roberto $"; 6char *rcs_tree="$Id: tree.c,v 1.13 1995/01/12 14:19:04 roberto Exp roberto $";
7 7
8 8
9#include <string.h> 9#include <string.h>
@@ -102,40 +102,22 @@ Long lua_strcollector (void)
102 return counter; 102 return counter;
103} 103}
104 104
105
105/* 106/*
106** Return next variable. 107** Traverse the constant tree looking for a specific symbol number
107*/ 108*/
108static TreeNode *tree_next (TreeNode *node, char *str) 109static TreeNode *nodebysymbol (TreeNode *root, Word symbol)
109{ 110{
110 if (node == NULL) return NULL; 111 TreeNode *t;
111 else if (str == NULL) return node; 112 if (root == NULL) return NULL;
112 else 113 if (root->varindex == symbol) return root;
113 { 114 t = nodebysymbol(root->left, symbol);
114 int c = lua_strcmp(str, node->ts.str); 115 if (t) return t;
115 if (c == 0) 116 return nodebysymbol(root->right, symbol);
116 return node->left != NULL ? node->left : node->right;
117 else if (c < 0)
118 {
119 TreeNode *result = tree_next(node->left, str);
120 return result != NULL ? result : node->right;
121 }
122 else
123 return tree_next(node->right, str);
124 }
125} 117}
126 118
127TreeNode *lua_varnext (char *n) 119TreeNode *luaI_nodebysymbol (Word symbol)
128{ 120{
129 TreeNode *result; 121 return nodebysymbol(constant_root, symbol);
130 char *name = n;
131 while (1)
132 { /* repeat until a valid (non nil) variable */
133 result = tree_next(constant_root, name);
134 if (result == NULL) return NULL;
135 if (result->varindex != NOT_USED &&
136 s_tag(result->varindex) != LUA_T_NIL)
137 return result;
138 name = result->ts.str;
139 }
140} 122}
141 123
diff --git a/tree.h b/tree.h
index f322e833..641765b3 100644
--- a/tree.h
+++ b/tree.h
@@ -1,7 +1,7 @@
1/* 1/*
2** tree.h 2** tree.h
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4** $Id: tree.h,v 1.8 1994/12/20 21:20:36 roberto Exp roberto $ 4** $Id: tree.h,v 1.9 1995/01/12 14:19:04 roberto Exp roberto $
5*/ 5*/
6 6
7#ifndef tree_h 7#ifndef tree_h
@@ -32,6 +32,6 @@ typedef struct TreeNode
32TaggedString *lua_createstring (char *str); 32TaggedString *lua_createstring (char *str);
33TreeNode *lua_constcreate (char *str); 33TreeNode *lua_constcreate (char *str);
34Long lua_strcollector (void); 34Long lua_strcollector (void);
35TreeNode *lua_varnext (char *n); 35TreeNode *luaI_nodebysymbol (Word symbol);
36 36
37#endif 37#endif