aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-05-31 15:51:50 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-05-31 15:51:50 -0300
commit616438fe9ab5e3ae7d73e9ad838e9b7bdea1ea59 (patch)
tree78322d820e3af1ca6645ed08eaa65a8f0aa04fec /lvm.c
parent47eda6ebd83785908ac26f8dd06dff36a7d42664 (diff)
downloadlua-616438fe9ab5e3ae7d73e9ad838e9b7bdea1ea59.tar.gz
lua-616438fe9ab5e3ae7d73e9ad838e9b7bdea1ea59.tar.bz2
lua-616438fe9ab5e3ae7d73e9ad838e9b7bdea1ea59.zip
new way to use `vararg' parameters (with `...')
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/lvm.c b/lvm.c
index 4c5a7ec7..5363ebef 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.5 2004/05/10 17:50:51 roberto Exp roberto $ 2** $Id: lvm.c,v 2.6 2004/05/14 19:25:09 roberto Exp $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -387,8 +387,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
387 luaD_callhook(L, LUA_HOOKCALL, -1); 387 luaD_callhook(L, LUA_HOOKCALL, -1);
388 retentry: /* entry point when returning to old functions */ 388 retentry: /* entry point when returning to old functions */
389 pc = L->ci->u.l.savedpc; 389 pc = L->ci->u.l.savedpc;
390 cl = &clvalue(L->ci->func)->l;
390 base = L->base; 391 base = L->base;
391 cl = &clvalue(base - 1)->l;
392 k = cl->p->k; 392 k = cl->p->k;
393 /* main loop of interpreter */ 393 /* main loop of interpreter */
394 for (;;) { 394 for (;;) {
@@ -615,17 +615,19 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
615 pcr = luaD_precall(L, ra, LUA_MULTRET); 615 pcr = luaD_precall(L, ra, LUA_MULTRET);
616 if (pcr == PCRLUA) { 616 if (pcr == PCRLUA) {
617 /* tail call: put new frame in place of previous one */ 617 /* tail call: put new frame in place of previous one */
618 CallInfo *ci = L->ci - 1; /* previous frame */
618 int aux; 619 int aux;
619 base = (L->ci - 1)->base; /* `luaD_precall' may change the stack */ 620 StkId func = ci->func;
620 ra = RA(i); 621 StkId pfunc = (ci+1)->func; /* previous function index */
622 base = ci->base = ci->func + ((ci+1)->base - pfunc);
623 L->base = base;
621 if (L->openupval) luaF_close(L, base); 624 if (L->openupval) luaF_close(L, base);
622 for (aux = 0; ra+aux < L->top; aux++) /* move frame down */ 625 for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */
623 setobjs2s(L, base+aux-1, ra+aux); 626 setobjs2s(L, func+aux, pfunc+aux);
624 (L->ci - 1)->top = L->top = base+aux; /* correct top */ 627 ci->top = L->top = base+aux; /* correct top */
625 (L->ci - 1)->u.l.savedpc = L->ci->u.l.savedpc; 628 ci->u.l.savedpc = L->ci->u.l.savedpc;
626 (L->ci - 1)->u.l.tailcalls++; /* one more call lost */ 629 ci->u.l.tailcalls++; /* one more call lost */
627 L->ci--; /* remove new frame */ 630 L->ci--; /* remove new frame */
628 L->base = L->ci->base;
629 goto callentry; 631 goto callentry;
630 } 632 }
631 else if (pcr == PCRC) { 633 else if (pcr == PCRC) {
@@ -758,6 +760,21 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
758 base = L->base; 760 base = L->base;
759 break; 761 break;
760 } 762 }
763 case OP_VARARG: {
764 int b = GETARG_B(i) - 1;
765 int j;
766 CallInfo *ci = L->ci;
767 int n = ci->base - ci->func - cl->p->numparams - 1;
768 if (b == LUA_MULTRET) {
769 b = n;
770 L->top = ra + n;
771 }
772 for (j=0; j<b && j<n; j++)
773 setobjs2s(L, ra+j, ci->base - n + j);
774 for (; j<b; j++)
775 setnilvalue(ra+j);
776 break;
777 }
761 } 778 }
762 } 779 }
763} 780}