aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-11-01 16:20:48 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-11-01 16:20:48 -0200
commitb9e76be8a691ed83a716a85c6b85cb80f66cc480 (patch)
tree851df615f2cb00ba1bdf4042336a56b7c4609a40
parentc5482468fde11c6c169da3b331a0653455f8fc94 (diff)
downloadlua-b9e76be8a691ed83a716a85c6b85cb80f66cc480.tar.gz
lua-b9e76be8a691ed83a716a85c6b85cb80f66cc480.tar.bz2
lua-b9e76be8a691ed83a716a85c6b85cb80f66cc480.zip
using 'L->func' when possible
-rw-r--r--lapi.c25
-rw-r--r--lapi.h4
-rw-r--r--ldebug.c8
-rw-r--r--ldo.c10
-rw-r--r--ltests.c4
-rw-r--r--lvm.c25
6 files changed, 37 insertions, 39 deletions
diff --git a/lapi.c b/lapi.c
index 6e9b972d..0f88e8de 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.270 2017/06/29 15:06:44 roberto Exp roberto $ 2** $Id: lapi.c,v 2.271 2017/10/11 12:38:45 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -60,13 +60,13 @@ const char lua_ident[] =
60static TValue *index2value (lua_State *L, int idx) { 60static TValue *index2value (lua_State *L, int idx) {
61 CallInfo *ci = L->ci; 61 CallInfo *ci = L->ci;
62 if (idx > 0) { 62 if (idx > 0) {
63 StkId o = ci->func + idx; 63 StkId o = L->func + idx;
64 api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index"); 64 api_check(L, idx <= ci->top - (L->func + 1), "unacceptable index");
65 if (o >= L->top) return NONVALIDVALUE; 65 if (o >= L->top) return NONVALIDVALUE;
66 else return s2v(o); 66 else return s2v(o);
67 } 67 }
68 else if (!ispseudo(idx)) { /* negative index */ 68 else if (!ispseudo(idx)) { /* negative index */
69 api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); 69 api_check(L, idx != 0 && -idx <= L->top - (L->func + 1), "invalid index");
70 return s2v(L->top + idx); 70 return s2v(L->top + idx);
71 } 71 }
72 else if (idx == LUA_REGISTRYINDEX) 72 else if (idx == LUA_REGISTRYINDEX)
@@ -74,10 +74,10 @@ static TValue *index2value (lua_State *L, int idx) {
74 else { /* upvalues */ 74 else { /* upvalues */
75 idx = LUA_REGISTRYINDEX - idx; 75 idx = LUA_REGISTRYINDEX - idx;
76 api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); 76 api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large");
77 if (ttislcf(s2v(ci->func))) /* light C function? */ 77 if (ttislcf(s2v(L->func))) /* light C function? */
78 return NONVALIDVALUE; /* it has no upvalues */ 78 return NONVALIDVALUE; /* it has no upvalues */
79 else { 79 else {
80 CClosure *func = clCvalue(s2v(ci->func)); 80 CClosure *func = clCvalue(s2v(L->func));
81 return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE; 81 return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE;
82 } 82 }
83 } 83 }
@@ -85,14 +85,13 @@ static TValue *index2value (lua_State *L, int idx) {
85 85
86 86
87static StkId index2stack (lua_State *L, int idx) { 87static StkId index2stack (lua_State *L, int idx) {
88 CallInfo *ci = L->ci;
89 if (idx > 0) { 88 if (idx > 0) {
90 StkId o = ci->func + idx; 89 StkId o = L->func + idx;
91 api_check(L, o < L->top, "unacceptable index"); 90 api_check(L, o < L->top, "unacceptable index");
92 return o; 91 return o;
93 } 92 }
94 else { /* non-positive index */ 93 else { /* non-positive index */
95 api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); 94 api_check(L, idx != 0 && -idx <= L->top - (L->func + 1), "invalid index");
96 api_check(L, !ispseudo(idx), "invalid index"); 95 api_check(L, !ispseudo(idx), "invalid index");
97 return L->top + idx; 96 return L->top + idx;
98 } 97 }
@@ -175,17 +174,17 @@ LUA_API const lua_Number *lua_version (lua_State *L) {
175LUA_API int lua_absindex (lua_State *L, int idx) { 174LUA_API int lua_absindex (lua_State *L, int idx) {
176 return (idx > 0 || ispseudo(idx)) 175 return (idx > 0 || ispseudo(idx))
177 ? idx 176 ? idx
178 : cast_int(L->top - L->ci->func) + idx; 177 : cast_int(L->top - L->func) + idx;
179} 178}
180 179
181 180
182LUA_API int lua_gettop (lua_State *L) { 181LUA_API int lua_gettop (lua_State *L) {
183 return cast_int(L->top - (L->ci->func + 1)); 182 return cast_int(L->top - (L->func + 1));
184} 183}
185 184
186 185
187LUA_API void lua_settop (lua_State *L, int idx) { 186LUA_API void lua_settop (lua_State *L, int idx) {
188 StkId func = L->ci->func; 187 StkId func = L->func;
189 lua_lock(L); 188 lua_lock(L);
190 if (idx >= 0) { 189 if (idx >= 0) {
191 api_check(L, idx <= L->stack_last - (func + 1), "new top too large"); 190 api_check(L, idx <= L->stack_last - (func + 1), "new top too large");
@@ -243,7 +242,7 @@ LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) {
243 api_checkvalidindex(L, to); 242 api_checkvalidindex(L, to);
244 setobj(L, to, fr); 243 setobj(L, to, fr);
245 if (isupvalue(toidx)) /* function upvalue? */ 244 if (isupvalue(toidx)) /* function upvalue? */
246 luaC_barrier(L, clCvalue(s2v(L->ci->func)), fr); 245 luaC_barrier(L, clCvalue(s2v(L->func)), fr);
247 /* LUA_REGISTRYINDEX does not need gc barrier 246 /* LUA_REGISTRYINDEX does not need gc barrier
248 (collector revisits it before finishing collection) */ 247 (collector revisits it before finishing collection) */
249 lua_unlock(L); 248 lua_unlock(L);
diff --git a/lapi.h b/lapi.h
index b39898eb..ce64a727 100644
--- a/lapi.h
+++ b/lapi.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.h,v 2.8 2014/07/15 21:26:50 roberto Exp roberto $ 2** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp roberto $
3** Auxiliary functions from Lua API 3** Auxiliary functions from Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -17,7 +17,7 @@
17#define adjustresults(L,nres) \ 17#define adjustresults(L,nres) \
18 { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 18 { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }
19 19
20#define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 20#define api_checknelems(L,n) api_check(L, (n) < (L->top - L->func), \
21 "not enough elements in the stack") 21 "not enough elements in the stack")
22 22
23 23
diff --git a/ldebug.c b/ldebug.c
index f3f807f1..9b6f3bbe 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.132 2017/10/04 21:56:32 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.133 2017/10/31 17:14:02 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*/
@@ -116,7 +116,7 @@ static void swapextra (lua_State *L) {
116 if (L->status == LUA_YIELD) { 116 if (L->status == LUA_YIELD) {
117 CallInfo *ci = L->ci; /* get function that yielded */ 117 CallInfo *ci = L->ci; /* get function that yielded */
118 StkId temp = ci->func; /* exchange its 'func' and 'extra' values */ 118 StkId temp = ci->func; /* exchange its 'func' and 'extra' values */
119 ci->func = restorestack(L, ci->extra); 119 L->func = ci->func = restorestack(L, ci->extra);
120 ci->extra = savestack(L, temp); 120 ci->extra = savestack(L, temp);
121 } 121 }
122} 122}
@@ -661,7 +661,7 @@ static const char *varinfo (lua_State *L, const TValue *o) {
661 kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */ 661 kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */
662 if (!kind && isinstack(L, o)) /* no? try a register */ 662 if (!kind && isinstack(L, o)) /* no? try a register */
663 kind = getobjname(ci_func(ci)->p, currentpc(ci), 663 kind = getobjname(ci_func(ci)->p, currentpc(ci),
664 cast_int(cast(StkId, o) - (ci->func + 1)), &name); 664 cast_int(cast(StkId, o) - (L->func + 1)), &name);
665 } 665 }
666 return (kind) ? luaO_pushfstring(L, " (%s '%s')", kind, name) : ""; 666 return (kind) ? luaO_pushfstring(L, " (%s '%s')", kind, name) : "";
667} 667}
@@ -790,7 +790,7 @@ void luaG_traceexec (lua_State *L) {
790 L->hookcount = 1; /* undo decrement to zero */ 790 L->hookcount = 1; /* undo decrement to zero */
791 ci->u.l.savedpc--; /* undo increment (resume will increment it again) */ 791 ci->u.l.savedpc--; /* undo increment (resume will increment it again) */
792 ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */ 792 ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */
793 ci->func = L->top - 1; /* protect stack below results */ 793 L->func = ci->func = L->top - 1; /* protect stack below results */
794 luaD_throw(L, LUA_YIELD); 794 luaD_throw(L, LUA_YIELD);
795 } 795 }
796} 796}
diff --git a/ldo.c b/ldo.c
index 4d2b3c76..46d6dcec 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.162 2017/07/27 13:50:16 roberto Exp roberto $ 2** $Id: ldo.c,v 2.163 2017/10/31 17:54:35 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*/
@@ -368,7 +368,7 @@ int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) {
368 } 368 }
369 L->oldpc = ci->previous->u.l.savedpc; /* 'oldpc' for caller function */ 369 L->oldpc = ci->previous->u.l.savedpc; /* 'oldpc' for caller function */
370 } 370 }
371 res = ci->func; /* res == final position of 1st result */ 371 res = L->func; /* res == final position of 1st result */
372 L->ci = ci->previous; /* back to caller */ 372 L->ci = ci->previous; /* back to caller */
373 L->func -= L->func->stkci.previous; 373 L->func -= L->func->stkci.previous;
374 lua_assert(L->func == L->ci->func); 374 lua_assert(L->func == L->ci->func);
@@ -604,7 +604,7 @@ static void resume (lua_State *L, void *ud) {
604 else { /* resuming from previous yield */ 604 else { /* resuming from previous yield */
605 lua_assert(L->status == LUA_YIELD); 605 lua_assert(L->status == LUA_YIELD);
606 L->status = LUA_OK; /* mark that it is running (again) */ 606 L->status = LUA_OK; /* mark that it is running (again) */
607 ci->func = restorestack(L, ci->extra); 607 L->func = ci->func = restorestack(L, ci->extra);
608 if (isLua(ci)) /* yielded inside a hook? */ 608 if (isLua(ci)) /* yielded inside a hook? */
609 luaV_execute(L); /* just continue running Lua code */ 609 luaV_execute(L); /* just continue running Lua code */
610 else { /* 'common' yield */ 610 else { /* 'common' yield */
@@ -679,14 +679,14 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx,
679 luaG_runerror(L, "attempt to yield from outside a coroutine"); 679 luaG_runerror(L, "attempt to yield from outside a coroutine");
680 } 680 }
681 L->status = LUA_YIELD; 681 L->status = LUA_YIELD;
682 ci->extra = savestack(L, ci->func); /* save current 'func' */ 682 ci->extra = savestack(L, L->func); /* save current 'func' */
683 if (isLua(ci)) { /* inside a hook? */ 683 if (isLua(ci)) { /* inside a hook? */
684 api_check(L, k == NULL, "hooks cannot continue after yielding"); 684 api_check(L, k == NULL, "hooks cannot continue after yielding");
685 } 685 }
686 else { 686 else {
687 if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ 687 if ((ci->u.c.k = k) != NULL) /* is there a continuation? */
688 ci->u.c.ctx = ctx; /* save context */ 688 ci->u.c.ctx = ctx; /* save context */
689 ci->func = L->top - nresults - 1; /* protect stack below results */ 689 L->func = ci->func = L->top - nresults - 1; /* protect stack below results */
690 luaD_throw(L, LUA_YIELD); 690 luaD_throw(L, LUA_YIELD);
691 } 691 }
692 lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */ 692 lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */
diff --git a/ltests.c b/ltests.c
index 7420fe3b..94b4cd31 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.224 2017/10/01 19:17:51 roberto Exp roberto $ 2** $Id: ltests.c,v 2.225 2017/10/04 21:56:32 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -46,7 +46,7 @@ void *l_Trick = 0;
46int islocked = 0; 46int islocked = 0;
47 47
48 48
49#define obj_at(L,k) s2v(L->ci->func + (k)) 49#define obj_at(L,k) s2v(L->func + (k))
50 50
51 51
52static int runC (lua_State *L, lua_State *L1, const char *pc); 52static int runC (lua_State *L, lua_State *L1, const char *pc);
diff --git a/lvm.c b/lvm.c
index 4fabd744..25b953a4 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.299 2017/10/04 21:56:32 roberto Exp roberto $ 2** $Id: lvm.c,v 2.300 2017/10/31 17:54:35 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*/
660void luaV_finishOp (lua_State *L) { 660void luaV_finishOp (lua_State *L) {
661 CallInfo *ci = L->ci; 661 CallInfo *ci = L->ci;
662 StkId base = ci->func + 1; 662 StkId base = L->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 */
@@ -699,7 +699,7 @@ void luaV_finishOp (lua_State *L) {
699 luaV_concat(L, total); /* concat them (may yield again) */ 699 luaV_concat(L, total); /* concat them (may yield again) */
700 } 700 }
701 /* move final result to final position */ 701 /* move final result to final position */
702 setobjs2s(L, ci->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 = ci->top; /* restore top */
704 break; 704 break;
705 } 705 }
@@ -771,7 +771,7 @@ void luaV_finishOp (lua_State *L) {
771** stack, and change the hooks. 771** stack, and change the hooks.
772*/ 772*/
773#define Protect(code) \ 773#define Protect(code) \
774 { savepc(L); {code;}; base = ci->func + 1; updatemask(L); } 774 { savepc(L); {code;}; base = L->func + 1; updatemask(L); }
775 775
776 776
777#define checkGC(L,c) \ 777#define checkGC(L,c) \
@@ -796,23 +796,23 @@ 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 'ci->func + 1' */ 799 StkId base; /* 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 ci->callstatus |= 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(ci->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 = ci->func + 1; 808 base = L->func + 1;
809 pc = ci->u.l.savedpc; 809 pc = ci->u.l.savedpc;
810 /* main loop of interpreter */ 810 /* main loop of interpreter */
811 for (;;) { 811 for (;;) {
812 Instruction i; 812 Instruction i;
813 StkId ra; 813 StkId ra;
814 vmfetch(); 814 vmfetch();
815 lua_assert(base == ci->func + 1); 815 lua_assert(base == L->func + 1);
816 lua_assert(base <= L->top && L->top < L->stack + L->stacksize); 816 lua_assert(base <= L->top && L->top < L->stack + L->stacksize);
817 vmdispatch (GET_OPCODE(i)) { 817 vmdispatch (GET_OPCODE(i)) {
818 vmcase(OP_MOVE) { 818 vmcase(OP_MOVE) {
@@ -1377,12 +1377,12 @@ void luaV_execute (lua_State *L) {
1377 CallInfo *nci = L->ci; /* called frame (new) */ 1377 CallInfo *nci = L->ci; /* called frame (new) */
1378 CallInfo *oci = nci->previous; /* caller frame (old) */ 1378 CallInfo *oci = nci->previous; /* caller frame (old) */
1379 StkId nfunc = nci->func; /* called function */ 1379 StkId nfunc = nci->func; /* called function */
1380 StkId ofunc = oci->func; /* caller function */ 1380 StkId ofunc = nfunc - nfunc->stkci.previous; /* caller function */
1381 /* last stack slot filled by 'precall' */ 1381 /* last stack slot filled by 'precall' */
1382 StkId lim = nci->func + 1 + getproto(s2v(nfunc))->numparams; 1382 StkId lim = nfunc + 1 + getproto(s2v(nfunc))->numparams;
1383 int aux; 1383 int aux;
1384 /* close all upvalues from previous call */ 1384 /* close all upvalues from previous call */
1385 if (cl->p->sizep > 0) luaF_close(L, oci->func + 1); 1385 if (cl->p->sizep > 0) luaF_close(L, ofunc + 1);
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);
@@ -1391,8 +1391,7 @@ void luaV_execute (lua_State *L) {
1391 oci->callstatus |= CIST_TAIL; /* function was tail called */ 1391 oci->callstatus |= CIST_TAIL; /* function was tail called */
1392 ci = L->ci = oci; /* remove new frame */ 1392 ci = L->ci = oci; /* remove new frame */
1393 L->func = ofunc; 1393 L->func = ofunc;
1394 lua_assert(L->top == 1394 lua_assert(L->top == ofunc + 1 + getproto(s2v(ofunc))->maxstacksize);
1395 oci->func + 1 + getproto(s2v(ofunc))->maxstacksize);
1396 goto newframe; /* restart luaV_execute over new Lua function */ 1395 goto newframe; /* restart luaV_execute over new Lua function */
1397 } 1396 }
1398 vmbreak; 1397 vmbreak;