aboutsummaryrefslogtreecommitdiff
path: root/lvm.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 /lvm.c
parentb53dc0c4853c56694dda727793e5f6188de39dd8 (diff)
downloadlua-a69356e9e0a7525b1cebadc928a0efcce8c39b46.tar.gz
lua-a69356e9e0a7525b1cebadc928a0efcce8c39b46.tar.bz2
lua-a69356e9e0a7525b1cebadc928a0efcce8c39b46.zip
no more special cases for closures with 0 upvalues (performance is the same,
memory use a little higher, code much simpler).
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/lvm.c b/lvm.c
index 9baee90e..96159c0c 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.96 2000/03/17 13:09:12 roberto Exp roberto $ 2** $Id: lvm.c,v 1.97 2000/03/27 20:10:21 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*/
@@ -72,17 +72,27 @@ void luaV_setn (lua_State *L, Hash *t, int val) {
72} 72}
73 73
74 74
75void luaV_closure (lua_State *L, int nelems) { 75static Closure *luaV_closure (lua_State *L, lua_Type t, int nelems) {
76 if (nelems > 0) { 76 Closure *c = luaF_newclosure(L, nelems);
77 Closure *c = luaF_newclosure(L, nelems); 77 L->top -= nelems;
78 c->consts[0] = *(L->top-1); 78 while (nelems--)
79 L->top -= nelems; 79 c->consts[nelems] = *(L->top+nelems);
80 while (nelems--) 80 ttype(L->top) = t;
81 c->consts[nelems+1] = *(L->top-1+nelems); 81 clvalue(L->top) = c;
82 ttype(L->top-1) = (ttype(&c->consts[0]) == TAG_CPROTO) ? 82 incr_top;
83 TAG_CCLOSURE : TAG_LCLOSURE; 83 return c;
84 (L->top-1)->value.cl = c; 84}
85 } 85
86
87void luaV_Cclosure (lua_State *L, lua_CFunction c, int nelems) {
88 Closure *cl = luaV_closure(L, TAG_CCLOSURE, nelems);
89 cl->f.c = c;
90}
91
92
93void luaV_Lclosure (lua_State *L, Proto *l, int nelems) {
94 Closure *cl = luaV_closure(L, TAG_LCLOSURE, nelems);
95 cl->f.l = l;
86} 96}
87 97
88 98
@@ -317,13 +327,11 @@ static void adjust_varargs (lua_State *L, StkId base, int nfixargs) {
317** Executes the given Lua function. Parameters are between [base,top). 327** Executes the given Lua function. Parameters are between [base,top).
318** Returns n such that the the results are between [n,top). 328** Returns n such that the the results are between [n,top).
319*/ 329*/
320StkId luaV_execute (lua_State *L, const Closure *cl, const Proto *tf, 330StkId luaV_execute (lua_State *L, const Closure *cl, register StkId base) {
321 register StkId base) { 331 const Proto *tf = cl->f.l;
322 register StkId top; /* keep top local, for performance */ 332 register StkId top; /* keep top local, for performance */
323 register const Instruction *pc = tf->code; 333 register const Instruction *pc = tf->code;
324 TString **kstr = tf->kstr; 334 TString **kstr = tf->kstr;
325 if (L->callhook)
326 luaD_callHook(L, base-1, L->callhook, "call");
327 luaD_checkstack(L, tf->maxstacksize+EXTRA_STACK); 335 luaD_checkstack(L, tf->maxstacksize+EXTRA_STACK);
328 if (tf->is_vararg) { /* varargs? */ 336 if (tf->is_vararg) { /* varargs? */
329 adjust_varargs(L, base, tf->numparams); 337 adjust_varargs(L, base, tf->numparams);
@@ -392,7 +400,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const Proto *tf,
392 break; 400 break;
393 401
394 case OP_PUSHUPVALUE: 402 case OP_PUSHUPVALUE:
395 *top++ = cl->consts[GETARG_U(i)+1]; 403 *top++ = cl->consts[GETARG_U(i)];
396 break; 404 break;
397 405
398 case OP_PUSHLOCAL: 406 case OP_PUSHLOCAL:
@@ -604,11 +612,9 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const Proto *tf,
604 break; 612 break;
605 613
606 case OP_CLOSURE: 614 case OP_CLOSURE:
607 ttype(top) = TAG_LPROTO; 615 L->top = top;
608 tfvalue(top) = tf->kproto[GETARG_A(i)]; 616 luaV_Lclosure(L, tf->kproto[GETARG_A(i)], GETARG_B(i));
609 L->top = ++top; 617 top = L->top;
610 luaV_closure(L, GETARG_B(i));
611 top -= GETARG_B(i);
612 luaC_checkGC(L); 618 luaC_checkGC(L);
613 break; 619 break;
614 620