better definitions for MULTRET

This commit is contained in:
Roberto Ierusalimschy 2000-08-29 11:48:16 -03:00
parent 4e56c0d514
commit 9d60598260
5 changed files with 21 additions and 20 deletions

9
ldo.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldo.c,v 1.86 2000/08/28 17:57:04 roberto Exp roberto $ ** $Id: ldo.c,v 1.87 2000/08/29 14:33:31 roberto Exp roberto $
** Stack and Call structure of Lua ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -92,7 +92,7 @@ void luaD_adjusttop (lua_State *L, StkId base, int extra) {
/* /*
** Open a hole inside the stack at `pos' ** Open a hole inside the stack at `pos'
*/ */
void luaD_openstack (lua_State *L, StkId pos) { static void luaD_openstack (lua_State *L, StkId pos) {
int i = L->top-pos; int i = L->top-pos;
while (i--) pos[i+1] = pos[i]; while (i--) pos[i+1] = pos[i];
incr_top; incr_top;
@ -160,7 +160,7 @@ void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults) {
** The arguments are on the stack, right after the function. ** The arguments are on the stack, right after the function.
** When returns, the results are on the stack, starting at the original ** When returns, the results are on the stack, starting at the original
** function position. ** function position.
** The number of results is nResults, unless nResults=MULT_RET. ** The number of results is nResults, unless nResults=LUA_MULTRET.
*/ */
void luaD_call (lua_State *L, StkId func, int nResults) { void luaD_call (lua_State *L, StkId func, int nResults) {
StkId firstResult; StkId firstResult;
@ -197,7 +197,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
if (callhook) /* same hook that was active at entry */ if (callhook) /* same hook that was active at entry */
luaD_callHook(L, func, callhook, "return"); luaD_callHook(L, func, callhook, "return");
/* adjust the number of results */ /* adjust the number of results */
if (nResults == MULT_RET) if (nResults == LUA_MULTRET)
nResults = L->top - firstResult; nResults = L->top - firstResult;
else else
luaD_adjusttop(L, firstResult, nResults); luaD_adjusttop(L, firstResult, nResults);
@ -264,7 +264,6 @@ int lua_call (lua_State *L, int nargs, int nresults) {
StkId func = L->top - (nargs+1); /* function to be called */ StkId func = L->top - (nargs+1); /* function to be called */
struct lua_longjmp myErrorJmp; struct lua_longjmp myErrorJmp;
chain_longjmp(L, &myErrorJmp); chain_longjmp(L, &myErrorJmp);
if (nresults == LUA_MULTRET) nresults = MULT_RET; /* internal code */
if (setjmp(myErrorJmp.b) == 0) { if (setjmp(myErrorJmp.b) == 0) {
luaD_call(L, func, nresults); luaD_call(L, func, nresults);
} }

3
ldo.h
View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldo.h,v 1.22 2000/08/07 18:39:16 roberto Exp roberto $ ** $Id: ldo.h,v 1.23 2000/08/28 17:57:04 roberto Exp roberto $
** Stack and Call structure of Lua ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -21,7 +21,6 @@
void luaD_init (lua_State *L, int stacksize); void luaD_init (lua_State *L, int stacksize);
void luaD_adjusttop (lua_State *L, StkId base, int extra); void luaD_adjusttop (lua_State *L, StkId base, int extra);
void luaD_openstack (lua_State *L, StkId pos);
void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook); void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook);
void luaD_call (lua_State *L, StkId func, int nResults); void luaD_call (lua_State *L, StkId func, int nResults);
void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults); void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults);

View File

@ -1,5 +1,5 @@
/* /*
** $Id: llimits.h,v 1.12 2000/08/15 18:28:48 roberto Exp roberto $ ** $Id: llimits.h,v 1.13 2000/08/28 17:57:04 roberto Exp roberto $
** Limits, basic types, and some other "installation-dependent" definitions ** Limits, basic types, and some other "installation-dependent" definitions
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -157,14 +157,6 @@ typedef unsigned long Instruction;
#endif #endif
/* special code for multiple returns */
#define MULT_RET 255 /* (<=MAXARG_B) */
#if MULT_RET>MAXARG_B
#undef MULT_RET
#define MULT_RET MAXARG_B
#endif
/* maximum number of variables in the left side of an assignment */ /* maximum number of variables in the left side of an assignment */
#ifndef MAXVARSLH #ifndef MAXVARSLH
#define MAXVARSLH 100 /* arbitrary limit (<MULT_RET) */ #define MAXVARSLH 100 /* arbitrary limit (<MULT_RET) */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lopcodes.h,v 1.65 2000/06/26 19:28:31 roberto Exp roberto $ ** $Id: lopcodes.h,v 1.66 2000/08/15 18:28:48 roberto Exp roberto $
** Opcodes for Lua virtual machine ** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -156,4 +156,13 @@ OP_CLOSURE/* A B v_b-v_1 closure(KPROTO[a], v_1-v_b) */
#define ISJUMP(o) (OP_JMPNE <= (o) && (o) <= OP_JMP) #define ISJUMP(o) (OP_JMPNE <= (o) && (o) <= OP_JMP)
/* special code to fit a LUA_MULTRET inside an argB */
#define MULT_RET 255 /* (<=MAXARG_B) */
#if MULT_RET>MAXARG_B
#undef MULT_RET
#define MULT_RET MAXARG_B
#endif
#endif #endif

8
lvm.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lvm.c,v 1.129 2000/08/22 20:53:30 roberto Exp roberto $ ** $Id: lvm.c,v 1.130 2000/08/29 14:41:56 roberto Exp roberto $
** Lua virtual machine ** Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -368,14 +368,16 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
return base+GETARG_U(i); return base+GETARG_U(i);
} }
case OP_CALL: { case OP_CALL: {
int nres = GETARG_B(i);
if (nres == MULT_RET) nres = LUA_MULTRET;
L->top = top; L->top = top;
luaD_call(L, base+GETARG_A(i), GETARG_B(i)); luaD_call(L, base+GETARG_A(i), nres);
top = L->top; top = L->top;
break; break;
} }
case OP_TAILCALL: { case OP_TAILCALL: {
L->top = top; L->top = top;
luaD_call(L, base+GETARG_A(i), MULT_RET); luaD_call(L, base+GETARG_A(i), LUA_MULTRET);
return base+GETARG_B(i); return base+GETARG_B(i);
} }
case OP_PUSHNIL: { case OP_PUSHNIL: {