Roberto Ierusalimschy 7 лет назад
Родитель
Сommit
b9e76be8a6
6 измененных файлов с 37 добавлено и 39 удалено
  1. 12 13
      lapi.c
  2. 2 2
      lapi.h
  3. 4 4
      ldebug.c
  4. 5 5
      ldo.c
  5. 2 2
      ltests.c
  6. 12 13
      lvm.c

+ 12 - 13
lapi.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.c,v 2.270 2017/06/29 15:06:44 roberto Exp roberto $
+** $Id: lapi.c,v 2.271 2017/10/11 12:38:45 roberto Exp roberto $
 ** Lua API
 ** See Copyright Notice in lua.h
 */
@@ -60,13 +60,13 @@ const char lua_ident[] =
 static TValue *index2value (lua_State *L, int idx) {
   CallInfo *ci = L->ci;
   if (idx > 0) {
-    StkId o = ci->func + idx;
-    api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index");
+    StkId o = L->func + idx;
+    api_check(L, idx <= ci->top - (L->func + 1), "unacceptable index");
     if (o >= L->top) return NONVALIDVALUE;
     else return s2v(o);
   }
   else if (!ispseudo(idx)) {  /* negative index */
-    api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index");
+    api_check(L, idx != 0 && -idx <= L->top - (L->func + 1), "invalid index");
     return s2v(L->top + idx);
   }
   else if (idx == LUA_REGISTRYINDEX)
@@ -74,10 +74,10 @@ static TValue *index2value (lua_State *L, int idx) {
   else {  /* upvalues */
     idx = LUA_REGISTRYINDEX - idx;
     api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large");
-    if (ttislcf(s2v(ci->func)))  /* light C function? */
+    if (ttislcf(s2v(L->func)))  /* light C function? */
       return NONVALIDVALUE;  /* it has no upvalues */
     else {
-      CClosure *func = clCvalue(s2v(ci->func));
+      CClosure *func = clCvalue(s2v(L->func));
       return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE;
     }
   }
@@ -85,14 +85,13 @@ static TValue *index2value (lua_State *L, int idx) {
 
 
 static StkId index2stack (lua_State *L, int idx) {
-  CallInfo *ci = L->ci;
   if (idx > 0) {
-    StkId o = ci->func + idx;
+    StkId o = L->func + idx;
     api_check(L, o < L->top, "unacceptable index");
     return o;
   }
   else {    /* non-positive index */
-    api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index");
+    api_check(L, idx != 0 && -idx <= L->top - (L->func + 1), "invalid index");
     api_check(L, !ispseudo(idx), "invalid index");
     return L->top + idx;
   }
@@ -175,17 +174,17 @@ LUA_API const lua_Number *lua_version (lua_State *L) {
 LUA_API int lua_absindex (lua_State *L, int idx) {
   return (idx > 0 || ispseudo(idx))
          ? idx
-         : cast_int(L->top - L->ci->func) + idx;
+         : cast_int(L->top - L->func) + idx;
 }
 
 
 LUA_API int lua_gettop (lua_State *L) {
-  return cast_int(L->top - (L->ci->func + 1));
+  return cast_int(L->top - (L->func + 1));
 }
 
 
 LUA_API void lua_settop (lua_State *L, int idx) {
-  StkId func = L->ci->func;
+  StkId func = L->func;
   lua_lock(L);
   if (idx >= 0) {
     api_check(L, idx <= L->stack_last - (func + 1), "new top too large");
@@ -243,7 +242,7 @@ LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) {
   api_checkvalidindex(L, to);
   setobj(L, to, fr);
   if (isupvalue(toidx))  /* function upvalue? */
-    luaC_barrier(L, clCvalue(s2v(L->ci->func)), fr);
+    luaC_barrier(L, clCvalue(s2v(L->func)), fr);
   /* LUA_REGISTRYINDEX does not need gc barrier
      (collector revisits it before finishing collection) */
   lua_unlock(L);

+ 2 - 2
lapi.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.h,v 2.8 2014/07/15 21:26:50 roberto Exp roberto $
+** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp roberto $
 ** Auxiliary functions from Lua API
 ** See Copyright Notice in lua.h
 */
@@ -17,7 +17,7 @@
 #define adjustresults(L,nres) \
     { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }
 
-#define api_checknelems(L,n)	api_check(L, (n) < (L->top - L->ci->func), \
+#define api_checknelems(L,n)	api_check(L, (n) < (L->top - L->func), \
 				  "not enough elements in the stack")
 
 

+ 4 - 4
ldebug.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldebug.c,v 2.132 2017/10/04 21:56:32 roberto Exp roberto $
+** $Id: ldebug.c,v 2.133 2017/10/31 17:14:02 roberto Exp roberto $
 ** Debug Interface
 ** See Copyright Notice in lua.h
 */
@@ -116,7 +116,7 @@ static void swapextra (lua_State *L) {
   if (L->status == LUA_YIELD) {
     CallInfo *ci = L->ci;  /* get function that yielded */
     StkId temp = ci->func;  /* exchange its 'func' and 'extra' values */
-    ci->func = restorestack(L, ci->extra);
+    L->func = ci->func = restorestack(L, ci->extra);
     ci->extra = savestack(L, temp);
   }
 }
@@ -661,7 +661,7 @@ static const char *varinfo (lua_State *L, const TValue *o) {
     kind = getupvalname(ci, o, &name);  /* check whether 'o' is an upvalue */
     if (!kind && isinstack(L, o))  /* no? try a register */
       kind = getobjname(ci_func(ci)->p, currentpc(ci),
-                        cast_int(cast(StkId, o) - (ci->func + 1)), &name);
+                        cast_int(cast(StkId, o) - (L->func + 1)), &name);
   }
   return (kind) ? luaO_pushfstring(L, " (%s '%s')", kind, name) : "";
 }
@@ -790,7 +790,7 @@ void luaG_traceexec (lua_State *L) {
       L->hookcount = 1;  /* undo decrement to zero */
     ci->u.l.savedpc--;  /* undo increment (resume will increment it again) */
     ci->callstatus |= CIST_HOOKYIELD;  /* mark that it yielded */
-    ci->func = L->top - 1;  /* protect stack below results */
+    L->func = ci->func = L->top - 1;  /* protect stack below results */
     luaD_throw(L, LUA_YIELD);
   }
 }

+ 5 - 5
ldo.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldo.c,v 2.162 2017/07/27 13:50:16 roberto Exp roberto $
+** $Id: ldo.c,v 2.163 2017/10/31 17:54:35 roberto Exp roberto $
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 */
@@ -368,7 +368,7 @@ int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) {
     }
     L->oldpc = ci->previous->u.l.savedpc;  /* 'oldpc' for caller function */
   }
-  res = ci->func;  /* res == final position of 1st result */
+  res = L->func;  /* res == final position of 1st result */
   L->ci = ci->previous;  /* back to caller */
   L->func -= L->func->stkci.previous;
   lua_assert(L->func == L->ci->func);
@@ -604,7 +604,7 @@ static void resume (lua_State *L, void *ud) {
   else {  /* resuming from previous yield */
     lua_assert(L->status == LUA_YIELD);
     L->status = LUA_OK;  /* mark that it is running (again) */
-    ci->func = restorestack(L, ci->extra);
+    L->func = ci->func = restorestack(L, ci->extra);
     if (isLua(ci))  /* yielded inside a hook? */
       luaV_execute(L);  /* just continue running Lua code */
     else {  /* 'common' yield */
@@ -679,14 +679,14 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx,
       luaG_runerror(L, "attempt to yield from outside a coroutine");
   }
   L->status = LUA_YIELD;
-  ci->extra = savestack(L, ci->func);  /* save current 'func' */
+  ci->extra = savestack(L, L->func);  /* save current 'func' */
   if (isLua(ci)) {  /* inside a hook? */
     api_check(L, k == NULL, "hooks cannot continue after yielding");
   }
   else {
     if ((ci->u.c.k = k) != NULL)  /* is there a continuation? */
       ci->u.c.ctx = ctx;  /* save context */
-    ci->func = L->top - nresults - 1;  /* protect stack below results */
+    L->func = ci->func = L->top - nresults - 1;  /* protect stack below results */
     luaD_throw(L, LUA_YIELD);
   }
   lua_assert(ci->callstatus & CIST_HOOKED);  /* must be inside a hook */

+ 2 - 2
ltests.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltests.c,v 2.224 2017/10/01 19:17:51 roberto Exp roberto $
+** $Id: ltests.c,v 2.225 2017/10/04 21:56:32 roberto Exp roberto $
 ** Internal Module for Debugging of the Lua Implementation
 ** See Copyright Notice in lua.h
 */
@@ -46,7 +46,7 @@ void *l_Trick = 0;
 int islocked = 0;
 
 
-#define obj_at(L,k)	s2v(L->ci->func + (k))
+#define obj_at(L,k)	s2v(L->func + (k))
 
 
 static int runC (lua_State *L, lua_State *L1, const char *pc);

+ 12 - 13
lvm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lvm.c,v 2.299 2017/10/04 21:56:32 roberto Exp roberto $
+** $Id: lvm.c,v 2.300 2017/10/31 17:54:35 roberto Exp roberto $
 ** Lua virtual machine
 ** See Copyright Notice in lua.h
 */
@@ -659,7 +659,7 @@ static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,
 */
 void luaV_finishOp (lua_State *L) {
   CallInfo *ci = L->ci;
-  StkId base = ci->func + 1;
+  StkId base = L->func + 1;
   Instruction inst = *(ci->u.l.savedpc - 1);  /* interrupted instruction */
   OpCode op = GET_OPCODE(inst);
   switch (op) {  /* finish its execution */
@@ -699,7 +699,7 @@ void luaV_finishOp (lua_State *L) {
         luaV_concat(L, total);  /* concat them (may yield again) */
       }
       /* move final result to final position */
-      setobjs2s(L, ci->func + 1 + GETARG_A(inst), L->top - 1);
+      setobjs2s(L, L->func + 1 + GETARG_A(inst), L->top - 1);
       L->top = ci->top;  /* restore top */
       break;
     }
@@ -771,7 +771,7 @@ void luaV_finishOp (lua_State *L) {
 ** stack, and change the hooks.
 */
 #define Protect(code)  \
-  { savepc(L); {code;}; base = ci->func + 1; updatemask(L); }
+  { savepc(L); {code;}; base = L->func + 1; updatemask(L); }
 
 
 #define checkGC(L,c)  \
@@ -796,23 +796,23 @@ void luaV_execute (lua_State *L) {
   CallInfo *ci = L->ci;
   LClosure *cl;
   TValue *k;
-  StkId base;  /* local copy of 'ci->func + 1' */
+  StkId base;  /* local copy of 'L->func + 1' */
   int mask;  /* local copy of 'L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)' */
   const Instruction *pc;  /* local copy of 'ci->u.l.savedpc' */
   ci->callstatus |= CIST_FRESH;  /* fresh invocation of 'luaV_execute" */
  newframe:  /* reentry point when frame changes (call/return) */
   lua_assert(ci == L->ci);
-  cl = clLvalue(s2v(ci->func));  /* local reference to function's closure */
+  cl = clLvalue(s2v(L->func));  /* local reference to function's closure */
   k = cl->p->k;  /* local reference to function's constant table */
   updatemask(L);
-  base = ci->func + 1;
+  base = L->func + 1;
   pc = ci->u.l.savedpc;
   /* main loop of interpreter */
   for (;;) {
     Instruction i;
     StkId ra;
     vmfetch();
-    lua_assert(base == ci->func + 1);
+    lua_assert(base == L->func + 1);
     lua_assert(base <= L->top && L->top < L->stack + L->stacksize);
     vmdispatch (GET_OPCODE(i)) {
       vmcase(OP_MOVE) {
@@ -1377,12 +1377,12 @@ void luaV_execute (lua_State *L) {
           CallInfo *nci = L->ci;  /* called frame (new) */
           CallInfo *oci = nci->previous;  /* caller frame (old) */
           StkId nfunc = nci->func;  /* called function */
-          StkId ofunc = oci->func;  /* caller function */
+          StkId ofunc = nfunc - nfunc->stkci.previous;  /* caller function */
           /* last stack slot filled by 'precall' */
-          StkId lim = nci->func + 1 + getproto(s2v(nfunc))->numparams;
+          StkId lim = nfunc + 1 + getproto(s2v(nfunc))->numparams;
           int aux;
           /* close all upvalues from previous call */
-          if (cl->p->sizep > 0) luaF_close(L, oci->func + 1);
+          if (cl->p->sizep > 0) luaF_close(L, ofunc + 1);
           /* move new frame into old one */
           for (aux = 0; nfunc + aux < lim; aux++)
             setobjs2s(L, ofunc + aux, nfunc + aux);
@@ -1391,8 +1391,7 @@ void luaV_execute (lua_State *L) {
           oci->callstatus |= CIST_TAIL;  /* function was tail called */
           ci = L->ci = oci;  /* remove new frame */
           L->func = ofunc;
-          lua_assert(L->top ==
-                     oci->func + 1 + getproto(s2v(ofunc))->maxstacksize);
+          lua_assert(L->top == ofunc + 1 + getproto(s2v(ofunc))->maxstacksize);
           goto newframe;  /* restart luaV_execute over new Lua function */
         }
         vmbreak;