aboutsummaryrefslogtreecommitdiff
path: root/opcode.c
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 /opcode.c
parent86b35cf4f6a824880239069d0afe282e95806aaa (diff)
downloadlua-94686ce58554a80374eeff115ee5b87c184ed173.tar.gz
lua-94686ce58554a80374eeff115ee5b87c184ed173.tar.bz2
lua-94686ce58554a80374eeff115ee5b87c184ed173.zip
correction of function 'nextvar'
Diffstat (limited to 'opcode.c')
-rw-r--r--opcode.c58
1 files changed, 17 insertions, 41 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: