2
0
Эх сурвалжийг харах

better definitions for MULTRET

Roberto Ierusalimschy 25 жил өмнө
parent
commit
9d60598260
5 өөрчлөгдсөн 21 нэмэгдсэн , 20 устгасан
  1. 4 5
      ldo.c
  2. 1 2
      ldo.h
  3. 1 9
      llimits.h
  4. 10 1
      lopcodes.h
  5. 5 3
      lvm.c

+ 4 - 5
ldo.c

@@ -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
 ** 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'
 */
-void luaD_openstack (lua_State *L, StkId pos) {
+static void luaD_openstack (lua_State *L, StkId pos) {
   int i = L->top-pos; 
   while (i--) pos[i+1] = pos[i];
   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.
 ** When returns, the results are on the stack, starting at the original
 ** 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) {
   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 */
     luaD_callHook(L, func, callhook, "return");
   /* adjust the number of results */
-  if (nResults == MULT_RET)
+  if (nResults == LUA_MULTRET)
     nResults = L->top - firstResult;
   else
     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 */
   struct lua_longjmp myErrorJmp;
   chain_longjmp(L, &myErrorJmp);
-  if (nresults == LUA_MULTRET) nresults = MULT_RET;  /* internal code */
   if (setjmp(myErrorJmp.b) == 0) {
     luaD_call(L, func, nresults);
   }

+ 1 - 2
ldo.h

@@ -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
 ** See Copyright Notice in lua.h
 */
@@ -21,7 +21,6 @@
 
 void luaD_init (lua_State *L, int stacksize);
 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_call (lua_State *L, StkId func, int nResults);
 void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults);

+ 1 - 9
llimits.h

@@ -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
 ** See Copyright Notice in lua.h
 */
@@ -157,14 +157,6 @@ typedef unsigned long Instruction;
 #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 */
 #ifndef MAXVARSLH
 #define MAXVARSLH 100           /* arbitrary limit (<MULT_RET) */

+ 10 - 1
lopcodes.h

@@ -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
 ** 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)
 
 
+
+/* 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

+ 5 - 3
lvm.c

@@ -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
 ** 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);
       }
       case OP_CALL: {
+        int nres = GETARG_B(i);
+        if (nres == MULT_RET) nres = LUA_MULTRET;
         L->top = top;
-        luaD_call(L, base+GETARG_A(i), GETARG_B(i));
+        luaD_call(L, base+GETARG_A(i), nres);
         top = L->top;
         break;
       }
       case OP_TAILCALL: {
         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);
       }
       case OP_PUSHNIL: {