summaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-03-29 17:19:20 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-03-29 17:19:20 -0300
commita69356e9e0a7525b1cebadc928a0efcce8c39b46 (patch)
treec676ee2997c699d3e0b036323ecbafa7ea0d786f /ldo.c
parentb53dc0c4853c56694dda727793e5f6188de39dd8 (diff)
downloadlua-github-a69356e9e0a7525b1cebadc928a0efcce8c39b46.tar.gz
no more special cases for closures with 0 upvalues (performance is the same,
memory use a little higher, code much simpler).
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c63
1 files changed, 23 insertions, 40 deletions
diff --git a/ldo.c b/ldo.c
index cde94514..d9f6d14a 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldo.c,v 1.68 2000/03/03 14:58:26 roberto Exp roberto $
+** $Id: ldo.c,v 1.69 2000/03/10 18:37:44 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -119,7 +119,7 @@ void luaD_lineHook (lua_State *L, StkId func, int line) {
}
-void luaD_callHook (lua_State *L, StkId func, lua_Dbghook callhook,
+static void luaD_callHook (lua_State *L, StkId func, lua_Dbghook callhook,
const char *event) {
if (L->allowhooks) {
lua_Dbgactreg ar;
@@ -137,40 +137,31 @@ void luaD_callHook (lua_State *L, StkId func, lua_Dbghook callhook,
}
-/*
-** Call a C function.
-** Cstack.num is the number of arguments; Cstack.lua2C points to the
-** first argument. Returns an index to the first result from C.
-*/
-static StkId callC (lua_State *L, lua_CFunction f, StkId base) {
+static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) {
+ int nup = cl->nelems; /* number of upvalues */
+ int numarg = L->top-base;
struct C_Lua_Stack oldCLS = L->Cstack;
StkId firstResult;
- int numarg = L->top - base;
+ if (nup > 0) {
+ int n = numarg;
+ luaD_checkstack(L, nup);
+ /* open space for upvalues as extra arguments */
+ while (n--) *(base+nup+n) = *(base+n);
+ L->top += nup;
+ numarg += nup;
+ /* copy upvalues into stack */
+ while (nup--) *(base+nup) = cl->consts[nup];
+ }
L->Cstack.num = numarg;
L->Cstack.lua2C = base;
L->Cstack.base = L->top;
- if (L->callhook)
- luaD_callHook(L, base-1, L->callhook, "call");
- (*f)(L); /* do the actual call */
+ (*cl->f.c)(L); /* do the actual call */
firstResult = L->Cstack.base;
L->Cstack = oldCLS;
return firstResult;
}
-static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) {
- int nup = cl->nelems; /* number of upvalues */
- int n = L->top-base; /* number of arguments (to move up) */
- luaD_checkstack(L, nup);
- /* open space for upvalues as extra arguments */
- while (n--) *(base+nup+n) = *(base+n);
- L->top += nup;
- /* copy upvalues into stack */
- while (nup--) *(base+nup) = cl->consts[nup+1];
- return callC(L, fvalue(cl->consts), base);
-}
-
-
void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults) {
StkId base = L->top - nParams;
luaD_openstack(L, base);
@@ -191,24 +182,18 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
lua_Dbghook callhook = L->callhook;
retry: /* for `function' tag method */
switch (ttype(func)) {
- case TAG_CPROTO:
- ttype(func) = TAG_CMARK;
- firstResult = callC(L, fvalue(func), func+1);
- break;
- case TAG_LPROTO:
- ttype(func) = TAG_LMARK;
- firstResult = luaV_execute(L, NULL, tfvalue(func), func+1);
- break;
case TAG_LCLOSURE: {
- Closure *c = clvalue(func);
ttype(func) = TAG_LCLMARK;
- firstResult = luaV_execute(L, c, tfvalue(c->consts), func+1);
+ if (callhook)
+ luaD_callHook(L, func, callhook, "call");
+ firstResult = luaV_execute(L, clvalue(func), func+1);
break;
}
case TAG_CCLOSURE: {
- Closure *c = clvalue(func);
ttype(func) = TAG_CCLMARK;
- firstResult = callCclosure(L, c, func+1);
+ if (callhook)
+ luaD_callHook(L, func, callhook, "call");
+ firstResult = callCclosure(L, clvalue(func), func+1);
break;
}
default: { /* `func' is not a function; check the `function' tag method */
@@ -316,9 +301,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
L->errorJmp = oldErr;
if (status) return 1; /* error code */
if (tf == NULL) return 2; /* `natural' end */
- L->top->ttype = TAG_LPROTO; /* push new function on the stack */
- L->top->value.tf = tf;
- incr_top;
+ luaV_Lclosure(L, tf, 0);
return 0;
}