diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-16 14:03:48 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-16 14:03:48 -0200 |
commit | 94686ce58554a80374eeff115ee5b87c184ed173 (patch) | |
tree | 9b41f32a05a41f7063df180015c13c5d9ae1d4a0 | |
parent | 86b35cf4f6a824880239069d0afe282e95806aaa (diff) | |
download | lua-94686ce58554a80374eeff115ee5b87c184ed173.tar.gz lua-94686ce58554a80374eeff115ee5b87c184ed173.tar.bz2 lua-94686ce58554a80374eeff115ee5b87c184ed173.zip |
correction of function 'nextvar'
-rw-r--r-- | opcode.c | 58 | ||||
-rw-r--r-- | table.c | 13 | ||||
-rw-r--r-- | table.h | 3 | ||||
-rw-r--r-- | tree.c | 17 | ||||
-rw-r--r-- | tree.h | 4 |
5 files changed, 41 insertions, 54 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.10 1994/11/11 14:00:08 roberto Exp roberto $"; | 6 | char *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 | */ |
123 | static char *lua_strconc (char *l, char *r) | 122 | static 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 | ||
374 | int lua_call (char *funcname) | 376 | int 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 | */ |
549 | lua_Object lua_getglobal (char *name) | 551 | lua_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 | */ |
562 | int lua_storeglobal (char *name) | 564 | int 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: |
@@ -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.16 1994/11/11 14:00:08 roberto Exp roberto $"; | 6 | char *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) */ | |||
41 | Word lua_recovered; /* counter of recovered entities (strings and arrays) */ | 41 | Word lua_recovered; /* counter of recovered entities (strings and arrays) */ |
42 | 42 | ||
43 | 43 | ||
44 | static 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 | */ |
242 | void lua_nextvar (void) | 244 | static 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 | } |
@@ -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); | |||
31 | char *lua_addfile (char *fn); | 31 | char *lua_addfile (char *fn); |
32 | int lua_delfile (void); | 32 | int lua_delfile (void); |
33 | char *lua_filename (void); | 33 | char *lua_filename (void); |
34 | void lua_nextvar (void); | ||
35 | 34 | ||
36 | #endif | 35 | #endif |
@@ -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.3 1994/11/10 20:41:37 roberto Exp roberto $"; | 6 | char *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 | ||
172 | char *lua_varnext (char *n) | 172 | TreeNode *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 | ||
@@ -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 | |||
31 | char *lua_strcreate (char *str); | 31 | char *lua_strcreate (char *str); |
32 | TreeNode *lua_constcreate (char *str); | 32 | TreeNode *lua_constcreate (char *str); |
33 | void lua_strcollector (void); | 33 | void lua_strcollector (void); |
34 | char *lua_varnext (char *n); | 34 | TreeNode *lua_varnext (char *n); |
35 | 35 | ||
36 | #endif | 36 | #endif |