aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-16 14:03:48 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-16 14:03:48 -0200
commit94686ce58554a80374eeff115ee5b87c184ed173 (patch)
tree9b41f32a05a41f7063df180015c13c5d9ae1d4a0
parent86b35cf4f6a824880239069d0afe282e95806aaa (diff)
downloadlua-94686ce58554a80374eeff115ee5b87c184ed173.tar.gz
lua-94686ce58554a80374eeff115ee5b87c184ed173.tar.bz2
lua-94686ce58554a80374eeff115ee5b87c184ed173.zip
correction of function 'nextvar'
-rw-r--r--opcode.c58
-rw-r--r--table.c13
-rw-r--r--table.h3
-rw-r--r--tree.c17
-rw-r--r--tree.h4
5 files changed, 41 insertions, 54 deletions
diff --git a/opcode.c b/opcode.c
index 263e9035..7f5f8bd6 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 3.10 1994/11/11 14:00:08 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 3.11 1994/11/13 16:17:04 roberto Exp $";
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <stdlib.h> 9#include <stdlib.h>
@@ -117,14 +117,14 @@ static void lua_checkstack (Word n)
117 117
118 118
119/* 119/*
120** Concatenate two given strings, creating a mark space at the beginning. 120** Concatenate two given strings. Return the new string pointer.
121** Return the new string pointer.
122*/ 121*/
123static char *lua_strconc (char *l, char *r) 122static char *lua_strconc (char *l, char *r)
124{ 123{
125 static char *buffer = NULL; 124 static char *buffer = NULL;
126 static int buffer_size = 0; 125 static int buffer_size = 0;
127 int n = strlen(l)+strlen(r)+1; 126 int nl = strlen(l);
127 int n = nl+strlen(r)+1;
128 if (n > buffer_size) 128 if (n > buffer_size)
129 { 129 {
130 buffer_size = n; 130 buffer_size = n;
@@ -137,7 +137,9 @@ static char *lua_strconc (char *l, char *r)
137 lua_error("concat - not enough memory"); 137 lua_error("concat - not enough memory");
138 } 138 }
139 } 139 }
140 return strcat(strcpy(buffer,l),r); 140 strcpy(buffer,l);
141 strcpy(buffer+nl, r);
142 return buffer;
141} 143}
142 144
143 145
@@ -373,7 +375,7 @@ int lua_callfunction (lua_Object function)
373 375
374int lua_call (char *funcname) 376int lua_call (char *funcname)
375{ 377{
376 int n = lua_findsymbol(funcname); 378 int n = luaI_findsymbolbyname(funcname);
377 return do_protectedrun(&s_object(n), MULT_RET); 379 return do_protectedrun(&s_object(n), MULT_RET);
378} 380}
379 381
@@ -548,7 +550,7 @@ lua_Object lua_getlocked (int ref)
548*/ 550*/
549lua_Object lua_getglobal (char *name) 551lua_Object lua_getglobal (char *name)
550{ 552{
551 int n = lua_findsymbol(name); 553 int n = luaI_findsymbolbyname(name);
552 adjustC(0); 554 adjustC(0);
553 *(top++) = s_object(n); 555 *(top++) = s_object(n);
554 CBase++; /* incorporate object in the stack */ 556 CBase++; /* incorporate object in the stack */
@@ -561,7 +563,7 @@ lua_Object lua_getglobal (char *name)
561*/ 563*/
562int lua_storeglobal (char *name) 564int lua_storeglobal (char *name)
563{ 565{
564 int n = lua_findsymbol (name); 566 int n = luaI_findsymbolbyname(name);
565 if (n < 0) return 1; 567 if (n < 0) return 1;
566 adjustC(1); 568 adjustC(1);
567 s_object(n) = *(--top); 569 s_object(n) = *(--top);
@@ -698,9 +700,10 @@ static int lua_execute (Byte *pc, int base)
698 { 700 {
699 case PUSHNIL: tag(top++) = LUA_T_NIL; break; 701 case PUSHNIL: tag(top++) = LUA_T_NIL; break;
700 702
701 case PUSH0: tag(top) = LUA_T_NUMBER; nvalue(top++) = 0; break; 703 case PUSH0: case PUSH1: case PUSH2:
702 case PUSH1: tag(top) = LUA_T_NUMBER; nvalue(top++) = 1; break; 704 tag(top) = LUA_T_NUMBER;
703 case PUSH2: tag(top) = LUA_T_NUMBER; nvalue(top++) = 2; break; 705 nvalue(top++) = opcode-PUSH0;
706 break;
704 707
705 case PUSHBYTE: tag(top) = LUA_T_NUMBER; nvalue(top++) = *pc++; break; 708 case PUSHBYTE: tag(top) = LUA_T_NUMBER; nvalue(top++) = *pc++; break;
706 709
@@ -813,8 +816,6 @@ static int lua_execute (Byte *pc, int base)
813 else m = *(pc++) * FIELDS_PER_FLUSH; 816 else m = *(pc++) * FIELDS_PER_FLUSH;
814 n = *(pc++); 817 n = *(pc++);
815 arr = top-n-1; 818 arr = top-n-1;
816 if (tag(arr) != LUA_T_ARRAY)
817 lua_reportbug ("internal error - table expected");
818 while (n) 819 while (n)
819 { 820 {
820 tag(top) = LUA_T_NUMBER; nvalue(top) = n+m; 821 tag(top) = LUA_T_NUMBER; nvalue(top) = n+m;
@@ -829,8 +830,6 @@ static int lua_execute (Byte *pc, int base)
829 { 830 {
830 int n = *(pc++); 831 int n = *(pc++);
831 Object *arr = top-n-1; 832 Object *arr = top-n-1;
832 if (tag(arr) != LUA_T_ARRAY)
833 lua_reportbug ("internal error - table expected");
834 while (n) 833 while (n)
835 { 834 {
836 CodeWord code; 835 CodeWord code;
@@ -856,39 +855,15 @@ static int lua_execute (Byte *pc, int base)
856 CodeWord size; 855 CodeWord size;
857 get_word(size,pc); 856 get_word(size,pc);
858 top++; 857 top++;
859 avalue(top-1) = lua_createarray(size.w);
860 tag(top-1) = LUA_T_ARRAY; 858 tag(top-1) = LUA_T_ARRAY;
859 avalue(top-1) = lua_createarray(size.w);
861 } 860 }
862 break; 861 break;
863 862
864 case EQOP: 863 case EQOP:
865 { 864 {
866 int res; 865 int res = lua_equalObj(top-2, top-1);
867 Object *l = top-2;
868 Object *r = top-1;
869 --top; 866 --top;
870 if (tag(l) != tag(r))
871 res = 0;
872 else
873 {
874 switch (tag(l))
875 {
876 case LUA_T_NIL:
877 res = 1; break;
878 case LUA_T_NUMBER:
879 res = (nvalue(l) == nvalue(r)); break;
880 case LUA_T_ARRAY:
881 res = (avalue(l) == avalue(r)); break;
882 case LUA_T_FUNCTION:
883 res = (bvalue(l) == bvalue(r)); break;
884 case LUA_T_CFUNCTION:
885 res = (fvalue(l) == fvalue(r)); break;
886 case LUA_T_STRING:
887 res = (strcmp (svalue(l), svalue(r)) == 0); break;
888 default:
889 res = (uvalue(l) == uvalue(r)); break;
890 }
891 }
892 tag(top-1) = res ? LUA_T_NUMBER : LUA_T_NIL; 867 tag(top-1) = res ? LUA_T_NUMBER : LUA_T_NIL;
893 nvalue(top-1) = 1; 868 nvalue(top-1) = 1;
894 } 869 }
@@ -1003,6 +978,7 @@ static int lua_execute (Byte *pc, int base)
1003 978
1004 case NOTOP: 979 case NOTOP:
1005 tag(top-1) = (tag(top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL; 980 tag(top-1) = (tag(top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL;
981 nvalue(top-1) = 1;
1006 break; 982 break;
1007 983
1008 case ONTJMP: 984 case ONTJMP:
diff --git a/table.c b/table.c
index 20ab6046..d37b7b03 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.16 1994/11/11 14:00:08 roberto Exp roberto $"; 6char *rcs_table="$Id: table.c,v 2.17 1994/11/14 21:40:14 roberto Exp $";
7 7
8#include <stdlib.h> 8#include <stdlib.h>
9#include <string.h> 9#include <string.h>
@@ -41,6 +41,8 @@ Word lua_nentity; /* counter of new entities (strings and arrays) */
41Word lua_recovered; /* counter of recovered entities (strings and arrays) */ 41Word lua_recovered; /* counter of recovered entities (strings and arrays) */
42 42
43 43
44static void lua_nextvar (void);
45
44/* 46/*
45** Initialise symbol table with internal functions 47** Initialise symbol table with internal functions
46*/ 48*/
@@ -239,9 +241,10 @@ char *lua_filename (void)
239/* 241/*
240** Internal function: return next global variable 242** Internal function: return next global variable
241*/ 243*/
242void lua_nextvar (void) 244static void lua_nextvar (void)
243{ 245{
244 char *varname, *next; 246 char *varname;
247 TreeNode *next;
245 lua_Object o = lua_getparam(1); 248 lua_Object o = lua_getparam(1);
246 if (o == 0) 249 if (o == 0)
247 lua_error ("too few arguments to function `nextvar'"); 250 lua_error ("too few arguments to function `nextvar'");
@@ -266,8 +269,8 @@ void lua_nextvar (void)
266 { 269 {
267 Object name; 270 Object name;
268 tag(&name) = LUA_T_STRING; 271 tag(&name) = LUA_T_STRING;
269 svalue(&name) = next; 272 svalue(&name) = next->str;
270 luaI_pushobject(&name); 273 luaI_pushobject(&name);
271 luaI_pushobject(&s_object(indexstring(next))); 274 luaI_pushobject(&s_object(next->varindex));
272 } 275 }
273} 276}
diff --git a/table.h b/table.h
index 423ba3dd..1433814d 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.4 1994/11/03 21:48:36 roberto Exp roberto $ 4** $Id: table.h,v 2.5 1994/11/14 21:40:14 roberto Exp roberto $
5*/ 5*/
6 6
7#ifndef table_h 7#ifndef table_h
@@ -31,6 +31,5 @@ char *lua_createstring (char *s);
31char *lua_addfile (char *fn); 31char *lua_addfile (char *fn);
32int lua_delfile (void); 32int lua_delfile (void);
33char *lua_filename (void); 33char *lua_filename (void);
34void lua_nextvar (void);
35 34
36#endif 35#endif
diff --git a/tree.c b/tree.c
index bca29994..eee5a204 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.3 1994/11/10 20:41:37 roberto Exp roberto $"; 6char *rcs_tree="$Id: tree.c,v 1.4 1994/11/14 21:40:14 roberto Exp roberto $";
7 7
8 8
9#include <stdlib.h> 9#include <stdlib.h>
@@ -169,9 +169,18 @@ static TreeNode *tree_next (TreeNode *node, char *str)
169 } 169 }
170} 170}
171 171
172char *lua_varnext (char *n) 172TreeNode *lua_varnext (char *n)
173{ 173{
174 TreeNode *result = tree_next(constant_root, n); 174 TreeNode *result;
175 return result != NULL ? result->str : NULL; 175 char *name = n;
176 while (1)
177 { /* repeat until a valid (non nil) variable */
178 result = tree_next(constant_root, name);
179 if (result == NULL) return NULL;
180 if (result->varindex != UNMARKED_STRING &&
181 s_tag(result->varindex) != LUA_T_NIL)
182 return result;
183 name = result->str;
184 }
176} 185}
177 186
diff --git a/tree.h b/tree.h
index 0e7c27c9..7587f4ec 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.1 1994/07/19 21:24:17 celes Exp roberto $ 4** $Id: tree.h,v 1.2 1994/11/14 21:40:14 roberto Exp roberto $
5*/ 5*/
6 6
7#ifndef tree_h 7#ifndef tree_h
@@ -31,6 +31,6 @@ typedef struct TreeNode
31char *lua_strcreate (char *str); 31char *lua_strcreate (char *str);
32TreeNode *lua_constcreate (char *str); 32TreeNode *lua_constcreate (char *str);
33void lua_strcollector (void); 33void lua_strcollector (void);
34char *lua_varnext (char *n); 34TreeNode *lua_varnext (char *n);
35 35
36#endif 36#endif