aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-11-04 10:57:02 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-11-04 10:57:02 -0200
commit93fd67b7936f0f1fc20645d18eb85a193887c315 (patch)
tree11cd249fad6b0253f0de48b94c08ab08671b8544
parent6bb3e40a8d2cdb64a6ac1962d8748dd638a11721 (diff)
downloadlua-93fd67b7936f0f1fc20645d18eb85a193887c315.tar.gz
lua-93fd67b7936f0f1fc20645d18eb85a193887c315.tar.bz2
lua-93fd67b7936f0f1fc20645d18eb85a193887c315.zip
no more 'CallInfo' structure
-rw-r--r--ldo.c64
-rw-r--r--ldo.h5
-rw-r--r--lstate.c57
-rw-r--r--lstate.h15
-rw-r--r--lvm.c9
5 files changed, 31 insertions, 119 deletions
diff --git a/ldo.c b/ldo.c
index 5cd518ef..bb189565 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.167 2017/11/03 17:22:54 roberto Exp roberto $ 2** $Id: ldo.c,v 2.168 2017/11/03 20:41:05 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*/
@@ -157,15 +157,11 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
157** =================================================================== 157** ===================================================================
158*/ 158*/
159static void correctstack (lua_State *L, StkId oldstack) { 159static void correctstack (lua_State *L, StkId oldstack) {
160 CallInfo *ci;
161 UpVal *up; 160 UpVal *up;
162 L->top = (L->top - oldstack) + L->stack; 161 L->top = (L->top - oldstack) + L->stack;
163 L->func = (L->func - oldstack) + L->stack; 162 L->func = (L->func - oldstack) + L->stack;
164 for (up = L->openupval; up != NULL; up = up->u.open.next) 163 for (up = L->openupval; up != NULL; up = up->u.open.next)
165 up->v = s2v((uplevel(up) - oldstack) + L->stack); 164 up->v = s2v((uplevel(up) - oldstack) + L->stack);
166 for (ci = L->ci; ci != NULL; ci = ci->previous) {
167 ci->func = (ci->func - oldstack) + L->stack;
168 }
169} 165}
170 166
171 167
@@ -223,10 +219,6 @@ void luaD_shrinkstack (lua_State *L) {
223 int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK; 219 int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK;
224 if (goodsize > LUAI_MAXSTACK) 220 if (goodsize > LUAI_MAXSTACK)
225 goodsize = LUAI_MAXSTACK; /* respect stack limit */ 221 goodsize = LUAI_MAXSTACK; /* respect stack limit */
226 if (L->stacksize > LUAI_MAXSTACK) /* had been handling stack overflow? */
227 luaE_freeCI(L); /* free all CIs (list grew because of an error) */
228 else
229 luaE_shrinkCI(L); /* shrink list */
230 /* if thread is currently not handling a stack overflow and its 222 /* if thread is currently not handling a stack overflow and its
231 good size is smaller than current size, shrink its stack */ 223 good size is smaller than current size, shrink its stack */
232 if (inuse <= (LUAI_MAXSTACK - EXTRA_STACK) && 224 if (inuse <= (LUAI_MAXSTACK - EXTRA_STACK) &&
@@ -363,7 +355,7 @@ static int moveresults (lua_State *L, StkId firstResult, StkId res,
363** moves current number of results to proper place; returns 0 iff call 355** moves current number of results to proper place; returns 0 iff call
364** wanted multiple (variable number of) results. 356** wanted multiple (variable number of) results.
365*/ 357*/
366int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) { 358int luaD_poscall (lua_State *L, StkId firstResult, int nres) {
367 StkId res = L->func; /* res == final position of 1st result */ 359 StkId res = L->func; /* res == final position of 1st result */
368 int wanted = res->stkci.nresults; 360 int wanted = res->stkci.nresults;
369 if (L->hookmask & (LUA_MASKRET | LUA_MASKLINE)) { 361 if (L->hookmask & (LUA_MASKRET | LUA_MASKLINE)) {
@@ -376,18 +368,12 @@ int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) {
376 /* 'oldpc' for caller function */ 368 /* 'oldpc' for caller function */
377 L->oldpc = (res - res->stkci.previous)->stkci.u.l.savedpc; 369 L->oldpc = (res - res->stkci.previous)->stkci.u.l.savedpc;
378 } 370 }
379 L->ci = ci->previous; /* back to caller */
380 L->func = res - res->stkci.previous; 371 L->func = res - res->stkci.previous;
381 lua_assert(L->func == L->ci->func);
382 /* move results to proper place */ 372 /* move results to proper place */
383 return moveresults(L, firstResult, res, nres, wanted); 373 return moveresults(L, firstResult, res, nres, wanted);
384} 374}
385 375
386 376
387
388#define next_ci(L) (L->ci = (L->ci->next ? L->ci->next : luaE_extendCI(L)))
389
390
391/* 377/*
392** Prepares a function call: checks the stack, creates a new CallInfo 378** Prepares a function call: checks the stack, creates a new CallInfo
393** entry, fills in the relevant information, calls hook if needed. 379** entry, fills in the relevant information, calls hook if needed.
@@ -398,7 +384,6 @@ int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) {
398int luaD_precall (lua_State *L, StkId func, int nresults) { 384int luaD_precall (lua_State *L, StkId func, int nresults) {
399 lua_CFunction f; 385 lua_CFunction f;
400 TValue *funcv = s2v(func); 386 TValue *funcv = s2v(func);
401 CallInfo *ci;
402 switch (ttype(funcv)) { 387 switch (ttype(funcv)) {
403 case LUA_TCCL: /* C closure */ 388 case LUA_TCCL: /* C closure */
404 f = clCvalue(funcv)->f; 389 f = clCvalue(funcv)->f;
@@ -408,10 +393,9 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
408 Cfunc: { 393 Cfunc: {
409 int n; /* number of returns */ 394 int n; /* number of returns */
410 checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ 395 checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
411 ci = next_ci(L); /* now 'enter' new function */
412 func->stkci.nresults = nresults; 396 func->stkci.nresults = nresults;
413 func->stkci.previous = func - L->func; 397 func->stkci.previous = func - L->func;
414 L->func = ci->func = func; 398 L->func = func;
415 setfunctop(func, L->top + LUA_MINSTACK); 399 setfunctop(func, L->top + LUA_MINSTACK);
416 lua_assert(functop(func) <= L->stack_last); 400 lua_assert(functop(func) <= L->stack_last);
417 callstatus(func) = 0; 401 callstatus(func) = 0;
@@ -421,7 +405,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
421 n = (*f)(L); /* do the actual call */ 405 n = (*f)(L); /* do the actual call */
422 lua_lock(L); 406 lua_lock(L);
423 api_checknelems(L, n); 407 api_checknelems(L, n);
424 luaD_poscall(L, ci, L->top - n, n); 408 luaD_poscall(L, L->top - n, n);
425 return 1; 409 return 1;
426 } 410 }
427 case LUA_TLCL: { /* Lua function: prepare its call */ 411 case LUA_TLCL: { /* Lua function: prepare its call */
@@ -433,11 +417,10 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
433 setnilvalue(s2v(L->top++)); /* complete missing arguments */ 417 setnilvalue(s2v(L->top++)); /* complete missing arguments */
434 if (p->is_vararg) 418 if (p->is_vararg)
435 luaT_adjustvarargs(L, p, n); 419 luaT_adjustvarargs(L, p, n);
436 ci = next_ci(L); /* now 'enter' new function */
437 func->stkci.nresults = nresults; 420 func->stkci.nresults = nresults;
438 func->stkci.previous = func - L->func; 421 func->stkci.previous = func - L->func;
439 func->stkci.framesize = fsize + 1; /* size includes function itself */ 422 func->stkci.framesize = fsize + 1; /* size includes function itself */
440 L->func = ci->func = func; 423 L->func = func;
441 L->top = func + 1 + fsize; 424 L->top = func + 1 + fsize;
442 lua_assert(functop(func) <= L->stack_last); 425 lua_assert(functop(func) <= L->stack_last);
443 func->stkci.u.l.savedpc = p->code; /* starting point */ 426 func->stkci.u.l.savedpc = p->code; /* starting point */
@@ -500,7 +483,6 @@ void luaD_callnoyield (lua_State *L, StkId func, int nResults) {
500** continuation function. 483** continuation function.
501*/ 484*/
502static void finishCcall (lua_State *L, int status) { 485static void finishCcall (lua_State *L, int status) {
503 CallInfo *ci = L->ci;
504 StkId func = L->func; 486 StkId func = L->func;
505 int n; 487 int n;
506 /* must have a continuation and must be able to call it */ 488 /* must have a continuation and must be able to call it */
@@ -519,7 +501,7 @@ static void finishCcall (lua_State *L, int status) {
519 n = (*func->stkci.u.c.k)(L, status, func->stkci.u.c.ctx); 501 n = (*func->stkci.u.c.k)(L, status, func->stkci.u.c.ctx);
520 lua_lock(L); 502 lua_lock(L);
521 api_checknelems(L, n); 503 api_checknelems(L, n);
522 luaD_poscall(L, ci, L->top - n, n); /* finish 'luaD_precall' */ 504 luaD_poscall(L, L->top - n, n); /* finish 'luaD_precall' */
523} 505}
524 506
525 507
@@ -534,7 +516,7 @@ static void finishCcall (lua_State *L, int status) {
534static void unroll (lua_State *L, void *ud) { 516static void unroll (lua_State *L, void *ud) {
535 if (ud != NULL) /* error status? */ 517 if (ud != NULL) /* error status? */
536 finishCcall(L, *(int *)ud); /* finish 'lua_pcallk' callee */ 518 finishCcall(L, *(int *)ud); /* finish 'lua_pcallk' callee */
537 while (L->ci != &L->base_ci) { /* something in the stack */ 519 while (L->func != L->stack) { /* something in the stack */
538 if (!isLua(L->func)) /* C function? */ 520 if (!isLua(L->func)) /* C function? */
539 finishCcall(L, LUA_YIELD); /* complete its execution */ 521 finishCcall(L, LUA_YIELD); /* complete its execution */
540 else { /* Lua function */ 522 else { /* Lua function */
@@ -549,11 +531,13 @@ static void unroll (lua_State *L, void *ud) {
549** Try to find a suspended protected call (a "recover point") for the 531** Try to find a suspended protected call (a "recover point") for the
550** given thread. 532** given thread.
551*/ 533*/
552static CallInfo *findpcall (lua_State *L) { 534static StkId findpcall (lua_State *L) {
553 CallInfo *ci; 535 StkId func;
554 for (ci = L->ci; ci != NULL; ci = ci->previous) { /* search for a pcall */ 536 for (func = L->func;
555 if (callstatus(ci->func) & CIST_YPCALL) 537 func->stkci.previous != 0;
556 return ci; 538 func -= func->stkci.previous) {
539 if (callstatus(func) & CIST_YPCALL)
540 return func;
557 } 541 }
558 return NULL; /* no pending pcall */ 542 return NULL; /* no pending pcall */
559} 543}
@@ -566,18 +550,17 @@ static CallInfo *findpcall (lua_State *L) {
566*/ 550*/
567static int recover (lua_State *L, int status) { 551static int recover (lua_State *L, int status) {
568 StkId oldtop; 552 StkId oldtop;
569 CallInfo *ci = findpcall(L); 553 StkId recf = findpcall(L);
570 if (ci == NULL) return 0; /* no recovery point */ 554 if (recf == NULL) return 0; /* no recovery point */
571 /* "finish" luaD_pcall */ 555 /* "finish" luaD_pcall */
572 oldtop = ci->func + ci->func->stkci.u2.funcidx; 556 oldtop = recf + recf->stkci.u2.funcidx;
573 luaF_close(L, oldtop); 557 luaF_close(L, oldtop);
574 seterrorobj(L, status, oldtop); 558 seterrorobj(L, status, oldtop);
575 L->ci = ci; 559 L->func = recf;
576 L->func = ci->func; 560 L->allowhook = getoah(callstatus(recf)); /* restore original 'allowhook' */
577 L->allowhook = getoah(callstatus(L->func)); /* restore original 'allowhook' */
578 L->nny = 0; /* should be zero to be yieldable */ 561 L->nny = 0; /* should be zero to be yieldable */
579 luaD_shrinkstack(L); 562 luaD_shrinkstack(L);
580 L->errfunc = ci->func->stkci.u.c.old_errfunc; 563 L->errfunc = recf->stkci.u.c.old_errfunc;
581 return 1; /* continue running the coroutine */ 564 return 1; /* continue running the coroutine */
582} 565}
583 566
@@ -606,7 +589,6 @@ static int resume_error (lua_State *L, const char *msg, int narg) {
606static void resume (lua_State *L, void *ud) { 589static void resume (lua_State *L, void *ud) {
607 int n = *(cast(int*, ud)); /* number of arguments */ 590 int n = *(cast(int*, ud)); /* number of arguments */
608 StkId firstArg = L->top - n; /* first argument */ 591 StkId firstArg = L->top - n; /* first argument */
609 CallInfo *ci = L->ci;
610 StkId func = L->func; 592 StkId func = L->func;
611 if (L->status == LUA_OK) { /* starting a coroutine? */ 593 if (L->status == LUA_OK) { /* starting a coroutine? */
612 if (!luaD_precall(L, firstArg - 1, LUA_MULTRET)) /* Lua function? */ 594 if (!luaD_precall(L, firstArg - 1, LUA_MULTRET)) /* Lua function? */
@@ -626,7 +608,7 @@ static void resume (lua_State *L, void *ud) {
626 api_checknelems(L, n); 608 api_checknelems(L, n);
627 firstArg = L->top - n; /* yield results come from continuation */ 609 firstArg = L->top - n; /* yield results come from continuation */
628 } 610 }
629 luaD_poscall(L, ci, firstArg, n); /* finish 'luaD_precall' */ 611 luaD_poscall(L, firstArg, n); /* finish 'luaD_precall' */
630 } 612 }
631 unroll(L, NULL); /* run continuation */ 613 unroll(L, NULL); /* run continuation */
632 } 614 }
@@ -639,7 +621,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
639 unsigned short oldnny = L->nny; /* save "number of non-yieldable" calls */ 621 unsigned short oldnny = L->nny; /* save "number of non-yieldable" calls */
640 lua_lock(L); 622 lua_lock(L);
641 if (L->status == LUA_OK) { /* may be starting a coroutine */ 623 if (L->status == LUA_OK) { /* may be starting a coroutine */
642 if (L->ci != &L->base_ci) /* not in base level? */ 624 if (L->func != L->stack) /* not in base level? */
643 return resume_error(L, "cannot resume non-suspended coroutine", nargs); 625 return resume_error(L, "cannot resume non-suspended coroutine", nargs);
644 } 626 }
645 else if (L->status != LUA_YIELD) 627 else if (L->status != LUA_YIELD)
@@ -712,7 +694,6 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx,
712int luaD_pcall (lua_State *L, Pfunc func, void *u, 694int luaD_pcall (lua_State *L, Pfunc func, void *u,
713 ptrdiff_t old_top, ptrdiff_t ef) { 695 ptrdiff_t old_top, ptrdiff_t ef) {
714 int status; 696 int status;
715 CallInfo *old_ci = L->ci;
716 ptrdiff_t oldfunc = savestack(L, L->func); 697 ptrdiff_t oldfunc = savestack(L, L->func);
717 lu_byte old_allowhooks = L->allowhook; 698 lu_byte old_allowhooks = L->allowhook;
718 unsigned short old_nny = L->nny; 699 unsigned short old_nny = L->nny;
@@ -723,7 +704,6 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u,
723 StkId oldtop = restorestack(L, old_top); 704 StkId oldtop = restorestack(L, old_top);
724 luaF_close(L, oldtop); /* close possible pending closures */ 705 luaF_close(L, oldtop); /* close possible pending closures */
725 seterrorobj(L, status, oldtop); 706 seterrorobj(L, status, oldtop);
726 L->ci = old_ci;
727 L->func = restorestack(L, oldfunc); 707 L->func = restorestack(L, oldfunc);
728 L->allowhook = old_allowhooks; 708 L->allowhook = old_allowhooks;
729 L->nny = old_nny; 709 L->nny = old_nny;
diff --git a/ldo.h b/ldo.h
index fedf70d4..4c03d594 100644
--- a/ldo.h
+++ b/ldo.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.h,v 2.30 2017/05/13 12:57:20 roberto Exp roberto $ 2** $Id: ldo.h,v 2.31 2017/06/29 15:06:44 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*/
@@ -52,8 +52,7 @@ LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
52LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 52LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);
53LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 53LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
54 ptrdiff_t oldtop, ptrdiff_t ef); 54 ptrdiff_t oldtop, ptrdiff_t ef);
55LUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, 55LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult, int nres);
56 int nres);
57LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 56LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);
58LUAI_FUNC void luaD_growstack (lua_State *L, int n); 57LUAI_FUNC void luaD_growstack (lua_State *L, int n);
59LUAI_FUNC void luaD_shrinkstack (lua_State *L); 58LUAI_FUNC void luaD_shrinkstack (lua_State *L);
diff --git a/lstate.c b/lstate.c
index 8e3177ca..76daa2e7 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.143 2017/10/31 17:54:35 roberto Exp roberto $ 2** $Id: lstate.c,v 2.144 2017/11/03 12:12:30 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*/
@@ -97,51 +97,8 @@ void luaE_setdebt (global_State *g, l_mem debt) {
97} 97}
98 98
99 99
100CallInfo *luaE_extendCI (lua_State *L) {
101 CallInfo *ci = luaM_new(L, CallInfo);
102 lua_assert(L->ci->next == NULL);
103 L->ci->next = ci;
104 ci->previous = L->ci;
105 ci->next = NULL;
106 L->nci++;
107 return ci;
108}
109
110
111/*
112** free all CallInfo structures not in use by a thread
113*/
114void luaE_freeCI (lua_State *L) {
115 CallInfo *ci = L->ci;
116 CallInfo *next = ci->next;
117 ci->next = NULL;
118 while ((ci = next) != NULL) {
119 next = ci->next;
120 luaM_free(L, ci);
121 L->nci--;
122 }
123}
124
125
126/*
127** free half of the CallInfo structures not in use by a thread
128*/
129void luaE_shrinkCI (lua_State *L) {
130 CallInfo *ci = L->ci;
131 CallInfo *next2; /* next's next */
132 /* while there are two nexts */
133 while (ci->next != NULL && (next2 = ci->next->next) != NULL) {
134 luaM_free(L, ci->next); /* free next */
135 L->nci--;
136 ci->next = next2; /* remove 'next' from the list */
137 next2->previous = ci;
138 ci = next2; /* keep next's next */
139 }
140}
141
142
143static void stack_init (lua_State *L1, lua_State *L) { 100static void stack_init (lua_State *L1, lua_State *L) {
144 int i; CallInfo *ci; 101 int i;
145 /* initialize stack array */ 102 /* initialize stack array */
146 L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, StackValue); 103 L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, StackValue);
147 L1->stacksize = BASIC_STACK_SIZE; 104 L1->stacksize = BASIC_STACK_SIZE;
@@ -149,24 +106,19 @@ static void stack_init (lua_State *L1, lua_State *L) {
149 setnilvalue(s2v(L1->stack + i)); /* erase new stack */ 106 setnilvalue(s2v(L1->stack + i)); /* erase new stack */
150 L1->top = L1->stack; 107 L1->top = L1->stack;
151 L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK; 108 L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK;
152 /* initialize first ci */ 109 /* initialize first 'function' */
153 ci = &L1->base_ci; 110 L1->func = L1->stack;
154 ci->next = ci->previous = NULL;
155 L1->func = ci->func = L1->top;
156 L1->func->stkci.previous = 0; /* end of linked list */ 111 L1->func->stkci.previous = 0; /* end of linked list */
157 L1->func->stkci.framesize = LUA_MINSTACK + 1; 112 L1->func->stkci.framesize = LUA_MINSTACK + 1;
158 callstatus(L1->func) = 0; 113 callstatus(L1->func) = 0;
159 setnilvalue(s2v(L1->top)); /* 'function' entry for this 'ci' */ 114 setnilvalue(s2v(L1->top)); /* 'function' entry for this 'ci' */
160 L1->top++; 115 L1->top++;
161 L1->ci = ci;
162} 116}
163 117
164 118
165static void freestack (lua_State *L) { 119static void freestack (lua_State *L) {
166 if (L->stack == NULL) 120 if (L->stack == NULL)
167 return; /* stack not completely built yet */ 121 return; /* stack not completely built yet */
168 L->ci = &L->base_ci; /* free the entire 'ci' list */
169 luaE_freeCI(L);
170 lua_assert(L->nci == 0); 122 lua_assert(L->nci == 0);
171 luaM_freearray(L, L->stack, L->stacksize); /* free stack array */ 123 luaM_freearray(L, L->stack, L->stacksize); /* free stack array */
172} 124}
@@ -216,7 +168,6 @@ static void f_luaopen (lua_State *L, void *ud) {
216static void preinit_thread (lua_State *L, global_State *g) { 168static void preinit_thread (lua_State *L, global_State *g) {
217 G(L) = g; 169 G(L) = g;
218 L->stack = NULL; 170 L->stack = NULL;
219 L->ci = NULL;
220 L->func = NULL; 171 L->func = NULL;
221 L->nci = 0; 172 L->nci = 0;
222 L->stacksize = 0; 173 L->stacksize = 0;
diff --git a/lstate.h b/lstate.h
index df1630ea..07cb3d3d 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 2.147 2017/11/03 12:12:30 roberto Exp roberto $ 2** $Id: lstate.h,v 2.148 2017/11/03 17:22:54 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*/
@@ -81,14 +81,6 @@ typedef struct stringtable {
81} stringtable; 81} stringtable;
82 82
83 83
84/*
85** Information about a call.
86*/
87typedef struct CallInfo {
88 StkId func; /* function index in the stack */
89 struct CallInfo *previous, *next; /* dynamic call link */
90} CallInfo;
91
92 84
93/* 85/*
94** Bits in CallInfo status 86** Bits in CallInfo status
@@ -170,7 +162,6 @@ struct lua_State {
170 lu_byte status; 162 lu_byte status;
171 StkId top; /* first free slot in the stack */ 163 StkId top; /* first free slot in the stack */
172 global_State *l_G; 164 global_State *l_G;
173 CallInfo *ci; /* call info for current function */
174 StkId func; /* current function */ 165 StkId func; /* current function */
175 const Instruction *oldpc; /* last pc traced */ 166 const Instruction *oldpc; /* last pc traced */
176 StkId stack_last; /* last free slot in the stack */ 167 StkId stack_last; /* last free slot in the stack */
@@ -179,7 +170,6 @@ struct lua_State {
179 GCObject *gclist; 170 GCObject *gclist;
180 struct lua_State *twups; /* list of threads with open upvalues */ 171 struct lua_State *twups; /* list of threads with open upvalues */
181 struct lua_longjmp *errorJmp; /* current error recover point */ 172 struct lua_longjmp *errorJmp; /* current error recover point */
182 CallInfo base_ci; /* CallInfo for first level (C calling Lua) */
183 volatile lua_Hook hook; 173 volatile lua_Hook hook;
184 ptrdiff_t errfunc; /* current error handling function (stack index) */ 174 ptrdiff_t errfunc; /* current error handling function (stack index) */
185 int stacksize; 175 int stacksize;
@@ -235,9 +225,6 @@ union GCUnion {
235 225
236LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt); 226LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);
237LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); 227LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
238LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
239LUAI_FUNC void luaE_freeCI (lua_State *L);
240LUAI_FUNC void luaE_shrinkCI (lua_State *L);
241 228
242 229
243#endif 230#endif
diff --git a/lvm.c b/lvm.c
index 28952da0..b1cf4666 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.303 2017/11/03 17:22:54 roberto Exp roberto $ 2** $Id: lvm.c,v 2.304 2017/11/03 19:33:22 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*/
@@ -796,7 +796,6 @@ void luaV_finishOp (lua_State *L) {
796 796
797 797
798void luaV_execute (lua_State *L) { 798void luaV_execute (lua_State *L) {
799 CallInfo *ci = L->ci;
800 LClosure *cl; 799 LClosure *cl;
801 TValue *k; 800 TValue *k;
802 StkId base = L->func + 1; /* local copy of 'L->func + 1' */ 801 StkId base = L->func + 1; /* local copy of 'L->func + 1' */
@@ -804,7 +803,6 @@ void luaV_execute (lua_State *L) {
804 const Instruction *pc; /* local copy of 'basepc(base)' */ 803 const Instruction *pc; /* local copy of 'basepc(base)' */
805 callstatus(base - 1) |= CIST_FRESH; /* fresh invocation of 'luaV_execute" */ 804 callstatus(base - 1) |= CIST_FRESH; /* fresh invocation of 'luaV_execute" */
806 newframe: /* reentry point when frame changes (call/return) */ 805 newframe: /* reentry point when frame changes (call/return) */
807 lua_assert(ci == L->ci);
808 cl = clLvalue(s2v(L->func)); /* local reference to function's closure */ 806 cl = clLvalue(s2v(L->func)); /* local reference to function's closure */
809 k = cl->p->k; /* local reference to function's constant table */ 807 k = cl->p->k; /* local reference to function's constant table */
810 updatemask(L); 808 updatemask(L);
@@ -1361,7 +1359,6 @@ void luaV_execute (lua_State *L) {
1361 /* else leave top for next instruction */ 1359 /* else leave top for next instruction */
1362 } 1360 }
1363 else { /* Lua function */ 1361 else { /* Lua function */
1364 ci = L->ci;
1365 base = L->func + 1; 1362 base = L->func + 1;
1366 goto newframe; /* restart luaV_execute over new Lua function */ 1363 goto newframe; /* restart luaV_execute over new Lua function */
1367 } 1364 }
@@ -1391,7 +1388,6 @@ void luaV_execute (lua_State *L) {
1391 L->top = functop(ofunc); /* correct top */ 1388 L->top = functop(ofunc); /* correct top */
1392 ofunc->stkci.u.l.savedpc = nfunc->stkci.u.l.savedpc; 1389 ofunc->stkci.u.l.savedpc = nfunc->stkci.u.l.savedpc;
1393 callstatus(ofunc) |= CIST_TAIL; /* function was tail called */ 1390 callstatus(ofunc) |= CIST_TAIL; /* function was tail called */
1394 ci = L->ci = L->ci->previous; /* remove new frame */
1395 base = ofunc + 1; 1391 base = ofunc + 1;
1396 L->func = ofunc; 1392 L->func = ofunc;
1397 lua_assert(L->top == base + getproto(s2v(ofunc))->maxstacksize); 1393 lua_assert(L->top == base + getproto(s2v(ofunc))->maxstacksize);
@@ -1403,11 +1399,10 @@ void luaV_execute (lua_State *L) {
1403 int b = GETARG_B(i); 1399 int b = GETARG_B(i);
1404 if (cl->p->sizep > 0) luaF_close(L, base); 1400 if (cl->p->sizep > 0) luaF_close(L, base);
1405 savepc(base); 1401 savepc(base);
1406 b = luaD_poscall(L, ci, ra, (b != 0 ? b - 1 : cast_int(L->top - ra))); 1402 b = luaD_poscall(L, ra, (b != 0 ? b - 1 : cast_int(L->top - ra)));
1407 if (callstatus(base - 1) & CIST_FRESH) /* local 'base' still from callee */ 1403 if (callstatus(base - 1) & CIST_FRESH) /* local 'base' still from callee */
1408 return; /* external invocation: return */ 1404 return; /* external invocation: return */
1409 else { /* invocation via reentry: continue execution */ 1405 else { /* invocation via reentry: continue execution */
1410 ci = L->ci;
1411 base = L->func + 1; 1406 base = L->func + 1;
1412 if (b) L->top = functop(base - 1); 1407 if (b) L->top = functop(base - 1);
1413 lua_assert(isLua(base - 1)); 1408 lua_assert(isLua(base - 1));