diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-05-13 10:54:47 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-05-13 10:54:47 -0300 |
commit | 6d95de83c644da5f720cf468c38df9782f1c890d (patch) | |
tree | 734170c5082ae1e44ad9fe69d85b167fd4d07207 | |
parent | 5c8770f8969a73cf4ca503f54c2217f76de62e04 (diff) | |
download | lua-6d95de83c644da5f720cf468c38df9782f1c890d.tar.gz lua-6d95de83c644da5f720cf468c38df9782f1c890d.tar.bz2 lua-6d95de83c644da5f720cf468c38df9782f1c890d.zip |
no more field 'base' in CallInfo (base is always equal to 'func + 1',
with old/new vararg implementation)
-rw-r--r-- | ldebug.c | 11 | ||||
-rw-r--r-- | ldo.c | 5 | ||||
-rw-r--r-- | lstate.h | 3 | ||||
-rw-r--r-- | lvm.c | 23 |
4 files changed, 19 insertions, 23 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 2.124 2017/04/29 15:28:38 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.125 2017/05/13 13:04:33 roberto Exp roberto $ |
3 | ** Debug Interface | 3 | ** Debug Interface |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -136,7 +136,7 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n, | |||
136 | const char *name = NULL; | 136 | const char *name = NULL; |
137 | StkId base; | 137 | StkId base; |
138 | if (isLua(ci)) { | 138 | if (isLua(ci)) { |
139 | base = ci->u.l.base; | 139 | base = ci->func + 1; |
140 | name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci)); | 140 | name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci)); |
141 | } | 141 | } |
142 | else | 142 | else |
@@ -562,8 +562,9 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci, | |||
562 | ** checks are ISO C and ensure a correct result. | 562 | ** checks are ISO C and ensure a correct result. |
563 | */ | 563 | */ |
564 | static int isinstack (CallInfo *ci, const TValue *o) { | 564 | static int isinstack (CallInfo *ci, const TValue *o) { |
565 | ptrdiff_t i = o - ci->u.l.base; | 565 | StkId base = ci->func + 1; |
566 | return (0 <= i && i < (ci->top - ci->u.l.base) && ci->u.l.base + i == o); | 566 | ptrdiff_t i = o - base; |
567 | return (0 <= i && i < (ci->top - base) && base + i == o); | ||
567 | } | 568 | } |
568 | 569 | ||
569 | 570 | ||
@@ -594,7 +595,7 @@ static const char *varinfo (lua_State *L, const TValue *o) { | |||
594 | kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */ | 595 | kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */ |
595 | if (!kind && isinstack(ci, o)) /* no? try a register */ | 596 | if (!kind && isinstack(ci, o)) /* no? try a register */ |
596 | kind = getobjname(ci_func(ci)->p, currentpc(ci), | 597 | kind = getobjname(ci_func(ci)->p, currentpc(ci), |
597 | cast_int(o - ci->u.l.base), &name); | 598 | cast_int(o - (ci->func + 1)), &name); |
598 | } | 599 | } |
599 | return (kind) ? luaO_pushfstring(L, " (%s '%s')", kind, name) : ""; | 600 | return (kind) ? luaO_pushfstring(L, " (%s '%s')", kind, name) : ""; |
600 | } | 601 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.157 2016/12/13 15:52:21 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.158 2017/05/13 12:57:20 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -164,8 +164,6 @@ static void correctstack (lua_State *L, TValue *oldstack) { | |||
164 | for (ci = L->ci; ci != NULL; ci = ci->previous) { | 164 | for (ci = L->ci; ci != NULL; ci = ci->previous) { |
165 | ci->top = (ci->top - oldstack) + L->stack; | 165 | ci->top = (ci->top - oldstack) + L->stack; |
166 | ci->func = (ci->func - oldstack) + L->stack; | 166 | ci->func = (ci->func - oldstack) + L->stack; |
167 | if (isLua(ci)) | ||
168 | ci->u.l.base = (ci->u.l.base - oldstack) + L->stack; | ||
169 | } | 167 | } |
170 | } | 168 | } |
171 | 169 | ||
@@ -424,7 +422,6 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
424 | ci = next_ci(L); /* now 'enter' new function */ | 422 | ci = next_ci(L); /* now 'enter' new function */ |
425 | ci->nresults = nresults; | 423 | ci->nresults = nresults; |
426 | ci->func = func; | 424 | ci->func = func; |
427 | ci->u.l.base = func + 1; | ||
428 | L->top = ci->top = func + 1 + fsize; | 425 | L->top = ci->top = func + 1 + fsize; |
429 | lua_assert(ci->top <= L->stack_last); | 426 | lua_assert(ci->top <= L->stack_last); |
430 | ci->u.l.savedpc = p->code; /* starting point */ | 427 | ci->u.l.savedpc = p->code; /* starting point */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 2.139 2017/04/24 16:59:26 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.140 2017/05/04 13:32:01 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -96,7 +96,6 @@ typedef struct CallInfo { | |||
96 | struct CallInfo *previous, *next; /* dynamic call link */ | 96 | struct CallInfo *previous, *next; /* dynamic call link */ |
97 | union { | 97 | union { |
98 | struct { /* only for Lua functions */ | 98 | struct { /* only for Lua functions */ |
99 | StkId base; /* base for this function */ | ||
100 | const Instruction *savedpc; | 99 | const Instruction *savedpc; |
101 | } l; | 100 | } l; |
102 | struct { /* only for C functions */ | 101 | struct { /* only for C functions */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.280 2017/05/11 18:57:46 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.281 2017/05/13 12:57:20 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 | */ |
@@ -659,7 +659,7 @@ static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base, | |||
659 | */ | 659 | */ |
660 | void luaV_finishOp (lua_State *L) { | 660 | void luaV_finishOp (lua_State *L) { |
661 | CallInfo *ci = L->ci; | 661 | CallInfo *ci = L->ci; |
662 | StkId base = ci->u.l.base; | 662 | StkId base = ci->func + 1; |
663 | Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */ | 663 | Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */ |
664 | OpCode op = GET_OPCODE(inst); | 664 | OpCode op = GET_OPCODE(inst); |
665 | switch (op) { /* finish its execution */ | 665 | switch (op) { /* finish its execution */ |
@@ -696,7 +696,7 @@ void luaV_finishOp (lua_State *L) { | |||
696 | luaV_concat(L, total); /* concat them (may yield again) */ | 696 | luaV_concat(L, total); /* concat them (may yield again) */ |
697 | } | 697 | } |
698 | /* move final result to final position */ | 698 | /* move final result to final position */ |
699 | setobj2s(L, ci->u.l.base + GETARG_A(inst), L->top - 1); | 699 | setobj2s(L, ci->func + 1 + GETARG_A(inst), L->top - 1); |
700 | L->top = ci->top; /* restore top */ | 700 | L->top = ci->top; /* restore top */ |
701 | break; | 701 | break; |
702 | } | 702 | } |
@@ -753,7 +753,7 @@ void luaV_finishOp (lua_State *L) { | |||
753 | */ | 753 | */ |
754 | #define dojump(ci,i,e) \ | 754 | #define dojump(ci,i,e) \ |
755 | { int a = GETARG_A(i); \ | 755 | { int a = GETARG_A(i); \ |
756 | if (a != 0) luaF_close(L, ci->u.l.base + a - 1); \ | 756 | if (a != 0) luaF_close(L, ci->func + a); \ |
757 | pc += GETARG_sBx(i) + e; updatemask(L); } | 757 | pc += GETARG_sBx(i) + e; updatemask(L); } |
758 | 758 | ||
759 | 759 | ||
@@ -772,7 +772,7 @@ void luaV_finishOp (lua_State *L) { | |||
772 | ** stack, and change the hooks. | 772 | ** stack, and change the hooks. |
773 | */ | 773 | */ |
774 | #define Protect(code) \ | 774 | #define Protect(code) \ |
775 | { savepc(L); {code;}; base = ci->u.l.base; updatemask(L); } | 775 | { savepc(L); {code;}; base = ci->func + 1; updatemask(L); } |
776 | 776 | ||
777 | 777 | ||
778 | #define checkGC(L,c) \ | 778 | #define checkGC(L,c) \ |
@@ -797,7 +797,7 @@ void luaV_execute (lua_State *L) { | |||
797 | CallInfo *ci = L->ci; | 797 | CallInfo *ci = L->ci; |
798 | LClosure *cl; | 798 | LClosure *cl; |
799 | TValue *k; | 799 | TValue *k; |
800 | StkId base; /* local copy of 'ci->u.l.base' */ | 800 | StkId base; /* local copy of 'ci->func + 1' */ |
801 | int mask; /* local copy of 'L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)' */ | 801 | int mask; /* local copy of 'L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)' */ |
802 | const Instruction *pc; /* local copy of 'ci->u.l.savedpc' */ | 802 | const Instruction *pc; /* local copy of 'ci->u.l.savedpc' */ |
803 | ci->callstatus |= CIST_FRESH; /* fresh invocation of 'luaV_execute" */ | 803 | ci->callstatus |= CIST_FRESH; /* fresh invocation of 'luaV_execute" */ |
@@ -806,14 +806,14 @@ void luaV_execute (lua_State *L) { | |||
806 | cl = clLvalue(ci->func); /* local reference to function's closure */ | 806 | cl = clLvalue(ci->func); /* local reference to function's closure */ |
807 | k = cl->p->k; /* local reference to function's constant table */ | 807 | k = cl->p->k; /* local reference to function's constant table */ |
808 | updatemask(L); | 808 | updatemask(L); |
809 | base = ci->u.l.base; | 809 | base = ci->func + 1; |
810 | pc = ci->u.l.savedpc; | 810 | pc = ci->u.l.savedpc; |
811 | /* main loop of interpreter */ | 811 | /* main loop of interpreter */ |
812 | for (;;) { | 812 | for (;;) { |
813 | Instruction i; | 813 | Instruction i; |
814 | StkId ra; | 814 | StkId ra; |
815 | vmfetch(); | 815 | vmfetch(); |
816 | lua_assert(base == ci->u.l.base); | 816 | lua_assert(base == ci->func + 1); |
817 | lua_assert(base <= L->top && L->top < L->stack + L->stacksize); | 817 | lua_assert(base <= L->top && L->top < L->stack + L->stacksize); |
818 | vmdispatch (GET_OPCODE(i)) { | 818 | vmdispatch (GET_OPCODE(i)) { |
819 | vmcase(OP_MOVE) { | 819 | vmcase(OP_MOVE) { |
@@ -1288,19 +1288,18 @@ void luaV_execute (lua_State *L) { | |||
1288 | StkId nfunc = nci->func; /* called function */ | 1288 | StkId nfunc = nci->func; /* called function */ |
1289 | StkId ofunc = oci->func; /* caller function */ | 1289 | StkId ofunc = oci->func; /* caller function */ |
1290 | /* last stack slot filled by 'precall' */ | 1290 | /* last stack slot filled by 'precall' */ |
1291 | StkId lim = nci->u.l.base + getproto(nfunc)->numparams; | 1291 | StkId lim = nci->func + 1 + getproto(nfunc)->numparams; |
1292 | int aux; | 1292 | int aux; |
1293 | /* close all upvalues from previous call */ | 1293 | /* close all upvalues from previous call */ |
1294 | if (cl->p->sizep > 0) luaF_close(L, oci->u.l.base); | 1294 | if (cl->p->sizep > 0) luaF_close(L, oci->func + 1); |
1295 | /* move new frame into old one */ | 1295 | /* move new frame into old one */ |
1296 | for (aux = 0; nfunc + aux < lim; aux++) | 1296 | for (aux = 0; nfunc + aux < lim; aux++) |
1297 | setobjs2s(L, ofunc + aux, nfunc + aux); | 1297 | setobjs2s(L, ofunc + aux, nfunc + aux); |
1298 | oci->u.l.base = ofunc + (nci->u.l.base - nfunc); /* correct base */ | ||
1299 | oci->top = L->top = ofunc + (L->top - nfunc); /* correct top */ | 1298 | oci->top = L->top = ofunc + (L->top - nfunc); /* correct top */ |
1300 | oci->u.l.savedpc = nci->u.l.savedpc; | 1299 | oci->u.l.savedpc = nci->u.l.savedpc; |
1301 | oci->callstatus |= CIST_TAIL; /* function was tail called */ | 1300 | oci->callstatus |= CIST_TAIL; /* function was tail called */ |
1302 | ci = L->ci = oci; /* remove new frame */ | 1301 | ci = L->ci = oci; /* remove new frame */ |
1303 | lua_assert(L->top == oci->u.l.base + getproto(ofunc)->maxstacksize); | 1302 | lua_assert(L->top == oci->func + 1 + getproto(ofunc)->maxstacksize); |
1304 | goto newframe; /* restart luaV_execute over new Lua function */ | 1303 | goto newframe; /* restart luaV_execute over new Lua function */ |
1305 | } | 1304 | } |
1306 | vmbreak; | 1305 | vmbreak; |