Browse Source

lua_table now has references to global variable names (TreeNode's).

Roberto Ierusalimschy 29 years ago
parent
commit
0d50b87aa4
5 changed files with 15 additions and 30 deletions
  1. 1 5
      opcode.h
  2. 4 3
      table.c
  3. 8 1
      table.h
  4. 1 19
      tree.c
  5. 1 2
      tree.h

+ 1 - 5
opcode.h

@@ -1,6 +1,6 @@
 /*
 ** TeCGraf - PUC-Rio
-** $Id: opcode.h,v 3.14 1995/10/25 13:05:51 roberto Exp roberto $
+** $Id: opcode.h,v 3.15 1995/12/21 16:14:04 roberto Exp roberto $
 */
 
 #ifndef opcode_h
@@ -94,10 +94,6 @@ typedef struct Object
  Value value;
 } Object;
 
-typedef struct
-{
- Object  object;
-} Symbol;
 
 /* Macros to access structure members */
 #define tag(o)		((o)->tag)

+ 4 - 3
table.c

@@ -3,7 +3,7 @@
 ** Module to control static tables
 */
 
-char *rcs_table="$Id: table.c,v 2.42 1996/01/23 18:39:45 roberto Exp roberto $";
+char *rcs_table="$Id: table.c,v 2.43 1996/01/26 14:04:32 roberto Exp roberto $";
 
 /*#include <string.h>*/
 
@@ -101,6 +101,7 @@ Word luaI_findsymbol (TreeNode *t)
    lua_table = growvector(lua_table, lua_maxsymbol, Symbol);
   }
   t->varindex = lua_ntable;
+  lua_table[lua_ntable].varname = t;
   s_tag(lua_ntable) = LUA_T_NIL;
   lua_ntable++;
  }
@@ -155,7 +156,7 @@ static char *lua_travsymbol (int (*fn)(Object *))
  Word i;
  for (i=0; i<lua_ntable; i++)
   if (fn(&s_object(i)))
-    return luaI_nodebysymbol(i)->ts.str;
+    return lua_table[i].varname->ts.str;
  return NULL;
 }
 
@@ -234,7 +235,7 @@ static void lua_nextvar (void)
  }
  else
  {
-  TreeNode *t = luaI_nodebysymbol(next);
+  TreeNode *t = lua_table[next].varname;
   Object name;
   tag(&name) = LUA_T_STRING;
   tsvalue(&name) = &(t->ts);

+ 8 - 1
table.h

@@ -1,7 +1,7 @@
 /*
 ** Module to control static tables
 ** TeCGraf - PUC-Rio
-** $Id: table.h,v 2.13 1995/10/26 14:21:56 roberto Exp roberto $
+** $Id: table.h,v 2.14 1996/01/22 14:15:13 roberto Exp roberto $
 */
 
 #ifndef table_h
@@ -10,6 +10,13 @@
 #include "tree.h"
 #include "opcode.h"
 
+typedef struct
+{
+ Object  object;
+ TreeNode *varname;
+} Symbol;
+
+
 extern Symbol *lua_table;
 extern TaggedString **lua_constant;
 

+ 1 - 19
tree.c

@@ -3,7 +3,7 @@
 ** TecCGraf - PUC-Rio
 */
  
-char *rcs_tree="$Id: tree.c,v 1.13 1995/01/12 14:19:04 roberto Exp roberto $";
+char *rcs_tree="$Id: tree.c,v 1.14 1995/10/17 11:53:53 roberto Exp roberto $";
 
 
 #include <string.h>
@@ -103,21 +103,3 @@ Long lua_strcollector (void)
 }
 
 
-/*
-** Traverse the constant tree looking for a specific symbol number
-*/
-static TreeNode *nodebysymbol (TreeNode *root, Word symbol)
-{
-  TreeNode *t;
-  if (root == NULL) return NULL;
-  if (root->varindex == symbol) return root;
-  t = nodebysymbol(root->left, symbol);
-  if (t) return t;
-  return nodebysymbol(root->right, symbol);
-}
-
-TreeNode *luaI_nodebysymbol (Word symbol)
-{
-  return nodebysymbol(constant_root, symbol); 
-}
-

+ 1 - 2
tree.h

@@ -1,7 +1,7 @@
 /*
 ** tree.h
 ** TecCGraf - PUC-Rio
-** $Id: tree.h,v 1.9 1995/01/12 14:19:04 roberto Exp roberto $
+** $Id: tree.h,v 1.10 1995/10/17 11:53:53 roberto Exp roberto $
 */
 
 #ifndef tree_h
@@ -32,6 +32,5 @@ typedef struct TreeNode
 TaggedString *lua_createstring (char *str);
 TreeNode *lua_constcreate  (char *str);
 Long lua_strcollector (void);
-TreeNode *luaI_nodebysymbol (Word symbol);
 
 #endif