diff options
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 60 |
1 files changed, 22 insertions, 38 deletions
@@ -1,5 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.314 2017/11/22 18:41:20 roberto Exp roberto $ | 2 | <<<<<<< lvm.c |
3 | ** $Id: lvm.c,v 2.313 2017/11/21 14:17:35 roberto Exp roberto $ | ||
4 | ======= | ||
5 | ** $Id: lvm.c,v 2.315 2017/11/22 19:15:44 roberto Exp $ | ||
6 | >>>>>>> 2.315 | ||
3 | ** Lua virtual machine | 7 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 8 | ** See Copyright Notice in lua.h |
5 | */ | 9 | */ |
@@ -829,20 +833,12 @@ void luaV_finishOp (lua_State *L) { | |||
829 | 833 | ||
830 | 834 | ||
831 | void luaV_execute (lua_State *L) { | 835 | void luaV_execute (lua_State *L) { |
832 | CallInfo *ci = L->ci; /* local copy of 'L->ci' */ | 836 | CallInfo *ci = L->ci; |
833 | LClosure *cl; | 837 | LClosure *cl = clLvalue(s2v(ci->func)); |
834 | TValue *k; | 838 | TValue *k = cl->p->k; |
835 | StkId base; /* local copy of 'ci->func + 1' */ | 839 | StkId base = ci->func + 1; |
836 | int trap; | 840 | int trap = ci->u.l.trap; |
837 | const Instruction *pc; /* local copy of 'ci->u.l.savedpc' */ | 841 | const Instruction *pc = ci->u.l.savedpc; |
838 | ci->callstatus |= CIST_FRESH; /* fresh invocation of 'luaV_execute" */ | ||
839 | newframe: /* reentry point when frame changes (call/return) */ | ||
840 | lua_assert(ci == L->ci); | ||
841 | cl = clLvalue(s2v(ci->func)); /* local reference to function's closure */ | ||
842 | k = cl->p->k; /* local reference to function's constant table */ | ||
843 | updatetrap(ci); | ||
844 | updatebase(ci); | ||
845 | pc = ci->u.l.savedpc; | ||
846 | /* main loop of interpreter */ | 842 | /* main loop of interpreter */ |
847 | for (;;) { | 843 | for (;;) { |
848 | Instruction i; | 844 | Instruction i; |
@@ -1418,20 +1414,13 @@ void luaV_execute (lua_State *L) { | |||
1418 | vmcase(OP_CALL) { | 1414 | vmcase(OP_CALL) { |
1419 | int b = GETARG_B(i); | 1415 | int b = GETARG_B(i); |
1420 | int nresults = GETARG_C(i) - 1; | 1416 | int nresults = GETARG_C(i) - 1; |
1421 | int isC; | ||
1422 | if (b != 0) /* fixed number of arguments? */ | 1417 | if (b != 0) /* fixed number of arguments? */ |
1423 | L->top = ra + b; /* top signals number of arguments */ | 1418 | L->top = ra + b; /* top signals number of arguments */ |
1424 | /* else previous instruction set top */ | 1419 | /* else previous instruction set top */ |
1425 | Protect(isC = luaD_precall(L, ra, nresults)); | 1420 | Protect(luaD_call(L, ra, nresults)); |
1426 | if (isC) { /* C function? */ | 1421 | if (nresults >= 0) /* fixed number of results? */ |
1427 | if (nresults >= 0) /* fixed number of results? */ | 1422 | L->top = ci->top; /* correct top */ |
1428 | L->top = ci->top; /* correct top */ | 1423 | /* else leave top for next instruction */ |
1429 | /* else leave top for next instruction */ | ||
1430 | } | ||
1431 | else { /* Lua function */ | ||
1432 | ci = L->ci; | ||
1433 | goto newframe; /* restart luaV_execute over new Lua function */ | ||
1434 | } | ||
1435 | vmbreak; | 1424 | vmbreak; |
1436 | } | 1425 | } |
1437 | vmcase(OP_TAILCALL) { | 1426 | vmcase(OP_TAILCALL) { |
@@ -1447,12 +1436,15 @@ void luaV_execute (lua_State *L) { | |||
1447 | b++; /* there is now one extra argument */ | 1436 | b++; /* there is now one extra argument */ |
1448 | } | 1437 | } |
1449 | if (!ttisLclosure(s2v(ra))) /* C function? */ | 1438 | if (!ttisLclosure(s2v(ra))) /* C function? */ |
1450 | Protect(luaD_precall(L, ra, LUA_MULTRET)); /* call it */ | 1439 | Protect(luaD_call(L, ra, LUA_MULTRET)); /* call it */ |
1451 | else { /* tail call */ | 1440 | else { /* tail call */ |
1452 | if (cl->p->sizep > 0) /* close upvalues from previous call */ | 1441 | if (cl->p->sizep > 0) /* close upvalues from previous call */ |
1453 | luaF_close(L, ci->func + 1); | 1442 | luaF_close(L, ci->func + 1); |
1454 | luaD_pretailcall(L, ci, ra, b); /* prepare call frame */ | 1443 | luaD_pretailcall(L, ci, ra, b); /* prepare call frame */ |
1455 | goto newframe; /* restart luaV_execute over new Lua function */ | 1444 | cl = clLvalue(s2v(ci->func)); |
1445 | k = cl->p->k; | ||
1446 | updatebase(ci); | ||
1447 | pc = ci->u.l.savedpc; | ||
1456 | } | 1448 | } |
1457 | vmbreak; | 1449 | vmbreak; |
1458 | } | 1450 | } |
@@ -1461,16 +1453,8 @@ void luaV_execute (lua_State *L) { | |||
1461 | if (cl->p->sizep > 0) | 1453 | if (cl->p->sizep > 0) |
1462 | luaF_close(L, base); | 1454 | luaF_close(L, base); |
1463 | savepc(L); | 1455 | savepc(L); |
1464 | b = luaD_poscall(L, ci, ra, (b != 0 ? b - 1 : cast_int(L->top - ra))); | 1456 | luaD_poscall(L, ci, ra, (b != 0 ? b - 1 : cast_int(L->top - ra))); |
1465 | if (ci->callstatus & CIST_FRESH) /* local 'ci' still from callee */ | 1457 | return; /* external invocation: return */ |
1466 | return; /* external invocation: return */ | ||
1467 | else { /* invocation via reentry: continue execution */ | ||
1468 | ci = L->ci; | ||
1469 | if (b) L->top = ci->top; | ||
1470 | lua_assert(isLua(ci)); | ||
1471 | lua_assert(GET_OPCODE(*((ci)->u.l.savedpc - 1)) == OP_CALL); | ||
1472 | goto newframe; /* restart luaV_execute over new Lua function */ | ||
1473 | } | ||
1474 | } | 1458 | } |
1475 | vmcase(OP_FORLOOP) { | 1459 | vmcase(OP_FORLOOP) { |
1476 | if (ttisinteger(s2v(ra))) { /* integer loop? */ | 1460 | if (ttisinteger(s2v(ra))) { /* integer loop? */ |