浏览代码

details in OP_CALL + comments

Roberto Ierusalimschy 8 年之前
父节点
当前提交
92b3deaffa
共有 1 个文件被更改,包括 12 次插入9 次删除
  1. 12 9
      lvm.c

+ 12 - 9
lvm.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lvm.c,v 2.281 2017/05/13 12:57:20 roberto Exp roberto $
+** $Id: lvm.c,v 2.282 2017/05/13 13:54:47 roberto Exp roberto $
 ** Lua virtual machine
 ** Lua virtual machine
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -1260,12 +1260,15 @@ void luaV_execute (lua_State *L) {
       vmcase(OP_CALL) {
       vmcase(OP_CALL) {
         int b = GETARG_B(i);
         int b = GETARG_B(i);
         int nresults = GETARG_C(i) - 1;
         int nresults = GETARG_C(i) - 1;
-        if (b != 0) L->top = ra+b;  /* else previous instruction set top */
-        savepc(L);
-        if (luaD_precall(L, ra, nresults)) {  /* C function? */
-          if (nresults >= 0)
-            L->top = ci->top;  /* adjust results */
-          Protect((void)0);  /* update 'base' */
+        int isC;
+        if (b != 0)  /* fixed number of arguments? */
+          L->top = ra + b;  /* top signals number of arguments */
+        /* else previous instruction set top */
+        Protect(isC = luaD_precall(L, ra, nresults));
+        if (isC) {  /* C function? */
+          if (nresults >= 0)  /* fixed number of results? */
+            L->top = ci->top;  /* correct top */
+          /* else leave top for next instruction */
         }
         }
         else {  /* Lua function */
         else {  /* Lua function */
           ci = L->ci;
           ci = L->ci;
@@ -1283,8 +1286,8 @@ void luaV_execute (lua_State *L) {
         }
         }
         else {
         else {
           /* tail call: put called frame (n) in place of caller one (o) */
           /* tail call: put called frame (n) in place of caller one (o) */
-          CallInfo *nci = L->ci;  /* called frame */
-          CallInfo *oci = nci->previous;  /* caller frame */
+          CallInfo *nci = L->ci;  /* called frame (new) */
+          CallInfo *oci = nci->previous;  /* caller frame (old) */
           StkId nfunc = nci->func;  /* called function */
           StkId nfunc = nci->func;  /* called function */
           StkId ofunc = oci->func;  /* caller function */
           StkId ofunc = oci->func;  /* caller function */
           /* last stack slot filled by 'precall' */
           /* last stack slot filled by 'precall' */