diff options
Diffstat (limited to 'lcode.c')
-rw-r--r-- | lcode.c | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.106 2015/12/18 13:53:36 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.107 2016/01/04 13:40:57 roberto Exp roberto $ |
3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -514,11 +514,12 @@ static int nilK (FuncState *fs) { | |||
514 | */ | 514 | */ |
515 | void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { | 515 | void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { |
516 | if (e->k == VCALL) { /* expression is an open function call? */ | 516 | if (e->k == VCALL) { /* expression is an open function call? */ |
517 | SETARG_C(getcode(fs, e), nresults+1); | 517 | SETARG_C(getinstruction(fs, e), nresults + 1); |
518 | } | 518 | } |
519 | else if (e->k == VVARARG) { | 519 | else if (e->k == VVARARG) { |
520 | SETARG_B(getcode(fs, e), nresults+1); | 520 | Instruction *pc = &getinstruction(fs, e); |
521 | SETARG_A(getcode(fs, e), fs->freereg); | 521 | SETARG_B(*pc, nresults + 1); |
522 | SETARG_A(*pc, fs->freereg); | ||
522 | luaK_reserveregs(fs, 1); | 523 | luaK_reserveregs(fs, 1); |
523 | } | 524 | } |
524 | else lua_assert(nresults == LUA_MULTRET); | 525 | else lua_assert(nresults == LUA_MULTRET); |
@@ -537,12 +538,13 @@ void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { | |||
537 | */ | 538 | */ |
538 | void luaK_setoneret (FuncState *fs, expdesc *e) { | 539 | void luaK_setoneret (FuncState *fs, expdesc *e) { |
539 | if (e->k == VCALL) { /* expression is an open function call? */ | 540 | if (e->k == VCALL) { /* expression is an open function call? */ |
540 | lua_assert(GETARG_C(getcode(fs, e)) == 2); /* already returns 1 value */ | 541 | /* already returns 1 value */ |
542 | lua_assert(GETARG_C(getinstruction(fs, e)) == 2); | ||
541 | e->k = VNONRELOC; /* result has fixed position */ | 543 | e->k = VNONRELOC; /* result has fixed position */ |
542 | e->u.info = GETARG_A(getcode(fs, e)); | 544 | e->u.info = GETARG_A(getinstruction(fs, e)); |
543 | } | 545 | } |
544 | else if (e->k == VVARARG) { | 546 | else if (e->k == VVARARG) { |
545 | SETARG_B(getcode(fs, e), 2); | 547 | SETARG_B(getinstruction(fs, e), 2); |
546 | e->k = VRELOCABLE; /* can relocate its simple result */ | 548 | e->k = VRELOCABLE; /* can relocate its simple result */ |
547 | } | 549 | } |
548 | } | 550 | } |
@@ -614,7 +616,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) { | |||
614 | break; | 616 | break; |
615 | } | 617 | } |
616 | case VRELOCABLE: { | 618 | case VRELOCABLE: { |
617 | Instruction *pc = &getcode(fs, e); | 619 | Instruction *pc = &getinstruction(fs, e); |
618 | SETARG_A(*pc, reg); /* instruction will put result in 'reg' */ | 620 | SETARG_A(*pc, reg); /* instruction will put result in 'reg' */ |
619 | break; | 621 | break; |
620 | } | 622 | } |
@@ -836,7 +838,7 @@ static void negatecondition (FuncState *fs, expdesc *e) { | |||
836 | */ | 838 | */ |
837 | static int jumponcond (FuncState *fs, expdesc *e, int cond) { | 839 | static int jumponcond (FuncState *fs, expdesc *e, int cond) { |
838 | if (e->k == VRELOCABLE) { | 840 | if (e->k == VRELOCABLE) { |
839 | Instruction ie = getcode(fs, e); | 841 | Instruction ie = getinstruction(fs, e); |
840 | if (GET_OPCODE(ie) == OP_NOT) { | 842 | if (GET_OPCODE(ie) == OP_NOT) { |
841 | fs->pc--; /* remove previous OP_NOT */ | 843 | fs->pc--; /* remove previous OP_NOT */ |
842 | return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond); | 844 | return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond); |
@@ -1134,10 +1136,11 @@ void luaK_posfix (FuncState *fs, BinOpr op, | |||
1134 | } | 1136 | } |
1135 | case OPR_CONCAT: { | 1137 | case OPR_CONCAT: { |
1136 | luaK_exp2val(fs, e2); | 1138 | luaK_exp2val(fs, e2); |
1137 | if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) { | 1139 | if (e2->k == VRELOCABLE && |
1138 | lua_assert(e1->u.info == GETARG_B(getcode(fs, e2))-1); | 1140 | GET_OPCODE(getinstruction(fs, e2)) == OP_CONCAT) { |
1141 | lua_assert(e1->u.info == GETARG_B(getinstruction(fs, e2))-1); | ||
1139 | freeexp(fs, e1); | 1142 | freeexp(fs, e1); |
1140 | SETARG_B(getcode(fs, e2), e1->u.info); | 1143 | SETARG_B(getinstruction(fs, e2), e1->u.info); |
1141 | e1->k = VRELOCABLE; e1->u.info = e2->u.info; | 1144 | e1->k = VRELOCABLE; e1->u.info = e2->u.info; |
1142 | } | 1145 | } |
1143 | else { | 1146 | else { |