aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-11-03 10:12:30 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-11-03 10:12:30 -0200
commit54eb35a8aa0f60265cf1b4764beabe1199d66f42 (patch)
tree83bc4049d312bdbe0b8e78ed1745839fcf9a5a03 /lvm.c
parentba36180fd7b68341ad57e0fbe7a55cdfb334908d (diff)
downloadlua-54eb35a8aa0f60265cf1b4764beabe1199d66f42.tar.gz
lua-54eb35a8aa0f60265cf1b4764beabe1199d66f42.tar.bz2
lua-54eb35a8aa0f60265cf1b4764beabe1199d66f42.zip
more fields moved out of 'CallInfo'
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c54
1 files changed, 29 insertions, 25 deletions
diff --git a/lvm.c b/lvm.c
index 25b953a4..7acb387f 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.300 2017/10/31 17:54:35 roberto Exp roberto $ 2** $Id: lvm.c,v 2.301 2017/11/01 18:20:48 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*/
@@ -390,9 +390,9 @@ int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {
390 else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0) /* try 'le' */ 390 else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0) /* try 'le' */
391 return res; 391 return res;
392 else { /* try 'lt': */ 392 else { /* try 'lt': */
393 L->ci->callstatus |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */ 393 callstatus(L->func) |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */
394 res = luaT_callorderTM(L, r, l, TM_LT); 394 res = luaT_callorderTM(L, r, l, TM_LT);
395 L->ci->callstatus ^= CIST_LEQ; /* clear mark */ 395 callstatus(L->func) ^= CIST_LEQ; /* clear mark */
396 if (res < 0) 396 if (res < 0)
397 luaG_ordererror(L, l, r); 397 luaG_ordererror(L, l, r);
398 return !res; /* result is negated */ 398 return !res; /* result is negated */
@@ -679,9 +679,9 @@ void luaV_finishOp (lua_State *L) {
679 case OP_LE: case OP_LT: case OP_EQ: { 679 case OP_LE: case OP_LT: case OP_EQ: {
680 int res = !l_isfalse(s2v(L->top - 1)); 680 int res = !l_isfalse(s2v(L->top - 1));
681 L->top--; 681 L->top--;
682 if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */ 682 if (callstatus(base - 1) & CIST_LEQ) { /* "<=" using "<" ? */
683 lua_assert(op == OP_LE); 683 lua_assert(op == OP_LE);
684 ci->callstatus ^= CIST_LEQ; /* clear mark */ 684 callstatus(base - 1) ^= CIST_LEQ; /* clear mark */
685 res = !res; /* negate result */ 685 res = !res; /* negate result */
686 } 686 }
687 lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); 687 lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP);
@@ -700,17 +700,17 @@ void luaV_finishOp (lua_State *L) {
700 } 700 }
701 /* move final result to final position */ 701 /* move final result to final position */
702 setobjs2s(L, L->func + 1 + GETARG_A(inst), L->top - 1); 702 setobjs2s(L, L->func + 1 + GETARG_A(inst), L->top - 1);
703 L->top = ci->top; /* restore top */ 703 L->top = functop(base - 1); /* restore top */
704 break; 704 break;
705 } 705 }
706 case OP_TFORCALL: { 706 case OP_TFORCALL: {
707 lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_TFORLOOP); 707 lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_TFORLOOP);
708 L->top = ci->top; /* correct top */ 708 L->top = functop(base - 1); /* correct top */
709 break; 709 break;
710 } 710 }
711 case OP_CALL: { 711 case OP_CALL: {
712 if (GETARG_C(inst) - 1 >= 0) /* nresults >= 0? */ 712 if (GETARG_C(inst) - 1 >= 0) /* nresults >= 0? */
713 L->top = ci->top; /* adjust results */ 713 L->top = functop(base - 1); /* adjust results */
714 break; 714 break;
715 } 715 }
716 case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE: 716 case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE:
@@ -775,9 +775,9 @@ void luaV_finishOp (lua_State *L) {
775 775
776 776
777#define checkGC(L,c) \ 777#define checkGC(L,c) \
778 { luaC_condGC(L, L->top = (c), /* limit of live values */ \ 778 { luaC_condGC(L, L->top = (c), /* limit of live values */ \
779 Protect(L->top = ci->top)); /* restore top */ \ 779 {Protect((void)0); L->top = functop(base - 1);}); /* restore top */ \
780 luai_threadyield(L); } 780 luai_threadyield(L); }
781 781
782 782
783/* fetch an instruction and prepare its execution */ 783/* fetch an instruction and prepare its execution */
@@ -796,16 +796,15 @@ void luaV_execute (lua_State *L) {
796 CallInfo *ci = L->ci; 796 CallInfo *ci = L->ci;
797 LClosure *cl; 797 LClosure *cl;
798 TValue *k; 798 TValue *k;
799 StkId base; /* local copy of 'L->func + 1' */ 799 StkId base = L->func + 1; /* local copy of 'L->func + 1' */
800 int mask; /* local copy of 'L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)' */ 800 int mask; /* local copy of 'L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)' */
801 const Instruction *pc; /* local copy of 'ci->u.l.savedpc' */ 801 const Instruction *pc; /* local copy of 'ci->u.l.savedpc' */
802 ci->callstatus |= CIST_FRESH; /* fresh invocation of 'luaV_execute" */ 802 callstatus(base - 1) |= CIST_FRESH; /* fresh invocation of 'luaV_execute" */
803 newframe: /* reentry point when frame changes (call/return) */ 803 newframe: /* reentry point when frame changes (call/return) */
804 lua_assert(ci == L->ci); 804 lua_assert(ci == L->ci);
805 cl = clLvalue(s2v(L->func)); /* local reference to function's closure */ 805 cl = clLvalue(s2v(L->func)); /* local reference to function's closure */
806 k = cl->p->k; /* local reference to function's constant table */ 806 k = cl->p->k; /* local reference to function's constant table */
807 updatemask(L); 807 updatemask(L);
808 base = L->func + 1;
809 pc = ci->u.l.savedpc; 808 pc = ci->u.l.savedpc;
810 /* main loop of interpreter */ 809 /* main loop of interpreter */
811 for (;;) { 810 for (;;) {
@@ -1276,7 +1275,7 @@ void luaV_execute (lua_State *L) {
1276 rb = base + b; 1275 rb = base + b;
1277 setobjs2s(L, ra, rb); 1276 setobjs2s(L, ra, rb);
1278 checkGC(L, (ra >= rb ? ra + 1 : rb)); 1277 checkGC(L, (ra >= rb ? ra + 1 : rb));
1279 L->top = ci->top; /* restore top */ 1278 L->top = functop(base - 1); /* restore top */
1280 vmbreak; 1279 vmbreak;
1281 } 1280 }
1282 vmcase(OP_CLOSE) { 1281 vmcase(OP_CLOSE) {
@@ -1355,11 +1354,12 @@ void luaV_execute (lua_State *L) {
1355 Protect(isC = luaD_precall(L, ra, nresults)); 1354 Protect(isC = luaD_precall(L, ra, nresults));
1356 if (isC) { /* C function? */ 1355 if (isC) { /* C function? */
1357 if (nresults >= 0) /* fixed number of results? */ 1356 if (nresults >= 0) /* fixed number of results? */
1358 L->top = ci->top; /* correct top */ 1357 L->top = functop(base - 1); /* correct top */
1359 /* else leave top for next instruction */ 1358 /* else leave top for next instruction */
1360 } 1359 }
1361 else { /* Lua function */ 1360 else { /* Lua function */
1362 ci = L->ci; 1361 ci = L->ci;
1362 base = L->func + 1;
1363 goto newframe; /* restart luaV_execute over new Lua function */ 1363 goto newframe; /* restart luaV_execute over new Lua function */
1364 } 1364 }
1365 vmbreak; 1365 vmbreak;
@@ -1386,12 +1386,14 @@ void luaV_execute (lua_State *L) {
1386 /* move new frame into old one */ 1386 /* move new frame into old one */
1387 for (aux = 0; nfunc + aux < lim; aux++) 1387 for (aux = 0; nfunc + aux < lim; aux++)
1388 setobjs2s(L, ofunc + aux, nfunc + aux); 1388 setobjs2s(L, ofunc + aux, nfunc + aux);
1389 oci->top = L->top = ofunc + (L->top - nfunc); /* correct top */ 1389 ofunc->stkci.framesize = L->top - nfunc;
1390 L->top = functop(ofunc); /* correct top */
1390 oci->u.l.savedpc = nci->u.l.savedpc; 1391 oci->u.l.savedpc = nci->u.l.savedpc;
1391 oci->callstatus |= CIST_TAIL; /* function was tail called */ 1392 callstatus(ofunc) |= CIST_TAIL; /* function was tail called */
1392 ci = L->ci = oci; /* remove new frame */ 1393 ci = L->ci = oci; /* remove new frame */
1394 base = ofunc + 1;
1393 L->func = ofunc; 1395 L->func = ofunc;
1394 lua_assert(L->top == ofunc + 1 + getproto(s2v(ofunc))->maxstacksize); 1396 lua_assert(L->top == base + getproto(s2v(ofunc))->maxstacksize);
1395 goto newframe; /* restart luaV_execute over new Lua function */ 1397 goto newframe; /* restart luaV_execute over new Lua function */
1396 } 1398 }
1397 vmbreak; 1399 vmbreak;
@@ -1401,14 +1403,15 @@ void luaV_execute (lua_State *L) {
1401 if (cl->p->sizep > 0) luaF_close(L, base); 1403 if (cl->p->sizep > 0) luaF_close(L, base);
1402 savepc(L); 1404 savepc(L);
1403 b = luaD_poscall(L, ci, ra, (b != 0 ? b - 1 : cast_int(L->top - ra))); 1405 b = luaD_poscall(L, ci, ra, (b != 0 ? b - 1 : cast_int(L->top - ra)));
1404 if (ci->callstatus & CIST_FRESH) /* local 'ci' still from callee */ 1406 if (callstatus(base - 1) & CIST_FRESH) /* local 'base' still from callee */
1405 return; /* external invocation: return */ 1407 return; /* external invocation: return */
1406 else { /* invocation via reentry: continue execution */ 1408 else { /* invocation via reentry: continue execution */
1407 ci = L->ci; 1409 ci = L->ci;
1408 if (b) L->top = ci->top; 1410 base = L->func + 1;
1409 lua_assert(isLua(ci)); 1411 if (b) L->top = functop(base - 1);
1412 lua_assert(isLua(L->func));
1410 lua_assert(GET_OPCODE(*((ci)->u.l.savedpc - 1)) == OP_CALL); 1413 lua_assert(GET_OPCODE(*((ci)->u.l.savedpc - 1)) == OP_CALL);
1411 goto newframe; /* restart luaV_execute over new Lua function */ 1414 goto newframe; /* restart luaV_execute over previous Lua function */
1412 } 1415 }
1413 } 1416 }
1414 vmcase(OP_FORLOOP) { 1417 vmcase(OP_FORLOOP) {
@@ -1473,7 +1476,7 @@ void luaV_execute (lua_State *L) {
1473 setobjs2s(L, cb, ra); 1476 setobjs2s(L, cb, ra);
1474 L->top = cb + 3; /* func. + 2 args (state and index) */ 1477 L->top = cb + 3; /* func. + 2 args (state and index) */
1475 Protect(luaD_call(L, cb, GETARG_C(i))); 1478 Protect(luaD_call(L, cb, GETARG_C(i)));
1476 L->top = ci->top; 1479 L->top = functop(base - 1);
1477 i = *(pc++); /* go to next instruction */ 1480 i = *(pc++); /* go to next instruction */
1478 ra = RA(i); 1481 ra = RA(i);
1479 lua_assert(GET_OPCODE(i) == OP_TFORLOOP); 1482 lua_assert(GET_OPCODE(i) == OP_TFORLOOP);
@@ -1507,7 +1510,8 @@ void luaV_execute (lua_State *L) {
1507 last--; 1510 last--;
1508 luaC_barrierback(L, h, val); 1511 luaC_barrierback(L, h, val);
1509 } 1512 }
1510 L->top = ci->top; /* correct top (in case of previous open call) */ 1513 /* correct top (in case of previous open call) */
1514 L->top = functop(base - 1);
1511 vmbreak; 1515 vmbreak;
1512 } 1516 }
1513 vmcase(OP_CLOSURE) { 1517 vmcase(OP_CLOSURE) {