Showing the changes to src/lcode.c (1 of 77 files). Show all
Unified · Split
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lcode.c,v 2.43 2010/01/11 17:38:30 roberto Exp $ | |
| 2 | +** $Id: lcode.c,v 2.46 2010/04/17 12:46:32 roberto Exp $ | |
| 3 | 3 | ** Code generator for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -372,11 +372,6 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) { · 366 unmodified lines | ||
| 372 | 372 | e->k = VRELOCABLE; |
| 373 | 373 | break; |
| 374 | 374 | } |
| 375 | − case VGLOBAL: { | |
| 376 | − e->u.s.info = luaK_codeABxX(fs, OP_GETGLOBAL, 0, e->u.s.info); | |
| 377 | − e->k = VRELOCABLE; | |
| 378 | − break; | |
| 379 | − } | |
| 380 | 375 | case VINDEXED: { |
| 381 | 376 | freereg(fs, e->u.s.aux); |
| 382 | 377 | freereg(fs, e->u.s.info); |
| @@ -384,6 +379,12 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) { · 1 unmodified line | ||
| 384 | 379 | e->k = VRELOCABLE; |
| 385 | 380 | break; |
| 386 | 381 | } |
| 382 | + case VINDEXEDUP: { | |
| 383 | + freereg(fs, e->u.s.aux); | |
| 384 | + e->u.s.info = luaK_codeABC(fs, OP_GETTABUP, 0, e->u.s.info, e->u.s.aux); | |
| 385 | + e->k = VRELOCABLE; | |
| 386 | + break; | |
| 387 | + } | |
| 387 | 388 | case VVARARG: |
| 388 | 389 | case VCALL: { |
| 389 | 390 | luaK_setoneret(fs, e); |
| @@ -493,6 +494,12 @@ int luaK_exp2anyreg (FuncState *fs, expdesc *e) { · 103 unmodified lines | ||
| 493 | 494 | } |
| 494 | 495 | |
| 495 | 496 | |
| 497 | +void luaK_exp2anyregup (FuncState *fs, expdesc *e) { | |
| 498 | + if (e->k != VUPVAL || hasjumps(e)) | |
| 499 | + luaK_exp2anyreg(fs, e); | |
| 500 | +} | |
| 501 | + | |
| 502 | + | |
| 496 | 503 | void luaK_exp2val (FuncState *fs, expdesc *e) { |
| 497 | 504 | if (hasjumps(e)) |
| 498 | 505 | luaK_exp2anyreg(fs, e); |
| @@ -543,16 +550,16 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { · 44 unmodified lines | ||
| 543 | 550 | luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0); |
| 544 | 551 | break; |
| 545 | 552 | } |
| 546 | − case VGLOBAL: { | |
| 547 | − int e = luaK_exp2anyreg(fs, ex); | |
| 548 | − luaK_codeABxX(fs, OP_SETGLOBAL, e, var->u.s.info); | |
| 549 | − break; | |
| 550 | − } | |
| 551 | 553 | case VINDEXED: { |
| 552 | 554 | int e = luaK_exp2RK(fs, ex); |
| 553 | 555 | luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e); |
| 554 | 556 | break; |
| 555 | 557 | } |
| 558 | + case VINDEXEDUP: { | |
| 559 | + int e = luaK_exp2RK(fs, ex); | |
| 560 | + luaK_codeABC(fs, OP_SETTABUP, var->u.s.info, var->u.s.aux, e); | |
| 561 | + break; | |
| 562 | + } | |
| 556 | 563 | default: { |
| 557 | 564 | lua_assert(0); /* invalid var kind to store */ |
| 558 | 565 | break; |
| @@ -567,9 +574,9 @@ void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { · 8 unmodified lines | ||
| 567 | 574 | luaK_exp2anyreg(fs, e); |
| 568 | 575 | freeexp(fs, e); |
| 569 | 576 | func = fs->freereg; |
| 570 | − luaK_reserveregs(fs, 2); | |
| 571 | 577 | luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key)); |
| 572 | 578 | freeexp(fs, key); |
| 579 | + luaK_reserveregs(fs, 2); | |
| 573 | 580 | e->u.s.info = func; |
| 574 | 581 | e->k = VNONRELOC; |
| 575 | 582 | } |
| @@ -695,8 +702,9 @@ static void codenot (FuncState *fs, expdesc *e) { · 119 unmodified lines | ||
| 695 | 702 | |
| 696 | 703 | |
| 697 | 704 | void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { |
| 705 | + lua_assert(!hasjumps(t)); | |
| 698 | 706 | t->u.s.aux = luaK_exp2RK(fs, k); |
| 699 | − t->k = VINDEXED; | |
| 707 | + t->k = (t->k == VUPVAL) ? VINDEXEDUP : VINDEXED; | |
| 700 | 708 | } |
| 701 | 709 | |
| 702 | 710 | |
| @@ -711,7 +719,8 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { · 8 unmodified lines | ||
| 711 | 719 | } |
| 712 | 720 | |
| 713 | 721 | |
| 714 | −static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { | |
| 722 | +static void codearith (FuncState *fs, OpCode op, | |
| 723 | + expdesc *e1, expdesc *e2, int line) { | |
| 715 | 724 | if (constfolding(op, e1, e2)) |
| 716 | 725 | return; |
| 717 | 726 | else { |
| @@ -727,6 +736,7 @@ static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { · 9 unmodified lines | ||
| 727 | 736 | } |
| 728 | 737 | e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); |
| 729 | 738 | e1->k = VRELOCABLE; |
| 739 | + luaK_fixline(fs, line); | |
| 730 | 740 | } |
| 731 | 741 | } |
| 732 | 742 | |
| @@ -747,7 +757,7 @@ static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, · 14 unmodified lines | ||
| 747 | 757 | } |
| 748 | 758 | |
| 749 | 759 | |
| 750 | −void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { | |
| 760 | +void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) { | |
| 751 | 761 | expdesc e2; |
| 752 | 762 | e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0; |
| 753 | 763 | switch (op) { |
| @@ -756,14 +766,14 @@ void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { · 2 unmodified lines | ||
| 756 | 766 | e->u.nval = luai_numunm(NULL, e->u.nval); /* fold it */ |
| 757 | 767 | else { |
| 758 | 768 | luaK_exp2anyreg(fs, e); |
| 759 | − codearith(fs, OP_UNM, e, &e2); | |
| 769 | + codearith(fs, OP_UNM, e, &e2, line); | |
| 760 | 770 | } |
| 761 | 771 | break; |
| 762 | 772 | } |
| 763 | 773 | case OPR_NOT: codenot(fs, e); break; |
| 764 | 774 | case OPR_LEN: { |
| 765 | 775 | luaK_exp2anyreg(fs, e); /* cannot operate on constants */ |
| 766 | − codearith(fs, OP_LEN, e, &e2); | |
| 776 | + codearith(fs, OP_LEN, e, &e2, line); | |
| 767 | 777 | break; |
| 768 | 778 | } |
| 769 | 779 | default: lua_assert(0); |
| @@ -798,7 +808,8 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { · 28 unmodified lines | ||
| 798 | 808 | } |
| 799 | 809 | |
| 800 | 810 | |
| 801 | −void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { | |
| 811 | +void luaK_posfix (FuncState *fs, BinOpr op, | |
| 812 | + expdesc *e1, expdesc *e2, int line) { | |
| 802 | 813 | switch (op) { |
| 803 | 814 | case OPR_AND: { |
| 804 | 815 | lua_assert(e1->t == NO_JUMP); /* list must be closed */ |
| @@ -824,13 +835,13 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { · 19 unmodified lines | ||
| 824 | 835 | } |
| 825 | 836 | else { |
| 826 | 837 | luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ |
| 827 | − codearith(fs, OP_CONCAT, e1, e2); | |
| 838 | + codearith(fs, OP_CONCAT, e1, e2, line); | |
| 828 | 839 | } |
| 829 | 840 | break; |
| 830 | 841 | } |
| 831 | 842 | case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: |
| 832 | 843 | case OPR_MOD: case OPR_POW: { |
| 833 | − codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2); | |
| 844 | + codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2, line); | |
| 834 | 845 | break; |
| 835 | 846 | } |
| 836 | 847 | case OPR_EQ: case OPR_LT: case OPR_LE: { |