diff options
| -rw-r--r-- | lparser.c | 4 | ||||
| -rw-r--r-- | lvm.c | 39 |
2 files changed, 23 insertions, 20 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.110 2000/08/22 17:44:17 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.111 2000/08/31 14:08:27 roberto Exp roberto $ |
| 3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -841,8 +841,8 @@ static void forbody (LexState *ls, int nvar, OpCode prepfor, OpCode loopfor) { | |||
| 841 | check(ls, TK_DO); | 841 | check(ls, TK_DO); |
| 842 | adjustlocalvars(ls, nvar); /* scope for control variables */ | 842 | adjustlocalvars(ls, nvar); /* scope for control variables */ |
| 843 | block(ls); | 843 | block(ls); |
| 844 | luaK_patchlist(fs, prep, luaK_getlabel(fs)); | ||
| 845 | luaK_patchlist(fs, luaK_code1(fs, loopfor, NO_JUMP), blockinit); | 844 | luaK_patchlist(fs, luaK_code1(fs, loopfor, NO_JUMP), blockinit); |
| 845 | luaK_patchlist(fs, prep, luaK_getlabel(fs)); | ||
| 846 | removelocalvars(ls, nvar); | 846 | removelocalvars(ls, nvar); |
| 847 | } | 847 | } |
| 848 | 848 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.134 2000/09/05 19:33:32 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.135 2000/09/11 17:38:42 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 | */ |
| @@ -336,6 +336,9 @@ static void adjust_varargs (lua_State *L, StkId base, int nfixargs) { | |||
| 336 | } | 336 | } |
| 337 | 337 | ||
| 338 | 338 | ||
| 339 | |||
| 340 | #define dojump(pc, i) { int d = GETARG_S(i); pc += d; } | ||
| 341 | |||
| 339 | /* | 342 | /* |
| 340 | ** Executes the given Lua function. Parameters are between [base,top). | 343 | ** Executes the given Lua function. Parameters are between [base,top). |
| 341 | ** Returns n such that the the results are between [n,top). | 344 | ** Returns n such that the the results are between [n,top). |
| @@ -578,54 +581,54 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 578 | } | 581 | } |
| 579 | case OP_JMPNE: { | 582 | case OP_JMPNE: { |
| 580 | top -= 2; | 583 | top -= 2; |
| 581 | if (!luaO_equalObj(top, top+1)) pc += GETARG_S(i); | 584 | if (!luaO_equalObj(top, top+1)) dojump(pc, i); |
| 582 | break; | 585 | break; |
| 583 | } | 586 | } |
| 584 | case OP_JMPEQ: { | 587 | case OP_JMPEQ: { |
| 585 | top -= 2; | 588 | top -= 2; |
| 586 | if (luaO_equalObj(top, top+1)) pc += GETARG_S(i); | 589 | if (luaO_equalObj(top, top+1)) dojump(pc, i); |
| 587 | break; | 590 | break; |
| 588 | } | 591 | } |
| 589 | case OP_JMPLT: { | 592 | case OP_JMPLT: { |
| 590 | top -= 2; | 593 | top -= 2; |
| 591 | if (luaV_lessthan(L, top, top+1, top+2)) pc += GETARG_S(i); | 594 | if (luaV_lessthan(L, top, top+1, top+2)) dojump(pc, i); |
| 592 | break; | 595 | break; |
| 593 | } | 596 | } |
| 594 | case OP_JMPLE: { /* a <= b === !(b<a) */ | 597 | case OP_JMPLE: { /* a <= b === !(b<a) */ |
| 595 | top -= 2; | 598 | top -= 2; |
| 596 | if (!luaV_lessthan(L, top+1, top, top+2)) pc += GETARG_S(i); | 599 | if (!luaV_lessthan(L, top+1, top, top+2)) dojump(pc, i); |
| 597 | break; | 600 | break; |
| 598 | } | 601 | } |
| 599 | case OP_JMPGT: { /* a > b === (b<a) */ | 602 | case OP_JMPGT: { /* a > b === (b<a) */ |
| 600 | top -= 2; | 603 | top -= 2; |
| 601 | if (luaV_lessthan(L, top+1, top, top+2)) pc += GETARG_S(i); | 604 | if (luaV_lessthan(L, top+1, top, top+2)) dojump(pc, i); |
| 602 | break; | 605 | break; |
| 603 | } | 606 | } |
| 604 | case OP_JMPGE: { /* a >= b === !(a<b) */ | 607 | case OP_JMPGE: { /* a >= b === !(a<b) */ |
| 605 | top -= 2; | 608 | top -= 2; |
| 606 | if (!luaV_lessthan(L, top, top+1, top+2)) pc += GETARG_S(i); | 609 | if (!luaV_lessthan(L, top, top+1, top+2)) dojump(pc, i); |
| 607 | break; | 610 | break; |
| 608 | } | 611 | } |
| 609 | case OP_JMPT: { | 612 | case OP_JMPT: { |
| 610 | if (ttype(--top) != TAG_NIL) pc += GETARG_S(i); | 613 | if (ttype(--top) != TAG_NIL) dojump(pc, i); |
| 611 | break; | 614 | break; |
| 612 | } | 615 | } |
| 613 | case OP_JMPF: { | 616 | case OP_JMPF: { |
| 614 | if (ttype(--top) == TAG_NIL) pc += GETARG_S(i); | 617 | if (ttype(--top) == TAG_NIL) dojump(pc, i); |
| 615 | break; | 618 | break; |
| 616 | } | 619 | } |
| 617 | case OP_JMPONT: { | 620 | case OP_JMPONT: { |
| 618 | if (ttype(top-1) != TAG_NIL) pc += GETARG_S(i); | 621 | if (ttype(top-1) == TAG_NIL) top--; |
| 619 | else top--; | 622 | else dojump(pc, i); |
| 620 | break; | 623 | break; |
| 621 | } | 624 | } |
| 622 | case OP_JMPONF: { | 625 | case OP_JMPONF: { |
| 623 | if (ttype(top-1) == TAG_NIL) pc += GETARG_S(i); | 626 | if (ttype(top-1) != TAG_NIL) top--; |
| 624 | else top--; | 627 | else dojump(pc, i); |
| 625 | break; | 628 | break; |
| 626 | } | 629 | } |
| 627 | case OP_JMP: { | 630 | case OP_JMP: { |
| 628 | pc += GETARG_S(i); | 631 | dojump(pc, i); |
| 629 | break; | 632 | break; |
| 630 | } | 633 | } |
| 631 | case OP_PUSHNILJMP: { | 634 | case OP_PUSHNILJMP: { |
| @@ -644,7 +647,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 644 | nvalue(top-3) > nvalue(top-2) : | 647 | nvalue(top-3) > nvalue(top-2) : |
| 645 | nvalue(top-3) < nvalue(top-2)) { /* `empty' loop? */ | 648 | nvalue(top-3) < nvalue(top-2)) { /* `empty' loop? */ |
| 646 | top -= 3; /* remove control variables */ | 649 | top -= 3; /* remove control variables */ |
| 647 | pc += GETARG_S(i)+1; /* jump to loop end */ | 650 | dojump(pc, i); /* jump to loop end */ |
| 648 | } | 651 | } |
| 649 | break; | 652 | break; |
| 650 | } | 653 | } |
| @@ -659,7 +662,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 659 | nvalue(top-3) < nvalue(top-2)) | 662 | nvalue(top-3) < nvalue(top-2)) |
| 660 | top -= 3; /* end loop: remove control variables */ | 663 | top -= 3; /* end loop: remove control variables */ |
| 661 | else | 664 | else |
| 662 | pc += GETARG_S(i); /* repeat loop */ | 665 | dojump(pc, i); /* repeat loop */ |
| 663 | break; | 666 | break; |
| 664 | } | 667 | } |
| 665 | case OP_LFORPREP: { | 668 | case OP_LFORPREP: { |
| @@ -669,7 +672,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 669 | node = luaH_next(L, hvalue(top-1), &luaO_nilobject); | 672 | node = luaH_next(L, hvalue(top-1), &luaO_nilobject); |
| 670 | if (node == NULL) { /* `empty' loop? */ | 673 | if (node == NULL) { /* `empty' loop? */ |
| 671 | top--; /* remove table */ | 674 | top--; /* remove table */ |
| 672 | pc += GETARG_S(i)+1; /* jump to loop end */ | 675 | dojump(pc, i); /* jump to loop end */ |
| 673 | } | 676 | } |
| 674 | else { | 677 | else { |
| 675 | top += 2; /* index,value */ | 678 | top += 2; /* index,value */ |
| @@ -687,7 +690,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 687 | else { | 690 | else { |
| 688 | *(top-2) = *key(node); | 691 | *(top-2) = *key(node); |
| 689 | *(top-1) = *val(node); | 692 | *(top-1) = *val(node); |
| 690 | pc += GETARG_S(i); /* repeat loop */ | 693 | dojump(pc, i); /* repeat loop */ |
| 691 | } | 694 | } |
| 692 | break; | 695 | break; |
| 693 | } | 696 | } |
