diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-01-26 16:03:19 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-01-26 16:03:19 -0200 |
commit | 0d50b87aa47d3cb64730bf5c8646e5e6ff02c268 (patch) | |
tree | adfab90a2efad542f12d7d7b0219226deedcb7a5 | |
parent | 19290a8e92a9b22f448b82c2bcb67ea635dee6ad (diff) | |
download | lua-0d50b87aa47d3cb64730bf5c8646e5e6ff02c268.tar.gz lua-0d50b87aa47d3cb64730bf5c8646e5e6ff02c268.tar.bz2 lua-0d50b87aa47d3cb64730bf5c8646e5e6ff02c268.zip |
lua_table now has references to global variable names (TreeNode's).
-rw-r--r-- | opcode.h | 6 | ||||
-rw-r--r-- | table.c | 7 | ||||
-rw-r--r-- | table.h | 9 | ||||
-rw-r--r-- | tree.c | 20 | ||||
-rw-r--r-- | tree.h | 3 |
5 files changed, 15 insertions, 30 deletions
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | ** TeCGraf - PUC-Rio | 2 | ** TeCGraf - PUC-Rio |
3 | ** $Id: opcode.h,v 3.14 1995/10/25 13:05:51 roberto Exp roberto $ | 3 | ** $Id: opcode.h,v 3.15 1995/12/21 16:14:04 roberto Exp roberto $ |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #ifndef opcode_h | 6 | #ifndef opcode_h |
@@ -94,10 +94,6 @@ typedef struct Object | |||
94 | Value value; | 94 | Value value; |
95 | } Object; | 95 | } Object; |
96 | 96 | ||
97 | typedef struct | ||
98 | { | ||
99 | Object object; | ||
100 | } Symbol; | ||
101 | 97 | ||
102 | /* Macros to access structure members */ | 98 | /* Macros to access structure members */ |
103 | #define tag(o) ((o)->tag) | 99 | #define tag(o) ((o)->tag) |
@@ -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.42 1996/01/23 18:39:45 roberto Exp roberto $"; | 6 | char *rcs_table="$Id: table.c,v 2.43 1996/01/26 14:04:32 roberto Exp roberto $"; |
7 | 7 | ||
8 | /*#include <string.h>*/ | 8 | /*#include <string.h>*/ |
9 | 9 | ||
@@ -101,6 +101,7 @@ Word luaI_findsymbol (TreeNode *t) | |||
101 | lua_table = growvector(lua_table, lua_maxsymbol, Symbol); | 101 | lua_table = growvector(lua_table, lua_maxsymbol, Symbol); |
102 | } | 102 | } |
103 | t->varindex = lua_ntable; | 103 | t->varindex = lua_ntable; |
104 | lua_table[lua_ntable].varname = t; | ||
104 | s_tag(lua_ntable) = LUA_T_NIL; | 105 | s_tag(lua_ntable) = LUA_T_NIL; |
105 | lua_ntable++; | 106 | lua_ntable++; |
106 | } | 107 | } |
@@ -155,7 +156,7 @@ static char *lua_travsymbol (int (*fn)(Object *)) | |||
155 | Word i; | 156 | Word i; |
156 | for (i=0; i<lua_ntable; i++) | 157 | for (i=0; i<lua_ntable; i++) |
157 | if (fn(&s_object(i))) | 158 | if (fn(&s_object(i))) |
158 | return luaI_nodebysymbol(i)->ts.str; | 159 | return lua_table[i].varname->ts.str; |
159 | return NULL; | 160 | return NULL; |
160 | } | 161 | } |
161 | 162 | ||
@@ -234,7 +235,7 @@ static void lua_nextvar (void) | |||
234 | } | 235 | } |
235 | else | 236 | else |
236 | { | 237 | { |
237 | TreeNode *t = luaI_nodebysymbol(next); | 238 | TreeNode *t = lua_table[next].varname; |
238 | Object name; | 239 | Object name; |
239 | tag(&name) = LUA_T_STRING; | 240 | tag(&name) = LUA_T_STRING; |
240 | tsvalue(&name) = &(t->ts); | 241 | tsvalue(&name) = &(t->ts); |
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | ** Module to control static tables | 2 | ** Module to control static tables |
3 | ** TeCGraf - PUC-Rio | 3 | ** TeCGraf - PUC-Rio |
4 | ** $Id: table.h,v 2.13 1995/10/26 14:21:56 roberto Exp roberto $ | 4 | ** $Id: table.h,v 2.14 1996/01/22 14:15:13 roberto Exp roberto $ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef table_h | 7 | #ifndef table_h |
@@ -10,6 +10,13 @@ | |||
10 | #include "tree.h" | 10 | #include "tree.h" |
11 | #include "opcode.h" | 11 | #include "opcode.h" |
12 | 12 | ||
13 | typedef struct | ||
14 | { | ||
15 | Object object; | ||
16 | TreeNode *varname; | ||
17 | } Symbol; | ||
18 | |||
19 | |||
13 | extern Symbol *lua_table; | 20 | extern Symbol *lua_table; |
14 | extern TaggedString **lua_constant; | 21 | extern TaggedString **lua_constant; |
15 | 22 | ||
@@ -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.13 1995/01/12 14:19:04 roberto Exp roberto $"; | 6 | char *rcs_tree="$Id: tree.c,v 1.14 1995/10/17 11:53:53 roberto Exp roberto $"; |
7 | 7 | ||
8 | 8 | ||
9 | #include <string.h> | 9 | #include <string.h> |
@@ -103,21 +103,3 @@ Long lua_strcollector (void) | |||
103 | } | 103 | } |
104 | 104 | ||
105 | 105 | ||
106 | /* | ||
107 | ** Traverse the constant tree looking for a specific symbol number | ||
108 | */ | ||
109 | static TreeNode *nodebysymbol (TreeNode *root, Word symbol) | ||
110 | { | ||
111 | TreeNode *t; | ||
112 | if (root == NULL) return NULL; | ||
113 | if (root->varindex == symbol) return root; | ||
114 | t = nodebysymbol(root->left, symbol); | ||
115 | if (t) return t; | ||
116 | return nodebysymbol(root->right, symbol); | ||
117 | } | ||
118 | |||
119 | TreeNode *luaI_nodebysymbol (Word symbol) | ||
120 | { | ||
121 | return nodebysymbol(constant_root, symbol); | ||
122 | } | ||
123 | |||
@@ -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.9 1995/01/12 14:19:04 roberto Exp roberto $ | 4 | ** $Id: tree.h,v 1.10 1995/10/17 11:53:53 roberto Exp roberto $ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef tree_h | 7 | #ifndef tree_h |
@@ -32,6 +32,5 @@ typedef struct TreeNode | |||
32 | TaggedString *lua_createstring (char *str); | 32 | TaggedString *lua_createstring (char *str); |
33 | TreeNode *lua_constcreate (char *str); | 33 | TreeNode *lua_constcreate (char *str); |
34 | Long lua_strcollector (void); | 34 | Long lua_strcollector (void); |
35 | TreeNode *luaI_nodebysymbol (Word symbol); | ||
36 | 35 | ||
37 | #endif | 36 | #endif |