diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-06-01 16:09:26 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-06-01 16:09:26 -0300 |
commit | 9423e22aa35f47b392fc52a1b93c1be4c69f2aee (patch) | |
tree | 4d466663bc69a342941ea9830b17014aa76acfb2 /lvm.c | |
parent | 57f8414de1968b6f9f212140f2da14cba3b6dacb (diff) | |
download | lua-9423e22aa35f47b392fc52a1b93c1be4c69f2aee.tar.gz lua-9423e22aa35f47b392fc52a1b93c1be4c69f2aee.tar.bz2 lua-9423e22aa35f47b392fc52a1b93c1be4c69f2aee.zip |
no more L->base + ci->base only for Lua functions (C functions may use
'func')
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 35 |
1 files changed, 18 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.88 2009/05/22 15:19:54 roberto Exp $ | 2 | ** $Id: lvm.c,v 2.89 2009/05/27 17:11:27 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 | */ |
@@ -357,12 +357,13 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb, | |||
357 | */ | 357 | */ |
358 | void luaV_finishOp (lua_State *L) { | 358 | void luaV_finishOp (lua_State *L) { |
359 | CallInfo *ci = L->ci; | 359 | CallInfo *ci = L->ci; |
360 | StkId base = ci->u.l.base; | ||
360 | Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */ | 361 | Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */ |
361 | switch (GET_OPCODE(inst)) { /* finish its execution */ | 362 | switch (GET_OPCODE(inst)) { /* finish its execution */ |
362 | case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: | 363 | case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: |
363 | case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN: | 364 | case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN: |
364 | case OP_GETGLOBAL: case OP_GETTABLE: case OP_SELF: { | 365 | case OP_GETGLOBAL: case OP_GETTABLE: case OP_SELF: { |
365 | setobjs2s(L, ci->base + GETARG_A(inst), --L->top); | 366 | setobjs2s(L, base + GETARG_A(inst), --L->top); |
366 | break; | 367 | break; |
367 | } | 368 | } |
368 | case OP_LE: case OP_LT: case OP_EQ: { | 369 | case OP_LE: case OP_LT: case OP_EQ: { |
@@ -371,7 +372,7 @@ void luaV_finishOp (lua_State *L) { | |||
371 | /* metamethod should not be called when operand is K */ | 372 | /* metamethod should not be called when operand is K */ |
372 | lua_assert(!ISK(GETARG_B(inst))); | 373 | lua_assert(!ISK(GETARG_B(inst))); |
373 | if (GET_OPCODE(inst) == OP_LE && /* "<=" using "<" instead? */ | 374 | if (GET_OPCODE(inst) == OP_LE && /* "<=" using "<" instead? */ |
374 | ttisnil(luaT_gettmbyobj(L, ci->base + GETARG_B(inst), TM_LE))) | 375 | ttisnil(luaT_gettmbyobj(L, base + GETARG_B(inst), TM_LE))) |
375 | res = !res; /* invert result */ | 376 | res = !res; /* invert result */ |
376 | lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); | 377 | lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); |
377 | if (res != GETARG_A(inst)) /* condition failed? */ | 378 | if (res != GETARG_A(inst)) /* condition failed? */ |
@@ -381,14 +382,14 @@ void luaV_finishOp (lua_State *L) { | |||
381 | case OP_CONCAT: { | 382 | case OP_CONCAT: { |
382 | StkId top = L->top - 1; /* top when 'call_binTM' was called */ | 383 | StkId top = L->top - 1; /* top when 'call_binTM' was called */ |
383 | int b = GETARG_B(inst); /* first element to concatenate */ | 384 | int b = GETARG_B(inst); /* first element to concatenate */ |
384 | int total = top - 1 - (ci->base + b); /* elements yet to concatenate */ | 385 | int total = top - 1 - (base + b); /* elements yet to concatenate */ |
385 | setobj2s(L, top - 2, top); /* put TM result in proper position */ | 386 | setobj2s(L, top - 2, top); /* put TM result in proper position */ |
386 | if (total > 1) { /* are there elements to concat? */ | 387 | if (total > 1) { /* are there elements to concat? */ |
387 | L->top = top - 1; /* top is one after last element (at top-2) */ | 388 | L->top = top - 1; /* top is one after last element (at top-2) */ |
388 | luaV_concat(L, total); /* concat them (may yield again) */ | 389 | luaV_concat(L, total); /* concat them (may yield again) */ |
389 | } | 390 | } |
390 | /* move final result to final position */ | 391 | /* move final result to final position */ |
391 | setobj2s(L, ci->base + GETARG_A(inst), L->top - 1); | 392 | setobj2s(L, ci->u.l.base + GETARG_A(inst), L->top - 1); |
392 | L->top = ci->top; /* restore top */ | 393 | L->top = ci->top; /* restore top */ |
393 | break; | 394 | break; |
394 | } | 395 | } |
@@ -428,7 +429,7 @@ void luaV_finishOp (lua_State *L) { | |||
428 | #define dojump(i) { ci->u.l.savedpc += (i); luai_threadyield(L);} | 429 | #define dojump(i) { ci->u.l.savedpc += (i); luai_threadyield(L);} |
429 | 430 | ||
430 | 431 | ||
431 | #define Protect(x) { {x;}; base = ci->base; } | 432 | #define Protect(x) { {x;}; base = ci->u.l.base; } |
432 | 433 | ||
433 | 434 | ||
434 | #define arith_op(op,tm) { \ | 435 | #define arith_op(op,tm) { \ |
@@ -448,7 +449,7 @@ void luaV_execute (lua_State *L) { | |||
448 | CallInfo *ci = L->ci; | 449 | CallInfo *ci = L->ci; |
449 | LClosure *cl = &clvalue(ci->func)->l; | 450 | LClosure *cl = &clvalue(ci->func)->l; |
450 | TValue *k = cl->p->k; | 451 | TValue *k = cl->p->k; |
451 | StkId base = ci->base; | 452 | StkId base = ci->u.l.base; |
452 | lua_assert(isLua(ci)); | 453 | lua_assert(isLua(ci)); |
453 | /* main loop of interpreter */ | 454 | /* main loop of interpreter */ |
454 | for (;;) { | 455 | for (;;) { |
@@ -461,11 +462,11 @@ void luaV_execute (lua_State *L) { | |||
461 | ci->u.l.savedpc--; /* undo increment */ | 462 | ci->u.l.savedpc--; /* undo increment */ |
462 | luaD_throw(L, LUA_YIELD); | 463 | luaD_throw(L, LUA_YIELD); |
463 | } | 464 | } |
464 | base = ci->base; | 465 | base = ci->u.l.base; |
465 | } | 466 | } |
466 | /* warning!! several calls may realloc the stack and invalidate `ra' */ | 467 | /* warning!! several calls may realloc the stack and invalidate `ra' */ |
467 | ra = RA(i); | 468 | ra = RA(i); |
468 | lua_assert(base == ci->base && base == L->base); | 469 | lua_assert(base == ci->u.l.base); |
469 | lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); | 470 | lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); |
470 | switch (GET_OPCODE(i)) { | 471 | switch (GET_OPCODE(i)) { |
471 | case OP_MOVE: { | 472 | case OP_MOVE: { |
@@ -642,7 +643,7 @@ void luaV_execute (lua_State *L) { | |||
642 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ | 643 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ |
643 | if (luaD_precall(L, ra, nresults)) { /* C function? */ | 644 | if (luaD_precall(L, ra, nresults)) { /* C function? */ |
644 | if (nresults >= 0) L->top = ci->top; /* adjust results */ | 645 | if (nresults >= 0) L->top = ci->top; /* adjust results */ |
645 | base = ci->base; | 646 | base = ci->u.l.base; |
646 | continue; | 647 | continue; |
647 | } | 648 | } |
648 | else { /* Lua function */ | 649 | else { /* Lua function */ |
@@ -656,7 +657,7 @@ void luaV_execute (lua_State *L) { | |||
656 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ | 657 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ |
657 | lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); | 658 | lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); |
658 | if (luaD_precall(L, ra, LUA_MULTRET)) { /* C function? */ | 659 | if (luaD_precall(L, ra, LUA_MULTRET)) { /* C function? */ |
659 | base = ci->base; | 660 | base = ci->u.l.base; |
660 | continue; | 661 | continue; |
661 | } | 662 | } |
662 | else { | 663 | else { |
@@ -666,12 +667,12 @@ void luaV_execute (lua_State *L) { | |||
666 | StkId nfunc = nci->func; /* called function index */ | 667 | StkId nfunc = nci->func; /* called function index */ |
667 | StkId ofunc = oci->func; | 668 | StkId ofunc = oci->func; |
668 | int aux; | 669 | int aux; |
669 | if (cl->p->sizep > 0) luaF_close(L, oci->base); | 670 | if (cl->p->sizep > 0) luaF_close(L, oci->u.l.base); |
670 | L->base = oci->base = ofunc + (nci->base - nfunc); | 671 | oci->u.l.base = ofunc + (nci->u.l.base - nfunc); |
671 | for (aux = 0; nfunc+aux < L->top; aux++) /* move frame down */ | 672 | for (aux = 0; nfunc+aux < L->top; aux++) /* move frame down */ |
672 | setobjs2s(L, ofunc + aux, nfunc + aux); | 673 | setobjs2s(L, ofunc + aux, nfunc + aux); |
673 | oci->top = L->top = ofunc + aux; /* correct top */ | 674 | oci->top = L->top = ofunc + aux; /* correct top */ |
674 | lua_assert(L->top == oci->base + clvalue(ofunc)->l.p->maxstacksize); | 675 | lua_assert(L->top == oci->u.l.base + clvalue(ofunc)->l.p->maxstacksize); |
675 | oci->u.l.savedpc = nci->u.l.savedpc; | 676 | oci->u.l.savedpc = nci->u.l.savedpc; |
676 | oci->u.l.tailcalls++; /* one more call lost */ | 677 | oci->u.l.tailcalls++; /* one more call lost */ |
677 | ci = L->ci = oci; /* remove new frame */ | 678 | ci = L->ci = oci; /* remove new frame */ |
@@ -789,7 +790,7 @@ void luaV_execute (lua_State *L) { | |||
789 | case OP_VARARG: { | 790 | case OP_VARARG: { |
790 | int b = GETARG_B(i) - 1; | 791 | int b = GETARG_B(i) - 1; |
791 | int j; | 792 | int j; |
792 | int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1; | 793 | int n = cast_int(base - ci->func) - cl->p->numparams - 1; |
793 | if (b == LUA_MULTRET) { | 794 | if (b == LUA_MULTRET) { |
794 | Protect(luaD_checkstack(L, n)); | 795 | Protect(luaD_checkstack(L, n)); |
795 | ra = RA(i); /* previous call may change the stack */ | 796 | ra = RA(i); /* previous call may change the stack */ |
@@ -798,7 +799,7 @@ void luaV_execute (lua_State *L) { | |||
798 | } | 799 | } |
799 | for (j = 0; j < b; j++) { | 800 | for (j = 0; j < b; j++) { |
800 | if (j < n) { | 801 | if (j < n) { |
801 | setobjs2s(L, ra + j, ci->base - n + j); | 802 | setobjs2s(L, ra + j, base - n + j); |
802 | } | 803 | } |
803 | else { | 804 | else { |
804 | setnilvalue(ra + j); | 805 | setnilvalue(ra + j); |
@@ -815,7 +816,7 @@ void luaV_execute (lua_State *L) { | |||
815 | lua_assert(ci == L->ci); | 816 | lua_assert(ci == L->ci); |
816 | cl = &clvalue(ci->func)->l; | 817 | cl = &clvalue(ci->func)->l; |
817 | k = cl->p->k; | 818 | k = cl->p->k; |
818 | base = ci->base; | 819 | base = ci->u.l.base; |
819 | } | 820 | } |
820 | } | 821 | } |
821 | 822 | ||