diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-12-20 12:58:05 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-12-20 12:58:05 -0200 |
commit | 1d5b885437286a307a77b5d12756d73d374efd54 (patch) | |
tree | b2daefb8d44be37af3b61816eb1f966c94d44393 /lvm.c | |
parent | 4dc0be950ad67e4385400aacd25e10325a2a6e59 (diff) | |
download | lua-1d5b885437286a307a77b5d12756d73d374efd54.tar.gz lua-1d5b885437286a307a77b5d12756d73d374efd54.tar.bz2 lua-1d5b885437286a307a77b5d12756d73d374efd54.zip |
when running Lua code, there is no need to keep 'L->top' "correct";
set it only when needed.
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 26 |
1 files changed, 6 insertions, 20 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.326 2017/12/18 17:53:50 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.327 2017/12/19 16:18:04 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -464,6 +464,8 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { | |||
464 | } | 464 | } |
465 | if (tm == NULL) /* no TM? */ | 465 | if (tm == NULL) /* no TM? */ |
466 | return 0; /* objects are different */ | 466 | return 0; /* objects are different */ |
467 | if (isLuacode(L->ci)) | ||
468 | L->top = L->ci->top; /* prepare top */ | ||
467 | luaT_callTMres(L, tm, t1, t2, L->top); /* call TM */ | 469 | luaT_callTMres(L, tm, t1, t2, L->top); /* call TM */ |
468 | return !l_isfalse(s2v(L->top)); | 470 | return !l_isfalse(s2v(L->top)); |
469 | } | 471 | } |
@@ -726,20 +728,10 @@ void luaV_finishOp (lua_State *L) { | |||
726 | } | 728 | } |
727 | /* move final result to final position */ | 729 | /* move final result to final position */ |
728 | setobjs2s(L, ci->func + 1 + GETARG_A(inst), L->top - 1); | 730 | setobjs2s(L, ci->func + 1 + GETARG_A(inst), L->top - 1); |
729 | L->top = ci->top; /* restore top */ | ||
730 | break; | 731 | break; |
731 | } | 732 | } |
732 | case OP_TFORCALL: { | 733 | case OP_TFORCALL: case OP_CALL: case OP_TAILCALL: |
733 | lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_TFORLOOP); | 734 | case OP_SETTABUP: case OP_SETTABLE: |
734 | L->top = ci->top; /* correct top */ | ||
735 | break; | ||
736 | } | ||
737 | case OP_CALL: { | ||
738 | if (GETARG_C(inst) - 1 >= 0) /* nresults >= 0? */ | ||
739 | L->top = ci->top; /* adjust results */ | ||
740 | break; | ||
741 | } | ||
742 | case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE: | ||
743 | case OP_SETI: case OP_SETFIELD: | 735 | case OP_SETI: case OP_SETFIELD: |
744 | break; | 736 | break; |
745 | default: lua_assert(0); | 737 | default: lua_assert(0); |
@@ -808,7 +800,7 @@ void luaV_finishOp (lua_State *L) { | |||
808 | 800 | ||
809 | #define checkGC(L,c) \ | 801 | #define checkGC(L,c) \ |
810 | { luaC_condGC(L, L->top = (c), /* limit of live values */ \ | 802 | { luaC_condGC(L, L->top = (c), /* limit of live values */ \ |
811 | (L->top = ci->top, updatetrap(ci))); /* restore top */ \ | 803 | updatetrap(ci)); \ |
812 | luai_threadyield(L); } | 804 | luai_threadyield(L); } |
813 | 805 | ||
814 | 806 | ||
@@ -1387,7 +1379,6 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1387 | rb = base + b; | 1379 | rb = base + b; |
1388 | setobjs2s(L, ra, rb); | 1380 | setobjs2s(L, ra, rb); |
1389 | checkGC(L, (ra >= rb ? ra + 1 : rb)); | 1381 | checkGC(L, (ra >= rb ? ra + 1 : rb)); |
1390 | L->top = ci->top; /* restore top */ | ||
1391 | vmbreak; | 1382 | vmbreak; |
1392 | } | 1383 | } |
1393 | vmcase(OP_CLOSE) { | 1384 | vmcase(OP_CLOSE) { |
@@ -1491,9 +1482,6 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1491 | L->top = ra + b; /* top signals number of arguments */ | 1482 | L->top = ra + b; /* top signals number of arguments */ |
1492 | /* else previous instruction set top */ | 1483 | /* else previous instruction set top */ |
1493 | Protect(luaD_call(L, ra, nresults)); | 1484 | Protect(luaD_call(L, ra, nresults)); |
1494 | if (nresults >= 0) /* fixed number of results? */ | ||
1495 | L->top = ci->top; /* correct top */ | ||
1496 | /* else leave top for next instruction */ | ||
1497 | vmbreak; | 1485 | vmbreak; |
1498 | } | 1486 | } |
1499 | vmcase(OP_TAILCALL) { | 1487 | vmcase(OP_TAILCALL) { |
@@ -1651,7 +1639,6 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1651 | setobjs2s(L, cb, ra); | 1639 | setobjs2s(L, cb, ra); |
1652 | L->top = cb + 3; /* func. + 2 args (state and index) */ | 1640 | L->top = cb + 3; /* func. + 2 args (state and index) */ |
1653 | Protect(luaD_call(L, cb, GETARG_C(i))); | 1641 | Protect(luaD_call(L, cb, GETARG_C(i))); |
1654 | L->top = ci->top; | ||
1655 | if (trap) /* keep 'base' correct for next instruction */ | 1642 | if (trap) /* keep 'base' correct for next instruction */ |
1656 | updatebase(ci); | 1643 | updatebase(ci); |
1657 | i = *(pc++); /* go to next instruction */ | 1644 | i = *(pc++); /* go to next instruction */ |
@@ -1686,7 +1673,6 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1686 | last--; | 1673 | last--; |
1687 | luaC_barrierback(L, h, val); | 1674 | luaC_barrierback(L, h, val); |
1688 | } | 1675 | } |
1689 | L->top = ci->top; /* correct top (in case of previous open call) */ | ||
1690 | vmbreak; | 1676 | vmbreak; |
1691 | } | 1677 | } |
1692 | vmcase(OP_CLOSURE) { | 1678 | vmcase(OP_CLOSURE) { |