aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-10-18 11:58:40 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-10-18 11:58:40 -0300
commit3699446aaf5c7a07af028b1ae43cf52d2d4dda59 (patch)
treef21cc5d1bef65fcb55388240706571005c2c9430 /ldo.c
parent0e5071b5fbcc244d9f8c4bae82e327ad59bccc3f (diff)
downloadlua-3699446aaf5c7a07af028b1ae43cf52d2d4dda59.tar.gz
lua-3699446aaf5c7a07af028b1ae43cf52d2d4dda59.tar.bz2
lua-3699446aaf5c7a07af028b1ae43cf52d2d4dda59.zip
Removed goto's in 'luaD_precall'
(plus a detail in lauxlib.h.)
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c51
1 files changed, 27 insertions, 24 deletions
diff --git a/ldo.c b/ldo.c
index 88b20f95..0ac12e74 100644
--- a/ldo.c
+++ b/ldo.c
@@ -511,6 +511,30 @@ l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret,
511 511
512 512
513/* 513/*
514** precall for C functions
515*/
516l_sinline CallInfo *precallC (lua_State *L, StkId func, int nresults,
517 lua_CFunction f) {
518 int n; /* number of returns */
519 CallInfo *ci;
520 checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
521 L->ci = ci = prepCallInfo(L, func, nresults, CIST_C,
522 L->top + LUA_MINSTACK);
523 lua_assert(ci->top <= L->stack_last);
524 if (l_unlikely(L->hookmask & LUA_MASKCALL)) {
525 int narg = cast_int(L->top - func) - 1;
526 luaD_hook(L, LUA_HOOKCALL, -1, 1, narg);
527 }
528 lua_unlock(L);
529 n = (*f)(L); /* do the actual call */
530 lua_lock(L);
531 api_checknelems(L, n);
532 luaD_poscall(L, ci, n);
533 return NULL;
534}
535
536
537/*
514** Prepares the call to a function (C or Lua). For C functions, also do 538** Prepares the call to a function (C or Lua). For C functions, also do
515** the call. The function to be called is at '*func'. The arguments 539** the call. The function to be called is at '*func'. The arguments
516** are on the stack, right after the function. Returns the CallInfo 540** are on the stack, right after the function. Returns the CallInfo
@@ -519,32 +543,11 @@ l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret,
519** original function position. 543** original function position.
520*/ 544*/
521CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { 545CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
522 lua_CFunction f;
523 retry:
524 switch (ttypetag(s2v(func))) { 546 switch (ttypetag(s2v(func))) {
525 case LUA_VCCL: /* C closure */ 547 case LUA_VCCL: /* C closure */
526 f = clCvalue(s2v(func))->f; 548 return precallC(L, func, nresults, clCvalue(s2v(func))->f);
527 goto Cfunc;
528 case LUA_VLCF: /* light C function */ 549 case LUA_VLCF: /* light C function */
529 f = fvalue(s2v(func)); 550 return precallC(L, func, nresults, fvalue(s2v(func)));
530 Cfunc: {
531 int n; /* number of returns */
532 CallInfo *ci;
533 checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
534 L->ci = ci = prepCallInfo(L, func, nresults, CIST_C,
535 L->top + LUA_MINSTACK);
536 lua_assert(ci->top <= L->stack_last);
537 if (l_unlikely(L->hookmask & LUA_MASKCALL)) {
538 int narg = cast_int(L->top - func) - 1;
539 luaD_hook(L, LUA_HOOKCALL, -1, 1, narg);
540 }
541 lua_unlock(L);
542 n = (*f)(L); /* do the actual call */
543 lua_lock(L);
544 api_checknelems(L, n);
545 luaD_poscall(L, ci, n);
546 return NULL;
547 }
548 case LUA_VLCL: { /* Lua function */ 551 case LUA_VLCL: { /* Lua function */
549 CallInfo *ci; 552 CallInfo *ci;
550 Proto *p = clLvalue(s2v(func))->p; 553 Proto *p = clLvalue(s2v(func))->p;
@@ -561,7 +564,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
561 } 564 }
562 default: { /* not a function */ 565 default: { /* not a function */
563 func = luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */ 566 func = luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */
564 goto retry; /* try again with metamethod */ 567 return luaD_precall(L, func, nresults); /* try again with metamethod */
565 } 568 }
566 } 569 }
567} 570}