diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-04-04 15:12:51 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-04-04 15:12:51 -0300 |
| commit | 0316308c0d8ee9834641dacf81b43bcfd396095d (patch) | |
| tree | f2a66cb6080fe432ede5d17911d3766d37ad5fb6 /lvm.c | |
| parent | 409ee99900216d4a64a9a7029099bc7ae67a4d8e (diff) | |
| download | lua-0316308c0d8ee9834641dacf81b43bcfd396095d.tar.gz lua-0316308c0d8ee9834641dacf81b43bcfd396095d.tar.bz2 lua-0316308c0d8ee9834641dacf81b43bcfd396095d.zip | |
removed dirt optimizations that gave small gains
Diffstat (limited to '')
| -rw-r--r-- | lvm.c | 89 |
1 files changed, 27 insertions, 62 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.34 2005/03/18 18:01:37 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.35 2005/03/28 17:17:53 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 | */ |
| @@ -108,8 +108,7 @@ static void callTM (lua_State *L) { | |||
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | 110 | ||
| 111 | StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val, | 111 | void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { |
| 112 | const Instruction *pc) { | ||
| 113 | int loop; | 112 | int loop; |
| 114 | for (loop = 0; loop < MAXTAGLOOP; loop++) { | 113 | for (loop = 0; loop < MAXTAGLOOP; loop++) { |
| 115 | const TValue *tm; | 114 | const TValue *tm; |
| @@ -119,30 +118,24 @@ StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val, | |||
| 119 | if (!ttisnil(res) || /* result is no nil? */ | 118 | if (!ttisnil(res) || /* result is no nil? */ |
| 120 | (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ | 119 | (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ |
| 121 | setobj2s(L, val, res); | 120 | setobj2s(L, val, res); |
| 122 | return L->base; | 121 | return; |
| 123 | } | 122 | } |
| 124 | /* else will try the tag method */ | 123 | /* else will try the tag method */ |
| 125 | } | 124 | } |
| 126 | else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) { | 125 | else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) |
| 127 | L->ci->savedpc = pc; | ||
| 128 | luaG_typeerror(L, t, "index"); | 126 | luaG_typeerror(L, t, "index"); |
| 129 | } | ||
| 130 | if (ttisfunction(tm)) { | 127 | if (ttisfunction(tm)) { |
| 131 | L->ci->savedpc = pc; | ||
| 132 | prepTMcall(L, tm, t, key); | 128 | prepTMcall(L, tm, t, key); |
| 133 | callTMres(L, val); | 129 | callTMres(L, val); |
| 134 | return L->base; | 130 | return; |
| 135 | } | 131 | } |
| 136 | t = tm; /* else repeat with `tm' */ | 132 | t = tm; /* else repeat with `tm' */ |
| 137 | } | 133 | } |
| 138 | L->ci->savedpc = pc; | ||
| 139 | luaG_runerror(L, "loop in gettable"); | 134 | luaG_runerror(L, "loop in gettable"); |
| 140 | return NULL; /* to avoid warnings */ | ||
| 141 | } | 135 | } |
| 142 | 136 | ||
| 143 | 137 | ||
| 144 | StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val, | 138 | void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { |
| 145 | const Instruction *pc) { | ||
| 146 | int loop; | 139 | int loop; |
| 147 | for (loop = 0; loop < MAXTAGLOOP; loop++) { | 140 | for (loop = 0; loop < MAXTAGLOOP; loop++) { |
| 148 | const TValue *tm; | 141 | const TValue *tm; |
| @@ -153,26 +146,21 @@ StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val, | |||
| 153 | (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ | 146 | (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ |
| 154 | setobj2t(L, oldval, val); | 147 | setobj2t(L, oldval, val); |
| 155 | luaC_barriert(L, h, val); | 148 | luaC_barriert(L, h, val); |
| 156 | return L->base; | 149 | return; |
| 157 | } | 150 | } |
| 158 | /* else will try the tag method */ | 151 | /* else will try the tag method */ |
| 159 | } | 152 | } |
| 160 | else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) { | 153 | else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) |
| 161 | L->ci->savedpc = pc; | ||
| 162 | luaG_typeerror(L, t, "index"); | 154 | luaG_typeerror(L, t, "index"); |
| 163 | } | ||
| 164 | if (ttisfunction(tm)) { | 155 | if (ttisfunction(tm)) { |
| 165 | L->ci->savedpc = pc; | ||
| 166 | prepTMcall(L, tm, t, key); | 156 | prepTMcall(L, tm, t, key); |
| 167 | setobj2s(L, L->top+3, val); /* 3th argument */ | 157 | setobj2s(L, L->top+3, val); /* 3th argument */ |
| 168 | callTM(L); | 158 | callTM(L); |
| 169 | return L->base; | 159 | return; |
| 170 | } | 160 | } |
| 171 | t = tm; /* else repeat with `tm' */ | 161 | t = tm; /* else repeat with `tm' */ |
| 172 | } | 162 | } |
| 173 | L->ci->savedpc = pc; | ||
| 174 | luaG_runerror(L, "loop in settable"); | 163 | luaG_runerror(L, "loop in settable"); |
| 175 | return NULL; /* to avoid warnings */ | ||
| 176 | } | 164 | } |
| 177 | 165 | ||
| 178 | 166 | ||
| @@ -330,10 +318,9 @@ void luaV_concat (lua_State *L, int total, int last) { | |||
| 330 | 318 | ||
| 331 | 319 | ||
| 332 | static StkId Arith (lua_State *L, StkId ra, const TValue *rb, | 320 | static StkId Arith (lua_State *L, StkId ra, const TValue *rb, |
| 333 | const TValue *rc, TMS op, const Instruction *pc) { | 321 | const TValue *rc, TMS op) { |
| 334 | TValue tempb, tempc; | 322 | TValue tempb, tempc; |
| 335 | const TValue *b, *c; | 323 | const TValue *b, *c; |
| 336 | L->ci->savedpc = pc; | ||
| 337 | if ((b = luaV_tonumber(rb, &tempb)) != NULL && | 324 | if ((b = luaV_tonumber(rb, &tempb)) != NULL && |
| 338 | (c = luaV_tonumber(rc, &tempc)) != NULL) { | 325 | (c = luaV_tonumber(rc, &tempc)) != NULL) { |
| 339 | lua_Number nb = nvalue(b), nc = nvalue(c); | 326 | lua_Number nb = nvalue(b), nc = nvalue(c); |
| @@ -377,7 +364,6 @@ static StkId Arith (lua_State *L, StkId ra, const TValue *rb, | |||
| 377 | StkId luaV_execute (lua_State *L, int nexeccalls) { | 364 | StkId luaV_execute (lua_State *L, int nexeccalls) { |
| 378 | LClosure *cl; | 365 | LClosure *cl; |
| 379 | TValue *k; | 366 | TValue *k; |
| 380 | StkId base; | ||
| 381 | const Instruction *pc; | 367 | const Instruction *pc; |
| 382 | callentry: /* entry point when calling new functions */ | 368 | callentry: /* entry point when calling new functions */ |
| 383 | if (L->hookmask & LUA_MASKCALL) | 369 | if (L->hookmask & LUA_MASKCALL) |
| @@ -385,10 +371,10 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 385 | retentry: /* entry point when returning to old functions */ | 371 | retentry: /* entry point when returning to old functions */ |
| 386 | pc = L->ci->savedpc; | 372 | pc = L->ci->savedpc; |
| 387 | cl = &clvalue(L->ci->func)->l; | 373 | cl = &clvalue(L->ci->func)->l; |
| 388 | base = L->base; | ||
| 389 | k = cl->p->k; | 374 | k = cl->p->k; |
| 390 | /* main loop of interpreter */ | 375 | /* main loop of interpreter */ |
| 391 | for (;;) { | 376 | for (;;) { |
| 377 | StkId base; | ||
| 392 | const Instruction i = *pc++; | 378 | const Instruction i = *pc++; |
| 393 | StkId ra; | 379 | StkId ra; |
| 394 | if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && | 380 | if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && |
| @@ -398,11 +384,12 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 398 | L->ci->savedpc = pc - 1; | 384 | L->ci->savedpc = pc - 1; |
| 399 | return NULL; | 385 | return NULL; |
| 400 | } | 386 | } |
| 401 | base = L->base; | ||
| 402 | } | 387 | } |
| 403 | /* warning!! several calls may realloc the stack and invalidate `ra' */ | 388 | /* warning!! several calls may realloc the stack and invalidate `ra' */ |
| 389 | base = L->base; | ||
| 404 | ra = RA(i); | 390 | ra = RA(i); |
| 405 | lua_assert(base == L->ci->base && base == L->base); | 391 | L->ci->savedpc = pc; |
| 392 | lua_assert(base == L->ci->base); | ||
| 406 | lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); | 393 | lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); |
| 407 | lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); | 394 | lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); |
| 408 | switch (GET_OPCODE(i)) { | 395 | switch (GET_OPCODE(i)) { |
| @@ -436,18 +423,18 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 436 | TValue *rb = KBx(i); | 423 | TValue *rb = KBx(i); |
| 437 | sethvalue(L, &g, cl->env); | 424 | sethvalue(L, &g, cl->env); |
| 438 | lua_assert(ttisstring(rb)); | 425 | lua_assert(ttisstring(rb)); |
| 439 | base = luaV_gettable(L, &g, rb, ra, pc); /***/ | 426 | luaV_gettable(L, &g, rb, ra); /***/ |
| 440 | continue; | 427 | continue; |
| 441 | } | 428 | } |
| 442 | case OP_GETTABLE: { | 429 | case OP_GETTABLE: { |
| 443 | base = luaV_gettable(L, RB(i), RKC(i), ra, pc); /***/ | 430 | luaV_gettable(L, RB(i), RKC(i), ra); /***/ |
| 444 | continue; | 431 | continue; |
| 445 | } | 432 | } |
| 446 | case OP_SETGLOBAL: { | 433 | case OP_SETGLOBAL: { |
| 447 | TValue g; | 434 | TValue g; |
| 448 | sethvalue(L, &g, cl->env); | 435 | sethvalue(L, &g, cl->env); |
| 449 | lua_assert(ttisstring(KBx(i))); | 436 | lua_assert(ttisstring(KBx(i))); |
| 450 | base = luaV_settable(L, &g, KBx(i), ra, pc); /***/ | 437 | luaV_settable(L, &g, KBx(i), ra); /***/ |
| 451 | continue; | 438 | continue; |
| 452 | } | 439 | } |
| 453 | case OP_SETUPVAL: { | 440 | case OP_SETUPVAL: { |
| @@ -457,22 +444,20 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 457 | continue; | 444 | continue; |
| 458 | } | 445 | } |
| 459 | case OP_SETTABLE: { | 446 | case OP_SETTABLE: { |
| 460 | base = luaV_settable(L, ra, RKB(i), RKC(i), pc); /***/ | 447 | luaV_settable(L, ra, RKB(i), RKC(i)); /***/ |
| 461 | continue; | 448 | continue; |
| 462 | } | 449 | } |
| 463 | case OP_NEWTABLE: { | 450 | case OP_NEWTABLE: { |
| 464 | int b = GETARG_B(i); | 451 | int b = GETARG_B(i); |
| 465 | int c = GETARG_C(i); | 452 | int c = GETARG_C(i); |
| 466 | sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c))); | 453 | sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c))); |
| 467 | L->ci->savedpc = pc; | ||
| 468 | luaC_checkGC(L); /***/ | 454 | luaC_checkGC(L); /***/ |
| 469 | base = L->base; | ||
| 470 | continue; | 455 | continue; |
| 471 | } | 456 | } |
| 472 | case OP_SELF: { | 457 | case OP_SELF: { |
| 473 | StkId rb = RB(i); | 458 | StkId rb = RB(i); |
| 474 | setobjs2s(L, ra+1, rb); | 459 | setobjs2s(L, ra+1, rb); |
| 475 | base = luaV_gettable(L, rb, RKC(i), ra, pc); /***/ | 460 | luaV_gettable(L, rb, RKC(i), ra); /***/ |
| 476 | continue; | 461 | continue; |
| 477 | } | 462 | } |
| 478 | case OP_ADD: { | 463 | case OP_ADD: { |
| @@ -483,7 +468,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 483 | setnvalue(ra, luai_numadd(nb, nc)); | 468 | setnvalue(ra, luai_numadd(nb, nc)); |
| 484 | } | 469 | } |
| 485 | else | 470 | else |
| 486 | base = Arith(L, ra, rb, rc, TM_ADD, pc); /***/ | 471 | Arith(L, ra, rb, rc, TM_ADD); /***/ |
| 487 | continue; | 472 | continue; |
| 488 | } | 473 | } |
| 489 | case OP_SUB: { | 474 | case OP_SUB: { |
| @@ -494,7 +479,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 494 | setnvalue(ra, luai_numsub(nb, nc)); | 479 | setnvalue(ra, luai_numsub(nb, nc)); |
| 495 | } | 480 | } |
| 496 | else | 481 | else |
| 497 | base = Arith(L, ra, rb, rc, TM_SUB, pc); /***/ | 482 | Arith(L, ra, rb, rc, TM_SUB); /***/ |
| 498 | continue; | 483 | continue; |
| 499 | } | 484 | } |
| 500 | case OP_MUL: { | 485 | case OP_MUL: { |
| @@ -505,7 +490,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 505 | setnvalue(ra, luai_nummul(nb, nc)); | 490 | setnvalue(ra, luai_nummul(nb, nc)); |
| 506 | } | 491 | } |
| 507 | else | 492 | else |
| 508 | base = Arith(L, ra, rb, rc, TM_MUL, pc); /***/ | 493 | Arith(L, ra, rb, rc, TM_MUL); /***/ |
| 509 | continue; | 494 | continue; |
| 510 | } | 495 | } |
| 511 | case OP_DIV: { | 496 | case OP_DIV: { |
| @@ -516,7 +501,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 516 | setnvalue(ra, luai_numdiv(nb, nc)); | 501 | setnvalue(ra, luai_numdiv(nb, nc)); |
| 517 | } | 502 | } |
| 518 | else | 503 | else |
| 519 | base = Arith(L, ra, rb, rc, TM_DIV, pc); /***/ | 504 | Arith(L, ra, rb, rc, TM_DIV); /***/ |
| 520 | continue; | 505 | continue; |
| 521 | } | 506 | } |
| 522 | case OP_MOD: { | 507 | case OP_MOD: { |
| @@ -527,7 +512,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 527 | setnvalue(ra, luai_nummod(nb, nc)); | 512 | setnvalue(ra, luai_nummod(nb, nc)); |
| 528 | } | 513 | } |
| 529 | else | 514 | else |
| 530 | base = Arith(L, ra, rb, rc, TM_MOD, pc); /***/ | 515 | Arith(L, ra, rb, rc, TM_MOD); /***/ |
| 531 | continue; | 516 | continue; |
| 532 | } | 517 | } |
| 533 | case OP_POW: { | 518 | case OP_POW: { |
| @@ -538,7 +523,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 538 | setnvalue(ra, luai_numpow(nb, nc)); | 523 | setnvalue(ra, luai_numpow(nb, nc)); |
| 539 | } | 524 | } |
| 540 | else | 525 | else |
| 541 | base = Arith(L, ra, rb, rc, TM_POW, pc); /***/ | 526 | Arith(L, ra, rb, rc, TM_POW); /***/ |
| 542 | continue; | 527 | continue; |
| 543 | } | 528 | } |
| 544 | case OP_UNM: { | 529 | case OP_UNM: { |
| @@ -550,10 +535,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 550 | } | 535 | } |
| 551 | else { | 536 | else { |
| 552 | setnilvalue(&temp); | 537 | setnilvalue(&temp); |
| 553 | L->ci->savedpc = pc; | ||
| 554 | if (!call_binTM(L, RB(i), &temp, ra, TM_UNM)) /***/ | 538 | if (!call_binTM(L, RB(i), &temp, ra, TM_UNM)) /***/ |
| 555 | luaG_aritherror(L, RB(i), &temp); | 539 | luaG_aritherror(L, RB(i), &temp); |
| 556 | base = L->base; | ||
| 557 | } | 540 | } |
| 558 | continue; | 541 | continue; |
| 559 | } | 542 | } |
| @@ -572,7 +555,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 572 | setnvalue(ra, cast(lua_Number, tsvalue(rb)->len)); | 555 | setnvalue(ra, cast(lua_Number, tsvalue(rb)->len)); |
| 573 | break; | 556 | break; |
| 574 | default: /* no metamethod?? */ | 557 | default: /* no metamethod?? */ |
| 575 | L->ci->savedpc = pc; | ||
| 576 | luaG_typeerror(L, rb, "get the size of"); | 558 | luaG_typeerror(L, rb, "get the size of"); |
| 577 | } | 559 | } |
| 578 | continue; | 560 | continue; |
| @@ -580,7 +562,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 580 | case OP_CONCAT: { | 562 | case OP_CONCAT: { |
| 581 | int b = GETARG_B(i); | 563 | int b = GETARG_B(i); |
| 582 | int c = GETARG_C(i); | 564 | int c = GETARG_C(i); |
| 583 | L->ci->savedpc = pc; | ||
| 584 | luaV_concat(L, c-b+1, c); /* may change `base' (and `ra') */ /***/ | 565 | luaV_concat(L, c-b+1, c); /* may change `base' (and `ra') */ /***/ |
| 585 | luaC_checkGC(L); /***/ | 566 | luaC_checkGC(L); /***/ |
| 586 | base = L->base; | 567 | base = L->base; |
| @@ -592,24 +573,18 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 592 | continue; | 573 | continue; |
| 593 | } | 574 | } |
| 594 | case OP_EQ: { | 575 | case OP_EQ: { |
| 595 | L->ci->savedpc = pc; | ||
| 596 | if (equalobj(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ | 576 | if (equalobj(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ |
| 597 | else dojump(L, pc, GETARG_sBx(*pc) + 1); | 577 | else dojump(L, pc, GETARG_sBx(*pc) + 1); |
| 598 | base = L->base; | ||
| 599 | continue; | 578 | continue; |
| 600 | } | 579 | } |
| 601 | case OP_LT: { | 580 | case OP_LT: { |
| 602 | L->ci->savedpc = pc; | ||
| 603 | if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ | 581 | if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ |
| 604 | else dojump(L, pc, GETARG_sBx(*pc) + 1); | 582 | else dojump(L, pc, GETARG_sBx(*pc) + 1); |
| 605 | base = L->base; | ||
| 606 | continue; | 583 | continue; |
| 607 | } | 584 | } |
| 608 | case OP_LE: { | 585 | case OP_LE: { |
| 609 | L->ci->savedpc = pc; | ||
| 610 | if (lessequal(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ | 586 | if (lessequal(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ |
| 611 | else dojump(L, pc, GETARG_sBx(*pc) + 1); | 587 | else dojump(L, pc, GETARG_sBx(*pc) + 1); |
| 612 | base = L->base; | ||
| 613 | continue; | 588 | continue; |
| 614 | } | 589 | } |
| 615 | case OP_TEST: { | 590 | case OP_TEST: { |
| @@ -626,7 +601,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 626 | int b = GETARG_B(i); | 601 | int b = GETARG_B(i); |
| 627 | int nresults = GETARG_C(i) - 1; | 602 | int nresults = GETARG_C(i) - 1; |
| 628 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ | 603 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ |
| 629 | L->ci->savedpc = pc; | ||
| 630 | pcr = luaD_precall(L, ra, nresults); | 604 | pcr = luaD_precall(L, ra, nresults); |
| 631 | if (pcr == PCRLUA) { | 605 | if (pcr == PCRLUA) { |
| 632 | nexeccalls++; | 606 | nexeccalls++; |
| @@ -635,7 +609,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 635 | else if (pcr == PCRC) { | 609 | else if (pcr == PCRC) { |
| 636 | /* it was a C function (`precall' called it); adjust results */ | 610 | /* it was a C function (`precall' called it); adjust results */ |
| 637 | if (nresults >= 0) L->top = L->ci->top; | 611 | if (nresults >= 0) L->top = L->ci->top; |
| 638 | base = L->base; | ||
| 639 | continue; | 612 | continue; |
| 640 | } | 613 | } |
| 641 | else { | 614 | else { |
| @@ -647,7 +620,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 647 | int pcr; | 620 | int pcr; |
| 648 | int b = GETARG_B(i); | 621 | int b = GETARG_B(i); |
| 649 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ | 622 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ |
| 650 | L->ci->savedpc = pc; | ||
| 651 | lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); | 623 | lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); |
| 652 | pcr = luaD_precall(L, ra, LUA_MULTRET); | 624 | pcr = luaD_precall(L, ra, LUA_MULTRET); |
| 653 | if (pcr == PCRLUA) { | 625 | if (pcr == PCRLUA) { |
| @@ -657,20 +629,18 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 657 | StkId func = ci->func; | 629 | StkId func = ci->func; |
| 658 | StkId pfunc = (ci+1)->func; /* previous function index */ | 630 | StkId pfunc = (ci+1)->func; /* previous function index */ |
| 659 | if (L->openupval) luaF_close(L, ci->base); | 631 | if (L->openupval) luaF_close(L, ci->base); |
| 660 | base = ci->base = ci->func + ((ci+1)->base - pfunc); | 632 | L->base = ci->base = ci->func + ((ci+1)->base - pfunc); |
| 661 | L->base = base; | ||
| 662 | for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */ | 633 | for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */ |
| 663 | setobjs2s(L, func+aux, pfunc+aux); | 634 | setobjs2s(L, func+aux, pfunc+aux); |
| 664 | ci->top = L->top = func+aux; /* correct top */ | 635 | ci->top = L->top = func+aux; /* correct top */ |
| 665 | lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize); | 636 | lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize); |
| 666 | ci->savedpc = L->ci->savedpc; | 637 | ci->savedpc = (ci+1)->savedpc; |
| 667 | ci->tailcalls++; /* one more call lost */ | 638 | ci->tailcalls++; /* one more call lost */ |
| 668 | L->ci--; /* remove new frame */ | 639 | L->ci--; /* remove new frame */ |
| 669 | goto callentry; | 640 | goto callentry; |
| 670 | } | 641 | } |
| 671 | else if (pcr == PCRC) { | 642 | else if (pcr == PCRC) { |
| 672 | /* it was a C function (`precall' called it) */ | 643 | /* it was a C function (`precall' called it) */ |
| 673 | base = L->base; | ||
| 674 | continue; | 644 | continue; |
| 675 | } | 645 | } |
| 676 | else { | 646 | else { |
| @@ -683,7 +653,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 683 | int b = GETARG_B(i); | 653 | int b = GETARG_B(i); |
| 684 | if (b != 0) L->top = ra+b-1; | 654 | if (b != 0) L->top = ra+b-1; |
| 685 | if (L->openupval) luaF_close(L, base); | 655 | if (L->openupval) luaF_close(L, base); |
| 686 | L->ci->savedpc = pc; | ||
| 687 | if (--nexeccalls == 0) /* was previous function running `here'? */ | 656 | if (--nexeccalls == 0) /* was previous function running `here'? */ |
| 688 | return ra; /* no: return */ | 657 | return ra; /* no: return */ |
| 689 | else { /* yes: continue its execution */ | 658 | else { /* yes: continue its execution */ |
| @@ -710,7 +679,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 710 | const TValue *init = ra; | 679 | const TValue *init = ra; |
| 711 | const TValue *plimit = ra+1; | 680 | const TValue *plimit = ra+1; |
| 712 | const TValue *pstep = ra+2; | 681 | const TValue *pstep = ra+2; |
| 713 | L->ci->savedpc = pc; | ||
| 714 | if (!tonumber(init, ra)) | 682 | if (!tonumber(init, ra)) |
| 715 | luaG_runerror(L, "`for' initial value must be a number"); | 683 | luaG_runerror(L, "`for' initial value must be a number"); |
| 716 | else if (!tonumber(plimit, ra+1)) | 684 | else if (!tonumber(plimit, ra+1)) |
| @@ -727,7 +695,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 727 | setobjs2s(L, cb+1, ra+1); | 695 | setobjs2s(L, cb+1, ra+1); |
| 728 | setobjs2s(L, cb, ra); | 696 | setobjs2s(L, cb, ra); |
| 729 | L->top = cb+3; /* func. + 2 args (state and index) */ | 697 | L->top = cb+3; /* func. + 2 args (state and index) */ |
| 730 | L->ci->savedpc = pc; | ||
| 731 | luaD_call(L, cb, GETARG_C(i)); /***/ | 698 | luaD_call(L, cb, GETARG_C(i)); /***/ |
| 732 | L->top = L->ci->top; | 699 | L->top = L->ci->top; |
| 733 | base = L->base; | 700 | base = L->base; |
| @@ -791,9 +758,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 791 | } | 758 | } |
| 792 | } | 759 | } |
| 793 | setclvalue(L, ra, ncl); | 760 | setclvalue(L, ra, ncl); |
| 794 | L->ci->savedpc = pc; | ||
| 795 | luaC_checkGC(L); /***/ | 761 | luaC_checkGC(L); /***/ |
| 796 | base = L->base; | ||
| 797 | continue; | 762 | continue; |
| 798 | } | 763 | } |
| 799 | case OP_VARARG: { | 764 | case OP_VARARG: { |
