Jelajahi Sumber

initial separation, in CallInfo, of what is relevant only to Lua
functions or only to C functions

Roberto Ierusalimschy 16 tahun lalu
induk
melakukan
1817dfc301
4 mengubah file dengan 15 tambahan dan 11 penghapusan
  1. 3 3
      ldebug.c
  2. 4 4
      ldo.c
  3. 6 2
      lstate.h
  4. 2 2
      lvm.c

+ 3 - 3
ldebug.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ldebug.c,v 2.41 2008/08/26 13:27:42 roberto Exp roberto $
+** $Id: ldebug.c,v 2.42 2008/10/30 15:39:30 roberto Exp roberto $
 ** Debug Interface
 ** Debug Interface
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -89,7 +89,7 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
   for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) {
   for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) {
     level--;
     level--;
     if (isLua(ci))  /* Lua function? */
     if (isLua(ci))  /* Lua function? */
-      level -= ci->tailcalls;  /* skip lost tail calls */
+      level -= ci->u.l.tailcalls;  /* skip lost tail calls */
   }
   }
   if (level == 0 && ci > L->base_ci) {  /* level found? */
   if (level == 0 && ci > L->base_ci) {  /* level found? */
     status = 1;
     status = 1;
@@ -527,7 +527,7 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos,
 static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
 static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
   TMS tm = 0;
   TMS tm = 0;
   Instruction i;
   Instruction i;
-  if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1))
+  if ((isLua(ci) && ci->u.l.tailcalls > 0) || !isLua(ci - 1))
     return NULL;  /* calling function is not Lua (or is unknown) */
     return NULL;  /* calling function is not Lua (or is unknown) */
   ci--;  /* calling function */
   ci--;  /* calling function */
   i = ci_func(ci)->l.p->code[currentpc(L, ci)];
   i = ci_func(ci)->l.p->code[currentpc(L, ci)];

+ 4 - 4
ldo.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ldo.c,v 2.52 2009/02/18 14:52:03 roberto Exp roberto $
+** $Id: ldo.c,v 2.53 2009/03/03 18:51:24 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
 */
 */
@@ -289,7 +289,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
     ci->top = L->base + p->maxstacksize;
     ci->top = L->base + p->maxstacksize;
     lua_assert(ci->top <= L->stack_last);
     lua_assert(ci->top <= L->stack_last);
     L->savedpc = p->code;  /* starting point */
     L->savedpc = p->code;  /* starting point */
-    ci->tailcalls = 0;
+    ci->u.l.tailcalls = 0;
     ci->callstatus = CIST_LUA;
     ci->callstatus = CIST_LUA;
     ci->nresults = nresults;
     ci->nresults = nresults;
     for (st = L->top; st < ci->top; st++)
     for (st = L->top; st < ci->top; st++)
@@ -328,8 +328,8 @@ static StkId callrethooks (lua_State *L, StkId firstResult) {
   ptrdiff_t fr = savestack(L, firstResult);  /* next call may change stack */
   ptrdiff_t fr = savestack(L, firstResult);  /* next call may change stack */
   luaD_callhook(L, LUA_HOOKRET, -1);
   luaD_callhook(L, LUA_HOOKRET, -1);
   if (isLua(L->ci)) {  /* Lua function? */
   if (isLua(L->ci)) {  /* Lua function? */
-    while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */
-      luaD_callhook(L, LUA_HOOKTAILRET, -1);
+    while ((L->hookmask & LUA_MASKRET) && L->ci->u.l.tailcalls--)
+      luaD_callhook(L, LUA_HOOKTAILRET, -1);  /* ret. hooks for tail calls */
   }
   }
   return restorestack(L, fr);
   return restorestack(L, fr);
 }
 }

+ 6 - 2
lstate.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lstate.h,v 2.36 2008/08/26 13:27:42 roberto Exp roberto $
+** $Id: lstate.h,v 2.37 2009/02/18 17:20:56 roberto Exp roberto $
 ** Global State
 ** Global State
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -83,7 +83,11 @@ typedef struct CallInfo {
   const Instruction *savedpc;
   const Instruction *savedpc;
   short nresults;  /* expected number of results from this function */
   short nresults;  /* expected number of results from this function */
   lu_byte callstatus;
   lu_byte callstatus;
-  int tailcalls;  /* number of tail calls lost under this entry */
+  union {
+    struct {  /* only for Lua functions */
+      int tailcalls;  /* number of tail calls lost under this entry */
+    } l;
+  } u;
 } CallInfo;
 } CallInfo;
 
 
 
 

+ 2 - 2
lvm.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lvm.c,v 2.81 2009/02/16 20:09:28 roberto Exp roberto $
+** $Id: lvm.c,v 2.82 2009/03/02 16:34:23 roberto Exp roberto $
 ** Lua virtual machine
 ** Lua virtual machine
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -622,7 +622,7 @@ void luaV_execute (lua_State *L) {
           ci->top = L->top = func+aux;  /* correct top */
           ci->top = L->top = func+aux;  /* correct top */
           lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize);
           lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize);
           ci->savedpc = L->savedpc;
           ci->savedpc = L->savedpc;
-          ci->tailcalls++;  /* one more call lost */
+          ci->u.l.tailcalls++;  /* one more call lost */
           L->ci--;  /* remove new frame */
           L->ci--;  /* remove new frame */
           goto reentry;
           goto reentry;
         }
         }