aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-01-26 16:03:19 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-01-26 16:03:19 -0200
commit0d50b87aa47d3cb64730bf5c8646e5e6ff02c268 (patch)
treeadfab90a2efad542f12d7d7b0219226deedcb7a5
parent19290a8e92a9b22f448b82c2bcb67ea635dee6ad (diff)
downloadlua-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.h6
-rw-r--r--table.c7
-rw-r--r--table.h9
-rw-r--r--tree.c20
-rw-r--r--tree.h3
5 files changed, 15 insertions, 30 deletions
diff --git a/opcode.h b/opcode.h
index f99c0073..e66c9676 100644
--- a/opcode.h
+++ b/opcode.h
@@ -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
97typedef 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)
diff --git a/table.c b/table.c
index 7c7f124c..587d582d 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.42 1996/01/23 18:39:45 roberto Exp roberto $"; 6char *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);
diff --git a/table.h b/table.h
index a3c10388..cb2ef006 100644
--- a/table.h
+++ b/table.h
@@ -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
13typedef struct
14{
15 Object object;
16 TreeNode *varname;
17} Symbol;
18
19
13extern Symbol *lua_table; 20extern Symbol *lua_table;
14extern TaggedString **lua_constant; 21extern TaggedString **lua_constant;
15 22
diff --git a/tree.c b/tree.c
index 4710ac44..f511436a 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.13 1995/01/12 14:19:04 roberto Exp roberto $"; 6char *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*/
109static 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
119TreeNode *luaI_nodebysymbol (Word symbol)
120{
121 return nodebysymbol(constant_root, symbol);
122}
123
diff --git a/tree.h b/tree.h
index 641765b3..bf6eb27d 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.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
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 *luaI_nodebysymbol (Word symbol);
36 35
37#endif 36#endif