aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-29 11:48:16 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-29 11:48:16 -0300
commit9d605982605db5ab8117b4cda71284bca2d25db8 (patch)
tree968b70b828f62ee945134424fbec866b4fc0f1bc
parent4e56c0d51412817a238f9de6453aaa16704a770d (diff)
downloadlua-9d605982605db5ab8117b4cda71284bca2d25db8.tar.gz
lua-9d605982605db5ab8117b4cda71284bca2d25db8.tar.bz2
lua-9d605982605db5ab8117b4cda71284bca2d25db8.zip
better definitions for MULTRET
-rw-r--r--ldo.c9
-rw-r--r--ldo.h3
-rw-r--r--llimits.h10
-rw-r--r--lopcodes.h11
-rw-r--r--lvm.c8
5 files changed, 21 insertions, 20 deletions
diff --git a/ldo.c b/ldo.c
index f2e36f67..e9fc1505 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.86 2000/08/28 17:57:04 roberto Exp roberto $ 2** $Id: ldo.c,v 1.87 2000/08/29 14:33:31 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -92,7 +92,7 @@ void luaD_adjusttop (lua_State *L, StkId base, int extra) {
92/* 92/*
93** Open a hole inside the stack at `pos' 93** Open a hole inside the stack at `pos'
94*/ 94*/
95void luaD_openstack (lua_State *L, StkId pos) { 95static void luaD_openstack (lua_State *L, StkId pos) {
96 int i = L->top-pos; 96 int i = L->top-pos;
97 while (i--) pos[i+1] = pos[i]; 97 while (i--) pos[i+1] = pos[i];
98 incr_top; 98 incr_top;
@@ -160,7 +160,7 @@ void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults) {
160** The arguments are on the stack, right after the function. 160** The arguments are on the stack, right after the function.
161** When returns, the results are on the stack, starting at the original 161** When returns, the results are on the stack, starting at the original
162** function position. 162** function position.
163** The number of results is nResults, unless nResults=MULT_RET. 163** The number of results is nResults, unless nResults=LUA_MULTRET.
164*/ 164*/
165void luaD_call (lua_State *L, StkId func, int nResults) { 165void luaD_call (lua_State *L, StkId func, int nResults) {
166 StkId firstResult; 166 StkId firstResult;
@@ -197,7 +197,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
197 if (callhook) /* same hook that was active at entry */ 197 if (callhook) /* same hook that was active at entry */
198 luaD_callHook(L, func, callhook, "return"); 198 luaD_callHook(L, func, callhook, "return");
199 /* adjust the number of results */ 199 /* adjust the number of results */
200 if (nResults == MULT_RET) 200 if (nResults == LUA_MULTRET)
201 nResults = L->top - firstResult; 201 nResults = L->top - firstResult;
202 else 202 else
203 luaD_adjusttop(L, firstResult, nResults); 203 luaD_adjusttop(L, firstResult, nResults);
@@ -264,7 +264,6 @@ int lua_call (lua_State *L, int nargs, int nresults) {
264 StkId func = L->top - (nargs+1); /* function to be called */ 264 StkId func = L->top - (nargs+1); /* function to be called */
265 struct lua_longjmp myErrorJmp; 265 struct lua_longjmp myErrorJmp;
266 chain_longjmp(L, &myErrorJmp); 266 chain_longjmp(L, &myErrorJmp);
267 if (nresults == LUA_MULTRET) nresults = MULT_RET; /* internal code */
268 if (setjmp(myErrorJmp.b) == 0) { 267 if (setjmp(myErrorJmp.b) == 0) {
269 luaD_call(L, func, nresults); 268 luaD_call(L, func, nresults);
270 } 269 }
diff --git a/ldo.h b/ldo.h
index ba168ccb..becbf417 100644
--- a/ldo.h
+++ b/ldo.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.h,v 1.22 2000/08/07 18:39:16 roberto Exp roberto $ 2** $Id: ldo.h,v 1.23 2000/08/28 17:57:04 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -21,7 +21,6 @@
21 21
22void luaD_init (lua_State *L, int stacksize); 22void luaD_init (lua_State *L, int stacksize);
23void luaD_adjusttop (lua_State *L, StkId base, int extra); 23void luaD_adjusttop (lua_State *L, StkId base, int extra);
24void luaD_openstack (lua_State *L, StkId pos);
25void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook); 24void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook);
26void luaD_call (lua_State *L, StkId func, int nResults); 25void luaD_call (lua_State *L, StkId func, int nResults);
27void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults); 26void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults);
diff --git a/llimits.h b/llimits.h
index c716b0dd..4c66c7b5 100644
--- a/llimits.h
+++ b/llimits.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llimits.h,v 1.12 2000/08/15 18:28:48 roberto Exp roberto $ 2** $Id: llimits.h,v 1.13 2000/08/28 17:57:04 roberto Exp roberto $
3** Limits, basic types, and some other "installation-dependent" definitions 3** Limits, basic types, and some other "installation-dependent" definitions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -157,14 +157,6 @@ typedef unsigned long Instruction;
157#endif 157#endif
158 158
159 159
160/* special code for multiple returns */
161#define MULT_RET 255 /* (<=MAXARG_B) */
162#if MULT_RET>MAXARG_B
163#undef MULT_RET
164#define MULT_RET MAXARG_B
165#endif
166
167
168/* maximum number of variables in the left side of an assignment */ 160/* maximum number of variables in the left side of an assignment */
169#ifndef MAXVARSLH 161#ifndef MAXVARSLH
170#define MAXVARSLH 100 /* arbitrary limit (<MULT_RET) */ 162#define MAXVARSLH 100 /* arbitrary limit (<MULT_RET) */
diff --git a/lopcodes.h b/lopcodes.h
index f97a2138..c1754682 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.65 2000/06/26 19:28:31 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.66 2000/08/15 18:28:48 roberto Exp roberto $
3** Opcodes for Lua virtual machine 3** Opcodes for Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -156,4 +156,13 @@ OP_CLOSURE/* A B v_b-v_1 closure(KPROTO[a], v_1-v_b) */
156#define ISJUMP(o) (OP_JMPNE <= (o) && (o) <= OP_JMP) 156#define ISJUMP(o) (OP_JMPNE <= (o) && (o) <= OP_JMP)
157 157
158 158
159
160/* special code to fit a LUA_MULTRET inside an argB */
161#define MULT_RET 255 /* (<=MAXARG_B) */
162#if MULT_RET>MAXARG_B
163#undef MULT_RET
164#define MULT_RET MAXARG_B
165#endif
166
167
159#endif 168#endif
diff --git a/lvm.c b/lvm.c
index 9a651b6f..b9f5f74e 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.129 2000/08/22 20:53:30 roberto Exp roberto $ 2** $Id: lvm.c,v 1.130 2000/08/29 14:41:56 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -368,14 +368,16 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
368 return base+GETARG_U(i); 368 return base+GETARG_U(i);
369 } 369 }
370 case OP_CALL: { 370 case OP_CALL: {
371 int nres = GETARG_B(i);
372 if (nres == MULT_RET) nres = LUA_MULTRET;
371 L->top = top; 373 L->top = top;
372 luaD_call(L, base+GETARG_A(i), GETARG_B(i)); 374 luaD_call(L, base+GETARG_A(i), nres);
373 top = L->top; 375 top = L->top;
374 break; 376 break;
375 } 377 }
376 case OP_TAILCALL: { 378 case OP_TAILCALL: {
377 L->top = top; 379 L->top = top;
378 luaD_call(L, base+GETARG_A(i), MULT_RET); 380 luaD_call(L, base+GETARG_A(i), LUA_MULTRET);
379 return base+GETARG_B(i); 381 return base+GETARG_B(i);
380 } 382 }
381 case OP_PUSHNIL: { 383 case OP_PUSHNIL: {