History

Lua 5.2.0-work3

Lua Team committed 16 years ago

Commit d618ddd1 parent be77f2777 files · +3825 −3949Browse files

Showing the changes to src/lcode.c (1 of 77 files). Show all

Unified · Split

src/lcode.c+31−20
@@ -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** Code generator for Lua3** Code generator for Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -372,11 +372,6 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) { · 366 unmodified lines
372 e->k = VRELOCABLE;372 e->k = VRELOCABLE;
373 break;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 case VINDEXED: {375 case VINDEXED: {
381 freereg(fs, e->u.s.aux);376 freereg(fs, e->u.s.aux);
382 freereg(fs, e->u.s.info);377 freereg(fs, e->u.s.info);
@@ -384,6 +379,12 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) { · 1 unmodified line
384 e->k = VRELOCABLE;379 e->k = VRELOCABLE;
385 break;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 case VVARARG:388 case VVARARG:
388 case VCALL: {389 case VCALL: {
389 luaK_setoneret(fs, e);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
497void luaK_exp2anyregup (FuncState *fs, expdesc *e) {
498 if (e->k != VUPVAL || hasjumps(e))
499 luaK_exp2anyreg(fs, e);
500}
501
502
496void luaK_exp2val (FuncState *fs, expdesc *e) {503void luaK_exp2val (FuncState *fs, expdesc *e) {
497 if (hasjumps(e))504 if (hasjumps(e))
498 luaK_exp2anyreg(fs, e);505 luaK_exp2anyreg(fs, e);
@@ -543,16 +550,16 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { · 44 unmodified lines
543 luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0);550 luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0);
544 break;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 case VINDEXED: {553 case VINDEXED: {
552 int e = luaK_exp2RK(fs, ex);554 int e = luaK_exp2RK(fs, ex);
553 luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e);555 luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e);
554 break;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 default: {563 default: {
557 lua_assert(0); /* invalid var kind to store */564 lua_assert(0); /* invalid var kind to store */
558 break;565 break;
@@ -567,9 +574,9 @@ void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { · 8 unmodified lines
567 luaK_exp2anyreg(fs, e);574 luaK_exp2anyreg(fs, e);
568 freeexp(fs, e);575 freeexp(fs, e);
569 func = fs->freereg;576 func = fs->freereg;
570 luaK_reserveregs(fs, 2);
571 luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key));577 luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key));
572 freeexp(fs, key);578 freeexp(fs, key);
579 luaK_reserveregs(fs, 2);
573 e->u.s.info = func;580 e->u.s.info = func;
574 e->k = VNONRELOC;581 e->k = VNONRELOC;
575}582}
@@ -695,8 +702,9 @@ static void codenot (FuncState *fs, expdesc *e) { · 119 unmodified lines
695 702
696 703
697void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {704void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
705 lua_assert(!hasjumps(t));
698 t->u.s.aux = luaK_exp2RK(fs, k);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
714static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {722static void codearith (FuncState *fs, OpCode op,
723 expdesc *e1, expdesc *e2, int line) {
715 if (constfolding(op, e1, e2))724 if (constfolding(op, e1, e2))
716 return;725 return;
717 else {726 else {
@@ -727,6 +736,7 @@ static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { · 9 unmodified lines
727 }736 }
728 e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);737 e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
729 e1->k = VRELOCABLE;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
750void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) {760void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) {
751 expdesc e2;761 expdesc e2;
752 e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;762 e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
753 switch (op) {763 switch (op) {
@@ -756,14 +766,14 @@ void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { · 2 unmodified lines
756 e->u.nval = luai_numunm(NULL, e->u.nval); /* fold it */766 e->u.nval = luai_numunm(NULL, e->u.nval); /* fold it */
757 else {767 else {
758 luaK_exp2anyreg(fs, e);768 luaK_exp2anyreg(fs, e);
759 codearith(fs, OP_UNM, e, &e2);769 codearith(fs, OP_UNM, e, &e2, line);
760 }770 }
761 break;771 break;
762 }772 }
763 case OPR_NOT: codenot(fs, e); break;773 case OPR_NOT: codenot(fs, e); break;
764 case OPR_LEN: {774 case OPR_LEN: {
765 luaK_exp2anyreg(fs, e); /* cannot operate on constants */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 break;777 break;
768 }778 }
769 default: lua_assert(0);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
801void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {811void luaK_posfix (FuncState *fs, BinOpr op,
812 expdesc *e1, expdesc *e2, int line) {
802 switch (op) {813 switch (op) {
803 case OPR_AND: {814 case OPR_AND: {
804 lua_assert(e1->t == NO_JUMP); /* list must be closed */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 else {836 else {
826 luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */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 break;840 break;
830 }841 }
831 case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:842 case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
832 case OPR_MOD: case OPR_POW: {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 break;845 break;
835 }846 }
836 case OPR_EQ: case OPR_LT: case OPR_LE: {847 case OPR_EQ: case OPR_LT: case OPR_LE: {