aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-09-23 10:18:01 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-10-12 12:29:09 -0300
commit287b302acb8d925178e9edb800f0a8d18c7d35f6 (patch)
treebd662481ea995dc8c050324d553146e870434d93 /ldo.c
parent5d8ce05b3f6fad79e37ed21c1076e47a322472c6 (diff)
downloadlua-287b302acb8d925178e9edb800f0a8d18c7d35f6.tar.gz
lua-287b302acb8d925178e9edb800f0a8d18c7d35f6.tar.bz2
lua-287b302acb8d925178e9edb800f0a8d18c7d35f6.zip
Revision of stackless implementation
- more organized handling of 'nCcalls' - comments - deprecation of 'setcstacklimit'
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/ldo.c b/ldo.c
index dc3cc9fd..0a6a7169 100644
--- a/ldo.c
+++ b/ldo.c
@@ -448,10 +448,11 @@ void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) {
448 448
449 449
450/* 450/*
451** Call a function (C or Lua). The function to be called is at *func. 451** Prepares the call to a function (C or Lua). For C functions, also do
452** The arguments are on the stack, right after the function. 452** the call. The function to be called is at '*func'. The arguments are
453** When returns, all the results are on the stack, starting at the original 453** on the stack, right after the function. Returns true if the call was
454** function position. 454** made (it was a C function). When returns true, all the results are
455** on the stack, starting at the original function position.
455*/ 456*/
456int luaD_precall (lua_State *L, StkId func, int nresults) { 457int luaD_precall (lua_State *L, StkId func, int nresults) {
457 lua_CFunction f; 458 lua_CFunction f;
@@ -511,32 +512,34 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
511} 512}
512 513
513 514
514static void stackerror (lua_State *L) { 515/*
515 if (getCcalls(L) == LUAI_MAXCCALLS) 516** Call a function (C or Lua). 'inc' can be 1 (increment number
516 luaG_runerror(L, "C stack overflow"); 517** of recursive invocations in the C stack) or nyci (the same plus
517 else if (getCcalls(L) >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) 518** increment number of non-yieldable calls).
518 luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ 519*/
519} 520static void docall (lua_State *L, StkId func, int nResults, int inc) {
520 521 L->nCcalls += inc;
521
522void luaD_call (lua_State *L, StkId func, int nResults) {
523 L->nCcalls++;
524 if (getCcalls(L) >= LUAI_MAXCCALLS) 522 if (getCcalls(L) >= LUAI_MAXCCALLS)
525 stackerror(L); 523 luaE_checkcstack(L);
526 if (!luaD_precall(L, func, nResults)) /* is a Lua function? */ 524 if (!luaD_precall(L, func, nResults)) /* is a Lua function? */
527 luaV_execute(L, L->ci); /* call it */ 525 luaV_execute(L, L->ci); /* call it */
528 L->nCcalls--; 526 L->nCcalls -= inc;
529} 527}
530 528
531 529
530/*
531** External interface for 'docall'
532*/
533void luaD_call (lua_State *L, StkId func, int nResults) {
534 return docall(L, func, nResults, 1);
535}
536
532 537
533/* 538/*
534** Similar to 'luaD_call', but does not allow yields during the call. 539** Similar to 'luaD_call', but does not allow yields during the call.
535*/ 540*/
536void luaD_callnoyield (lua_State *L, StkId func, int nResults) { 541void luaD_callnoyield (lua_State *L, StkId func, int nResults) {
537 incnny(L); 542 return docall(L, func, nResults, nyci);
538 luaD_call(L, func, nResults);
539 decnny(L);
540} 543}
541 544
542 545
@@ -650,13 +653,12 @@ static void resume (lua_State *L, void *ud) {
650 int n = *(cast(int*, ud)); /* number of arguments */ 653 int n = *(cast(int*, ud)); /* number of arguments */
651 StkId firstArg = L->top - n; /* first argument */ 654 StkId firstArg = L->top - n; /* first argument */
652 CallInfo *ci = L->ci; 655 CallInfo *ci = L->ci;
653 if (L->status == LUA_OK) { /* starting a coroutine? */ 656 if (L->status == LUA_OK) /* starting a coroutine? */
654 if (!luaD_precall(L, firstArg - 1, LUA_MULTRET)) /* Lua function? */ 657 docall(L, firstArg - 1, LUA_MULTRET, 1); /* just call its body */
655 luaV_execute(L, L->ci); /* call it */
656 }
657 else { /* resuming from previous yield */ 658 else { /* resuming from previous yield */
658 lua_assert(L->status == LUA_YIELD); 659 lua_assert(L->status == LUA_YIELD);
659 L->status = LUA_OK; /* mark that it is running (again) */ 660 L->status = LUA_OK; /* mark that it is running (again) */
661 luaE_incCstack(L); /* control the C stack */
660 if (isLua(ci)) /* yielded inside a hook? */ 662 if (isLua(ci)) /* yielded inside a hook? */
661 luaV_execute(L, ci); /* just continue running Lua code */ 663 luaV_execute(L, ci); /* just continue running Lua code */
662 else { /* 'common' yield */ 664 else { /* 'common' yield */
@@ -684,9 +686,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
684 } 686 }
685 else if (L->status != LUA_YIELD) /* ended with errors? */ 687 else if (L->status != LUA_YIELD) /* ended with errors? */
686 return resume_error(L, "cannot resume dead coroutine", nargs); 688 return resume_error(L, "cannot resume dead coroutine", nargs);
687 L->nCcalls = (from) ? getCcalls(from) + 1 : 1; 689 L->nCcalls = (from) ? getCcalls(from) : 0;
688 if (getCcalls(L) >= LUAI_MAXCCALLS)
689 return resume_error(L, "C stack overflow", nargs);
690 luai_userstateresume(L, nargs); 690 luai_userstateresume(L, nargs);
691 api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs); 691 api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);
692 status = luaD_rawrunprotected(L, resume, &nargs); 692 status = luaD_rawrunprotected(L, resume, &nargs);