aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c79
1 files changed, 42 insertions, 37 deletions
diff --git a/lvm.c b/lvm.c
index b9d36938..1d16a7b5 100644
--- a/lvm.c
+++ b/lvm.c
@@ -64,8 +64,8 @@ int luaV_tostring (lua_State *L, TObject *obj) {
64 64
65static void traceexec (lua_State *L, lua_Hook linehook) { 65static void traceexec (lua_State *L, lua_Hook linehook) {
66 CallInfo *ci = L->ci; 66 CallInfo *ci = L->ci;
67 int *lineinfo = ci_func(ci)->f.l->lineinfo; 67 int *lineinfo = ci_func(ci)->u.l.p->lineinfo;
68 int pc = (*ci->pc - ci_func(ci)->f.l->code) - 1; 68 int pc = (*ci->pc - ci_func(ci)->u.l.p->code) - 1;
69 int newline; 69 int newline;
70 if (pc == 0) { /* may be first time? */ 70 if (pc == 0) { /* may be first time? */
71 ci->line = 1; 71 ci->line = 1;
@@ -82,30 +82,6 @@ static void traceexec (lua_State *L, lua_Hook linehook) {
82} 82}
83 83
84 84
85static Closure *luaV_closure (lua_State *L, int nelems) {
86 Closure *c = luaF_newclosure(L, nelems);
87 L->top -= nelems;
88 while (nelems--)
89 setobj(&c->upvalue[nelems], L->top+nelems);
90 setclvalue(L->top, c);
91 incr_top;
92 return c;
93}
94
95
96void luaV_Cclosure (lua_State *L, lua_CFunction c, int nelems) {
97 Closure *cl = luaV_closure(L, nelems);
98 cl->f.c = c;
99 cl->isC = 1;
100}
101
102
103void luaV_Lclosure (lua_State *L, Proto *l, int nelems) {
104 Closure *cl = luaV_closure(L, nelems);
105 cl->f.l = l;
106 cl->isC = 0;
107}
108
109 85
110/* maximum stack used by a call to a tag method (func + args) */ 86/* maximum stack used by a call to a tag method (func + args) */
111#define MAXSTACK_TM 4 87#define MAXSTACK_TM 4
@@ -376,7 +352,7 @@ static void adjust_varargs (lua_State *L, StkId base, int nfixargs) {
376** Returns n such that the the results are between [n,top). 352** Returns n such that the the results are between [n,top).
377*/ 353*/
378StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { 354StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
379 const Proto *const tf = cl->f.l; 355 const Proto *const tf = cl->u.l.p;
380 const Instruction *pc; 356 const Instruction *pc;
381 lua_Hook linehook; 357 lua_Hook linehook;
382 if (tf->is_vararg) /* varargs? */ 358 if (tf->is_vararg) /* varargs? */
@@ -406,10 +382,6 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
406 setnvalue(ra, (lua_Number)GETARG_sBc(i)); 382 setnvalue(ra, (lua_Number)GETARG_sBc(i));
407 break; 383 break;
408 } 384 }
409 case OP_LOADUPVAL: {
410 setobj(ra, cl->upvalue+GETARG_Bc(i));
411 break;
412 }
413 case OP_LOADNIL: { 385 case OP_LOADNIL: {
414 TObject *rb = RB(i); 386 TObject *rb = RB(i);
415 do { 387 do {
@@ -417,6 +389,12 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
417 } while (rb >= ra); 389 } while (rb >= ra);
418 break; 390 break;
419 } 391 }
392 case OP_GETUPVAL: {
393 int b = GETARG_B(i);
394 lua_assert(luaF_isclosed(cl, b) || cl->u.l.upvals[b] < base);
395 setobj(ra, cl->u.l.upvals[b]);
396 break;
397 }
420 case OP_GETGLOBAL: { 398 case OP_GETGLOBAL: {
421 lua_assert(ttype(KBc(i)) == LUA_TSTRING); 399 lua_assert(ttype(KBc(i)) == LUA_TSTRING);
422 luaV_getglobal(L, tsvalue(KBc(i)), ra); 400 luaV_getglobal(L, tsvalue(KBc(i)), ra);
@@ -431,6 +409,12 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
431 luaV_setglobal(L, tsvalue(KBc(i)), ra); 409 luaV_setglobal(L, tsvalue(KBc(i)), ra);
432 break; 410 break;
433 } 411 }
412 case OP_SETUPVAL: {
413 int b = GETARG_B(i);
414 lua_assert(luaF_isclosed(cl, b) || cl->u.l.upvals[b] < base);
415 setobj(cl->u.l.upvals[b], ra);
416 break;
417 }
434 case OP_SETTABLE: { 418 case OP_SETTABLE: {
435 luaV_settable(L, RB(i), RKC(i), ra); 419 luaV_settable(L, RB(i), RKC(i), ra);
436 break; 420 break;
@@ -646,13 +630,34 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
646 luaH_setnum(L, h, bc+n, ra+n); 630 luaH_setnum(L, h, bc+n, ra+n);
647 break; 631 break;
648 } 632 }
633 case OP_CLOSE: {
634 luaF_close(L, ra);
635 break;
636 }
649 case OP_CLOSURE: { 637 case OP_CLOSURE: {
650 Proto *p = tf->p[GETARG_Bc(i)]; 638 Proto *p;
651 int nup = p->nupvalues; 639 Closure *ncl;
652 luaV_checkGC(L, ra+nup); 640 int nup, j;
653 L->top = ra+nup; 641 luaV_checkGC(L, L->top);
654 luaV_Lclosure(L, p, nup); 642 p = tf->p[GETARG_Bc(i)];
655 L->top = base + tf->maxstacksize; 643 nup = p->nupvalues;
644 ncl = luaF_newLclosure(L, nup);
645 ncl->u.l.p = p;
646 for (j=0; j<nup; j++, pc++) {
647 if (GET_OPCODE(*pc) == OP_GETUPVAL) {
648 int n = GETARG_B(*pc);
649 if (!luaF_isclosed(cl, n))
650 luaF_openentry(ncl, j);
651 ncl->u.l.upvals[j] = cl->u.l.upvals[n];
652 }
653 else {
654 lua_assert(GET_OPCODE(*pc) == OP_MOVE);
655 luaF_openentry(ncl, j);
656 ncl->u.l.upvals[j] = base + GETARG_B(*pc);
657 }
658 }
659 luaF_LConlist(L, ncl);
660 setclvalue(ra, ncl);
656 break; 661 break;
657 } 662 }
658 } 663 }