aboutsummaryrefslogtreecommitdiff
path: root/opcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'opcode.c')
-rw-r--r--opcode.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/opcode.c b/opcode.c
index d967c2cc..6625f51e 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.8 1994/11/10 17:11:52 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 3.9 1994/11/10 17:36:54 roberto Exp roberto $";
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <stdlib.h> 9#include <stdlib.h>
@@ -101,7 +101,7 @@ static void lua_initstack (void)
101*/ 101*/
102static void lua_checkstack (Word n) 102static void lua_checkstack (Word n)
103{ 103{
104 if (n > maxstack) 104 if ((Long)n > maxstack)
105 { 105 {
106 int t; 106 int t;
107 if (stack == NULL) 107 if (stack == NULL)
@@ -186,16 +186,17 @@ static int lua_tostring (Object *obj)
186/* 186/*
187** Adjust stack. Set top to the given value, pushing NILs if needed. 187** Adjust stack. Set top to the given value, pushing NILs if needed.
188*/ 188*/
189static void adjust_top (Object *newtop) 189static void adjust_top (int newtop)
190{ 190{
191 while (top < newtop) tag(top++) = LUA_T_NIL; 191 Object *nt = stack+newtop;
192 top = newtop; /* top could be bigger than newtop */ 192 while (top < nt) tag(top++) = LUA_T_NIL;
193 top = nt; /* top could be bigger than newtop */
193} 194}
194 195
195 196
196static void adjustC (int nParams) 197static void adjustC (int nParams)
197{ 198{
198 adjust_top(stack+CBase+nParams); 199 adjust_top(CBase+nParams);
199} 200}
200 201
201 202
@@ -240,14 +241,15 @@ static void do_call (Object *func, int base, int nResults, int whereRes)
240 } 241 }
241 /* adjust the number of results */ 242 /* adjust the number of results */
242 if (nResults != MULT_RET && top - (stack+firstResult) != nResults) 243 if (nResults != MULT_RET && top - (stack+firstResult) != nResults)
243 adjust_top(stack+firstResult+nResults); 244 adjust_top(firstResult+nResults);
244 /* move results to the given position */ 245 /* move results to the given position */
245 if (firstResult != whereRes) 246 if (firstResult != whereRes)
246 { 247 {
247 int i = top - (stack+firstResult); /* number of results */ 248 int i;
248 top -= firstResult-whereRes; 249 nResults = top - (stack+firstResult); /* actual number of results */
249 while (i--) 250 for (i=0; i<nResults; i++)
250 *(stack+whereRes+i) = *(stack+firstResult+i); 251 *(stack+whereRes+i) = *(stack+firstResult+i);
252 top -= firstResult-whereRes;
251 } 253 }
252} 254}
253 255
@@ -830,11 +832,11 @@ static int lua_execute (Byte *pc, int base)
830 break; 832 break;
831 833
832 case ADJUST0: 834 case ADJUST0:
833 adjust_top((stack+base)); 835 adjust_top(base);
834 break; 836 break;
835 837
836 case ADJUST: 838 case ADJUST:
837 adjust_top((stack+base) + *(pc++)); 839 adjust_top(base + *(pc++));
838 break; 840 break;
839 841
840 case CREATEARRAY: 842 case CREATEARRAY: