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

This commit is contained in:
Roberto Ierusalimschy 1996-01-26 16:03:19 -02:00
parent 19290a8e92
commit 0d50b87aa4
5 changed files with 15 additions and 30 deletions

View File

@ -1,6 +1,6 @@
/* /*
** TeCGraf - PUC-Rio ** 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 #ifndef opcode_h
@ -94,10 +94,6 @@ typedef struct Object
Value value; Value value;
} Object; } Object;
typedef struct
{
Object object;
} Symbol;
/* Macros to access structure members */ /* Macros to access structure members */
#define tag(o) ((o)->tag) #define tag(o) ((o)->tag)

View File

@ -3,7 +3,7 @@
** Module to control static tables ** 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>*/ /*#include <string.h>*/
@ -101,6 +101,7 @@ Word luaI_findsymbol (TreeNode *t)
lua_table = growvector(lua_table, lua_maxsymbol, Symbol); lua_table = growvector(lua_table, lua_maxsymbol, Symbol);
} }
t->varindex = lua_ntable; t->varindex = lua_ntable;
lua_table[lua_ntable].varname = t;
s_tag(lua_ntable) = LUA_T_NIL; s_tag(lua_ntable) = LUA_T_NIL;
lua_ntable++; lua_ntable++;
} }
@ -155,7 +156,7 @@ static char *lua_travsymbol (int (*fn)(Object *))
Word i; Word i;
for (i=0; i<lua_ntable; i++) for (i=0; i<lua_ntable; i++)
if (fn(&s_object(i))) if (fn(&s_object(i)))
return luaI_nodebysymbol(i)->ts.str; return lua_table[i].varname->ts.str;
return NULL; return NULL;
} }
@ -234,7 +235,7 @@ static void lua_nextvar (void)
} }
else else
{ {
TreeNode *t = luaI_nodebysymbol(next); TreeNode *t = lua_table[next].varname;
Object name; Object name;
tag(&name) = LUA_T_STRING; tag(&name) = LUA_T_STRING;
tsvalue(&name) = &(t->ts); tsvalue(&name) = &(t->ts);

View File

@ -1,7 +1,7 @@
/* /*
** Module to control static tables ** Module to control static tables
** TeCGraf - PUC-Rio ** 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 #ifndef table_h
@ -10,6 +10,13 @@
#include "tree.h" #include "tree.h"
#include "opcode.h" #include "opcode.h"
typedef struct
{
Object object;
TreeNode *varname;
} Symbol;
extern Symbol *lua_table; extern Symbol *lua_table;
extern TaggedString **lua_constant; extern TaggedString **lua_constant;

20
tree.c
View File

@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio ** 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> #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);
}

3
tree.h
View File

@ -1,7 +1,7 @@
/* /*
** tree.h ** tree.h
** TecCGraf - PUC-Rio ** 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 #ifndef tree_h
@ -32,6 +32,5 @@ typedef struct TreeNode
TaggedString *lua_createstring (char *str); TaggedString *lua_createstring (char *str);
TreeNode *lua_constcreate (char *str); TreeNode *lua_constcreate (char *str);
Long lua_strcollector (void); Long lua_strcollector (void);
TreeNode *luaI_nodebysymbol (Word symbol);
#endif #endif